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): ...@@ -365,31 +365,35 @@ def hdf2tifs(path, outpath=None, overwrite=False, create_stack=True, **kwargs):
# read the hdf dataset # read the hdf dataset
hdf = gdal.Open(str(path)).GetSubDatasets() hdf = gdal.Open(str(path)).GetSubDatasets()
# iterate over the different subdatasets in the hdf # check if the dataset is not empty
for ds in hdf: if hdf:
# name of the current subdataset # iterate over the different subdatasets in the hdf
name = ds[0].split(':')[-1] for ds in hdf:
# name of the current subdataset
name = ds[0].split(':')[-1]
# filename of the GeoTIFF # filename of the GeoTIFF
tif_name = outpath.joinpath(path.name.replace(path.suffix, tif_name = outpath.joinpath(
'_{}.tif'.format(name))) path.name.replace(path.suffix, '_{}.tif'.format(name)))
# convert hdf subdataset to GeoTIFF # convert hdf subdataset to GeoTIFF
gdal.Translate(str(tif_name), gdal.Open(ds[0]), **kwargs) gdal.Translate(str(tif_name), gdal.Open(ds[0]), **kwargs)
# check whether to create a GeoTIFF stack # check whether to create a GeoTIFF stack
if create_stack: if create_stack:
# filename for the GeoTIFF stack # filename for the GeoTIFF stack
stk = tif_name.parent.joinpath(path.name.replace(path.suffix, '.tif')) stk = tif_name.parent.joinpath(
LOGGER.info('Creating GeoTIFF stack: {}'.format(stk)) path.name.replace(path.suffix, '.tif'))
LOGGER.info('Creating GeoTIFF stack: {}'.format(stk))
# generated GeoTIFF files # generated GeoTIFF files
tifs = [str(f) for f in outpath.iterdir() if f.suffix in tifs = [str(f) for f in outpath.iterdir() if f.suffix in
['.tif', '.TIF']] ['.tif', '.TIF']]
# create stacked GeoTIFF # create stacked GeoTIFF
stack_tifs(str(stk), tifs) stack_tifs(str(stk), tifs)
return 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