Commit 76f15f8b authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

added a function to get a subset GeoArray

geoarray.baseclasses.GeoArray
- added get_subset()

updated __version__
added __versionalias__ to __init__
parent 84359a44
......@@ -12,4 +12,5 @@ Development Lead
Contributors
------------
None yet. Why not be the first?
* Jessica Palka <jessica.palka@gfz-potsdam.de>
......@@ -2,7 +2,8 @@
__author__ = """Daniel Scheffler"""
__email__ = 'danschef@gfz-potsdam.de'
__version__ = '0.1.0'
__version__ = '0.2.0'
__versionalias__ = 'v20170529.01'
from .baseclasses import GeoArray
......
......@@ -27,7 +27,7 @@ from pandas import DataFrame
from py_tools_ds.ptds.convenience.object_oriented import alias_property
from py_tools_ds.ptds.geo.coord_calc import get_corner_coordinates
from py_tools_ds.ptds.geo.coord_grid import snap_bounds_to_pixGrid
from py_tools_ds.ptds.geo.coord_trafo import mapXY2imXY, transform_any_prj, reproject_shapelyGeometry
from py_tools_ds.ptds.geo.coord_trafo import mapXY2imXY, imXY2mapXY, transform_any_prj, reproject_shapelyGeometry
from py_tools_ds.ptds.geo.projection import prj_equal, WKT2EPSG, EPSG2WKT
from py_tools_ds.ptds.geo.raster.conversion import raster2polygon
from py_tools_ds.ptds.geo.vector.topology \
......@@ -233,7 +233,7 @@ class GeoArray(object):
@property
def geotransform(self):
"""Get the GDAL GeoTransform of the associated image."""
"""Get the GDAL GeoTransform of the associated image, e.g., (283500.0, 5.0, 0.0, 4464500.0, 0.0, -5.0)"""
if self._geotransform:
return self._geotransform
......@@ -1215,6 +1215,39 @@ class GeoArray(object):
return sub_arr, sub_gt, sub_prj
def get_subset(self, xslice=None, yslice=None, zslice=None, return_GeoArray=True):
# type: (slice, slice, slice, bool) -> GeoArray
"""Returns a new instatnce of GeoArray representing a subset of the initial one wit respect to given array position.
:param xslice: a slice providing the X-position for the subset in the form slice(xstart, xend, xstep)
:param yslice: a slice providing the Y-position for the subset in the form slice(ystart, yend, ystep)
:param zslice: a slice providing the Z-position for the subset in the form slice(zstart, zend, zstep)
:param return_GeoArray: whether to return an instance of GeoArray (default) or a tuple(np.ndarray, gt, prj)
:return:
"""
sub_arr = self[xslice if xslice else slice(None),
yslice if yslice else slice(None),
zslice if zslice else slice(None)]
sub_ulXY = imXY2mapXY((xslice.start, yslice.start), self.gt)
sub_gt = (sub_ulXY[0], self.gt[1], self.gt[2], sub_ulXY[1], self.gt[4], self.gt[5])
sub_gA = GeoArray(sub_arr, sub_gt, self.prj)
return sub_gA if return_GeoArray else (sub_arr, sub_gt, self.prj)
# import copy # TODO implement that in order to include all previously set attribute values
# sub_gA = copy.deepcopy(self)
# print(type(sub_gA))
# sub_gA.arr = self[xslice if xslice else slice(None),
# yslice if yslice else slice(None),
# zslice if zslice else slice(None)]
# #sub_gA.deepcopy_array()
# sub_ulXY = imXY2mapXY((xslice.start, yslice.start), self.gt)
# sub_gA.gt = (sub_ulXY[0], self.gt[1], self.gt[2], sub_ulXY[1], self.gt[4], self.gt[5])
#
# return sub_gA if return_GeoArray else (sub_gA.arr, sub_gA.gt, sub_gA.prj)
def reproject_to_new_grid(self, prototype=None, tgt_prj=None, tgt_xygrid=None, rspAlg='cubic', CPUs=None):
"""Reproject all array-like attributes to a given target grid.
......
......@@ -20,7 +20,7 @@ test_requirements = [
setup(
name='geoarray',
version='0.1.0',
version='0.2.0',
description="Fast Python interface for geodata - either on disk or in memory.",
long_description=readme + '\n\n' + history,
author="Daniel Scheffler",
......
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