diff --git a/pysegcnn/core/utils.py b/pysegcnn/core/utils.py index 1e18dea571a20f76fe741325ecdbc6ca991e19ef..4be32f9a2c24a3684ed633e97b52d2c4e6af9569 100644 --- a/pysegcnn/core/utils.py +++ b/pysegcnn/core/utils.py @@ -510,6 +510,7 @@ def hdf2tifs(path, outpath=None, overwrite=False, create_stack=True, **kwargs): for ds in hdf: # name of the current subdataset + hdf_ds = gdal.Open(ds[0]) name = ds[0].split(':')[-1].lower() # filename of the GeoTIFF @@ -518,9 +519,14 @@ def hdf2tifs(path, outpath=None, overwrite=False, create_stack=True, **kwargs): # convert hdf subdataset to GeoTIFF LOGGER.info('Converting: {}'.format(tif_name.name)) - gdal.Translate(str(tif_name), gdal.Open(ds[0]), creationOptions=[ + gdal.Translate(str(tif_name), hdf_ds, creationOptions=[ 'COMPRESS=DEFLATE', 'PREDICTOR=1', 'TILED=YES'], **kwargs) + # set metadata field + tif_ds = gdal.Open(str(tif_name)) + tif_ds.SetMetadata(hdf_ds.GetMetadata()) + del tif_ds + # check whether to create a GeoTIFF stack if create_stack: # filename for the GeoTIFF stack