Commit 1ec5e10c authored by Daniel Scheffler's avatar Daniel Scheffler

Fix for broken GeoArray.get_subset() in case GeoArray.is_inmem == True.

parent 8292fce7
Pipeline #3086 passed with stages
in 1 minute and 24 seconds
......@@ -1471,6 +1471,9 @@ class GeoArray(object):
yslicing = yslice.start is not None or yslice.stop is not None or yslice.step is not None # type: bool
zslicing = zslice.start is not None or zslice.stop is not None or zslice.step is not None # type: bool
# get array subset #
####################
# get sub_arr
if zslicing:
# validation
......@@ -1484,25 +1487,26 @@ class GeoArray(object):
if sub_arr is None:
raise ValueError('Unable to return an array for the given slice parameters.')
# copy GeoArray instance #
##########################
# get deepcopy of self (but without slowly copying the full-size self.arr)
# -> cache self.arr, overwrite with subset, quickly create sub_gA and recreate self.arr
# -> do the same with attributes 'mask_nodata' and 'mask_baddata'
from .masks import NoDataMask, BadDataMask
full_arr = self.arr
self.arr = sub_arr
full_mask_nodata = self._mask_nodata
full_mask_baddata = self._mask_baddata
from .masks import NoDataMask, BadDataMask
full_mask_nodata = None
self.arr = sub_arr
if isinstance(self._mask_nodata, NoDataMask): # avoid computing it here by using private
full_mask_nodata = self._mask_nodata
self._mask_nodata = self._mask_nodata.get_subset(xslice=xslice, yslice=yslice)
full_mask_baddata = None
if isinstance(self._mask_baddata, BadDataMask): # avoid computing it here by using private
full_mask_baddata = self._mask_baddata
self._mask_baddata = self._mask_baddata.get_subset(xslice=xslice, yslice=yslice)
sub_gA = deepcopy(self) # do not copy any references, otherwise numpy arrays would be copied as views
self.arr = full_arr
self._arr = full_arr
if isinstance(self._mask_nodata, NoDataMask):
self._mask_nodata = full_mask_nodata
if isinstance(self._mask_baddata, BadDataMask):
......@@ -1511,6 +1515,9 @@ class GeoArray(object):
# numpy array references need to be cleared separately (also called by self._mask_nodata.get_subset() above)
sub_gA.deepcopy_array()
# handle metadata #
###################
# adapt geotransform
sub_ulXY = imXY2mapXY((xslice.start or 0, yslice.start or 0), self.gt)
sub_gt = (sub_ulXY[0], self.gt[1], self.gt[2], sub_ulXY[1], self.gt[4], self.gt[5])
......
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