Commit 30275f59 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Updated metadata handling (not yet completely working).

parent 4fe5ea39
Pipeline #139 failed with stages
......@@ -673,13 +673,21 @@ class GeoArray(object):
band = ds.GetRasterBand(1)
self._nodata = band.GetNoDataValue() # FIXME this does not support different nodata values within the same file
# read global domain metadata
global_meta = ds.GetMetadata() # TODO check to specifically use the 'ENVI' metadata domain ds.GetMetadata('ENVI')
# read band domain metadata
for b in range(self.bands):
band = ds.GetRasterBand(b+1)
self.metadata[b] = GeoSeries(band.GetMetadata())
band = ds.GetRasterBand(b + 1)
meta_gs = GeoSeries(band.GetMetadata())
# read global domain metadata
# TODO add support for global domain metadata
# add band names if available
if 'Band_%s' % str(b + 1) in global_meta.keys():
meta_gs['band_name'] = global_meta['Band_%s' % str(b + 1)]
# TODO add the remaining global metadata
self.metadata[b] = meta_gs
ds = band = None
......@@ -841,13 +849,30 @@ class GeoArray(object):
# set metadata
if not self.metadata.empty:
global_meta = {}
# set band domain metadata
for bidx in range(self.bands):
band = ds.GetRasterBand(bidx+1)
meta2write = self.metadata[bidx].to_dict()
meta2write = dict((k, v) for k, v in meta2write.items() if not v is np.nan)
if 'band_name' in meta2write:
global_meta['Band_%s'%str(bidx+1)] = meta2write['band_name']
del meta2write['band_name']
band.SetMetadata(meta2write)
band = None
# set global domain metadata
ds.SetMetadata(global_meta)
## get ENVI metadata domain
#ds_orig = gdal.Open(self.filePath)
#envi_meta_domain = ds_orig.GetMetadata('ENVI')
#ds.SetMetadata(envi_meta_domain, 'ENVI')
#ds_orig = None
driver.CreateCopy(out_path, ds, options=creationOptions if creationOptions else [])
#out_arr = self.arr if self.ndim == 2 else np.swapaxes(np.swapaxes(self.arr, 0, 2), 1, 2) # rows, columns, bands => bands, rows, columns
......@@ -1247,6 +1272,7 @@ class GeoArray(object):
sub_gA = GeoArray(sub_arr, sub_gt, self.prj,
bandnames=list(self.bandnames.keys()), nodata=self.nodata, progress=self.progress, q=self.q)
sub_gA.meta = self.meta
sub_gA.filePath = self.filePath
return sub_gA if return_GeoArray else (sub_arr, sub_gt, self.prj)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment