Skip to content
Snippets Groups Projects
Commit bc471953 authored by Frisinghelli Daniel's avatar Frisinghelli Daniel
Browse files

Added a check for an empty dataset.

parent e0898c8c
No related branches found
No related tags found
No related merge requests found
......@@ -365,31 +365,35 @@ def hdf2tifs(path, outpath=None, overwrite=False, create_stack=True, **kwargs):
# read the hdf dataset
hdf = gdal.Open(str(path)).GetSubDatasets()
# iterate over the different subdatasets in the hdf
for ds in hdf:
# check if the dataset is not empty
if hdf:
# name of the current subdataset
name = ds[0].split(':')[-1]
# iterate over the different subdatasets in the hdf
for ds in hdf:
# name of the current subdataset
name = ds[0].split(':')[-1]
# filename of the GeoTIFF
tif_name = outpath.joinpath(path.name.replace(path.suffix,
'_{}.tif'.format(name)))
# filename of the GeoTIFF
tif_name = outpath.joinpath(
path.name.replace(path.suffix, '_{}.tif'.format(name)))
# convert hdf subdataset to GeoTIFF
gdal.Translate(str(tif_name), gdal.Open(ds[0]), **kwargs)
# convert hdf subdataset to GeoTIFF
gdal.Translate(str(tif_name), gdal.Open(ds[0]), **kwargs)
# check whether to create a GeoTIFF stack
if create_stack:
# filename for the GeoTIFF stack
stk = tif_name.parent.joinpath(path.name.replace(path.suffix, '.tif'))
LOGGER.info('Creating GeoTIFF stack: {}'.format(stk))
# check whether to create a GeoTIFF stack
if create_stack:
# filename for the GeoTIFF stack
stk = tif_name.parent.joinpath(
path.name.replace(path.suffix, '.tif'))
LOGGER.info('Creating GeoTIFF stack: {}'.format(stk))
# generated GeoTIFF files
tifs = [str(f) for f in outpath.iterdir() if f.suffix in
['.tif', '.TIF']]
# generated GeoTIFF files
tifs = [str(f) for f in outpath.iterdir() if f.suffix in
['.tif', '.TIF']]
# create stacked GeoTIFF
stack_tifs(str(stk), tifs)
# create stacked GeoTIFF
stack_tifs(str(stk), tifs)
return
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment