Commit 7b1ca393 authored by Daniel Scheffler's avatar Daniel Scheffler

Bugfix for not updating GeoArray.metadata.bands within GeoArray.get_subset().

parent 8a3b342b
Pipeline #3071 failed with stages
in 1 minute and 21 seconds
......@@ -1487,11 +1487,7 @@ class GeoArray(object):
# apply zslice to bandnames and metadata
if zslicing:
bNs_out = list(np.array(list(self.bandnames))[zslice])
_meta_out = deepcopy(self.meta)
if self._metadata:
for k, v in _meta_out.band_meta.items():
_meta_out.band_meta[k] = list(np.array(v)[zslice])
_meta_out = self.metadata.get_band_subset(bandslice=zslice)
else:
bNs_out = list(self.bandnames)
_meta_out = self.meta
......
......@@ -2,8 +2,10 @@
import os
from pprint import pformat
from copy import deepcopy
from geopandas import GeoDataFrame, GeoSeries
import numpy as np
try:
from osgeo import gdal
except ImportError:
......@@ -31,7 +33,7 @@ class GDAL_Metadata(object):
self.bands = nbands
self.filePath = filePath
self.format = ''
self.fileFormat = ''
if filePath:
self.read_from_file(filePath)
......@@ -140,13 +142,13 @@ class GDAL_Metadata(object):
raise Exception('Error reading file: ' + gdal.GetLastErrorMsg())
self.bands = ds.RasterCount
self.format = ds.GetDriver().GetDescription()
self.fileFormat = ds.GetDriver().GetDescription()
###############
# ENVI format #
###############
if self.format == 'ENVI':
if self.fileFormat == 'ENVI':
metadict = ds.GetMetadata('ENVI')
for k, v in metadict.items():
......@@ -201,3 +203,14 @@ class GDAL_Metadata(object):
def to_ENVI_metadict(self):
return dict(zip(self.all_meta.keys(),
[self._convert_param_to_ENVI_str(i) for i in self.all_meta.values()]))
def get_band_subset(self, bandslice=None):
bandslice = bandslice or slice(None)
meta_sub = deepcopy(self)
for k, v in meta_sub.band_meta.items():
meta_sub.band_meta[k] = list(np.array(v)[bandslice])
meta_sub.bands = len(list(range(*bandslice.indices(bandslice.stop))))
return meta_sub
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