Commit cb1cc079 authored by Jessica Palka's avatar Jessica Palka
Browse files
parents 3206642c ac91043a
......@@ -12,4 +12,5 @@ Development Lead
Contributors
------------
None yet. Why not be the first?
* Jessica Palka <jessica.palka@gfz-potsdam.de>
Welcome to GeoArray's documentation!
======================================
====================================
Contents:
.. toctree::
:maxdepth: 2
:maxdepth: 4
readme
installation
......
......@@ -2,7 +2,8 @@
__author__ = """Daniel Scheffler"""
__email__ = 'danschef@gfz-potsdam.de'
__version__ = '0.1.0'
__version__ = '0.2.3'
__versionalias__ = 'v20170529.04'
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
......@@ -661,6 +661,9 @@ class GeoArray(object):
if not self._gdalDataset_meta_already_set:
assert self.filePath
ds = gdal.Open(self.filePath)
if not ds:
raise Exception('Error reading file: ' + gdal.GetLastErrorMsg())
# set private class variables (in order to avoid recursion error)
self._shape = tuple([ds.RasterYSize, ds.RasterXSize] + ([ds.RasterCount] if ds.RasterCount>1 else []))
self._dtype = gdal_array.GDALTypeCodeToNumericTypeCode(ds.GetRasterBand(1).DataType)
......@@ -691,7 +694,10 @@ class GeoArray(object):
"""
ds = gdal.Open(path)
if not ds: raise IOError('Error reading image data at %s.' %path)
if not ds:
raise Exception('Error reading file: ' + gdal.GetLastErrorMsg())
R, C, B = ds.RasterYSize, ds.RasterXSize, ds.RasterCount
ds = None
......@@ -764,7 +770,7 @@ class GeoArray(object):
# check if the requested array position is already in cache -> if yes, return it from there
if self._arr_cache is not None and self._arr_cache['pos']==arr_pos:
out_arr = self._arr_cache['arr_cached']
out_arr = self._arr_cache['arr_cached']
else:
# TODO insert a multiprocessing.Lock here in order to prevent IO bottlenecks?
......@@ -776,8 +782,6 @@ class GeoArray(object):
out_arr = np.swapaxes(np.swapaxes(tempArr, 0, 2), 0, 1) if B > 1 else tempArr
else:
ds = gdal.Open(path)
if ds is None:
raise Exception('Error reading file: ' + gdal.GetLastErrorMsg())
if len(bL) == 1:
band = ds.GetRasterBand(bL[0] + 1)
out_arr= band.ReadAsArray(cS, rS, cE - cS + 1, rE - rS + 1)
......@@ -848,6 +852,9 @@ class GeoArray(object):
else:
src_ds = gdal.Open(self.filePath)
if not src_ds:
raise Exception('Error reading file: ' + gdal.GetLastErrorMsg())
gdal_Translate = get_gdal_func('Translate')
gdal_Translate(out_path, src_ds, format=fmt, creationOptions=creationOptions)
src_ds = None
......@@ -873,8 +880,8 @@ class GeoArray(object):
image2plot, gt, prj = self.get_mapPos(boundsMap, boundsMapPrj, band2get=band,
fillVal=nodataVal if nodataVal is not None else self.nodata)
else:
cS, cE = xlim if isinstance(xlim, (tuple, list)) else (0, self.columns - 1)
rS, rE = ylim if isinstance(ylim, (tuple, list)) else (0, self.rows - 1)
cS, cE = xlim if isinstance(xlim, (tuple, list)) else (0, self.columns)
rS, rE = ylim if isinstance(ylim, (tuple, list)) else (0, self.rows)
image2plot = self[rS:rE, cS:cE, band] if band is not None else self[rS:rE, cS:cE]
gt, prj = self.geotransform, self.projection
......@@ -1215,6 +1222,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.3',
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