Commit 8b4847cb authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Added GeoArray.clip_to_footprint() and GeoArray.clip_to_poly(). Simplified GeoArray.get_mapPos().

parent 2c4104ed
......@@ -1271,6 +1271,24 @@ class GeoArray(object):
print('2 % percentile:', np.percentile(data, 2))
print('98 % percentile:', np.percentile(data, 98))
def clip_to_footprint(self):
"""Clip the GeoArray instance to the outer bounds of the actual footprint."""
def clip_to_poly(self, poly):
"""Clip the GeoArray instance to the outer bounds of a given shapely polygon.
:param poly: instance of shapely.geometry.Polygon
# type: Polygon -> None
self.arr,, self.projection = self.get_mapPos(mapBounds=poly.bounds, mapBounds_prj=self.prj)
self.mask_nodata.arr,, self.mask_nodata.projection = \
self.mask_nodata.get_mapPos(mapBounds=poly.bounds, mapBounds_prj=self.prj)
if self._mask_baddata is not None:
self.mask_baddata.arr,, self.mask_baddata.projection = \
self.mask_baddata.get_mapPos(mapBounds=poly.bounds, mapBounds_prj=self.prj)
def get_mapPos(self, mapBounds, mapBounds_prj, band2get=None, out_prj=None, arr_gt=None, arr_prj=None, fillVal=None,
rspAlg='near', progress=None, v=False): # TODO implement slice for indexing bands
# type: (tuple, str, int, str, tuple, str, int, str, bool, bool) -> (np.ndarray, tuple, str)
......@@ -1293,9 +1311,9 @@ class GeoArray(object):
arr_gt = arr_gt if arr_gt else self.geotransform
arr_prj = arr_prj if arr_prj else self.projection
out_prj = out_prj if out_prj else arr_prj
arr_gt = arr_gt or self.geotransform
arr_prj = arr_prj or self.projection
out_prj = out_prj or arr_prj
fillVal = fillVal if fillVal is not None else self.nodata
progress = progress if progress is not None else self.progress
......@@ -1474,6 +1492,7 @@ class GeoArray(object):
if not self.is_inmem:
# noinspection PyStatementEffect
self[arr_pos] # runs __getitem__ and sets self._arr_cache
pass # no array cache needed because array is in memory anyways
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