Skip to content
Snippets Groups Projects
Commit 498c19c5 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Added function numeric.array.get_array_tilebounds + tests.

parent 29c088b7
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -288,7 +288,6 @@ def warp_ndarray(ndarray, in_gt, in_prj=None, out_prj=None, out_dtype=None,
in_prj = out_prj = out_bounds_prj = "LOCAL_CS[\"MAP\"]"
# assertions
assert str(np.dtype(ndarray.dtype)) in dTypeDic_NumPy2GDAL, "Unknown target datatype '%s'." % ndarray.dtype
if rspAlg == 'average':
is_avail_rsp_average = int(gdal.VersionInfo()[0]) >= 2
if not is_avail_rsp_average:
......@@ -296,6 +295,14 @@ def warp_ndarray(ndarray, in_gt, in_prj=None, out_prj=None, out_dtype=None,
"'cubic' is used instead. To avoid this please update GDAL to a version above 2.0.0!")
rspAlg = 'cubic'
if not isinstance(ndarray, list):
assert str(np.dtype(ndarray.dtype)) in dTypeDic_NumPy2GDAL, "Unknown target datatype '%s'." % ndarray.dtype
else:
assert str(np.dtype(ndarray[0].dtype)) in dTypeDic_NumPy2GDAL, "Unknown target datatype '%s'." % ndarray.dtype
assert isinstance(in_gt, list), "If 'ndarray' is a list, 'in_gt' must also be a list!"
assert isinstance(in_prj, list), "If 'ndarray' is a list, 'in_prj' must also be a list!"
assert len(list(set([arr.dtype for arr in ndarray]))) == 1, "Data types of input ndarray list must be equal."
def get_SRS(prjArg):
return prjArg if isinstance(prjArg, str) and prjArg.startswith('EPSG:') else \
'EPSG:%s' % prjArg if isinstance(prjArg, int) else prjArg
......@@ -385,7 +392,11 @@ def warp_ndarray(ndarray, in_gt, in_prj=None, out_prj=None, out_dtype=None,
"""
# get input dataset (in-MEM)
if not isinstance(ndarray, list):
in_ds = get_GDAL_ds_inmem(ndarray, in_gt, in_prj)
else:
# list of ndarrays
in_ds = [get_GDAL_ds_inmem(arr, gt, prj) for arr, gt, prj in zip(ndarray, in_gt, in_prj)]
# set RPCs
# if rpcList:
......@@ -412,11 +423,12 @@ def warp_ndarray(ndarray, in_gt, in_prj=None, out_prj=None, out_dtype=None,
# NOTE: options = ['SPARSE_OK=YES'] ## => what is that for?
# GDAL Warp
in_dtype = get_GDT(ndarray.dtype) if not isinstance(ndarray, list) else get_GDT(ndarray[0].dtype)
gdal_Warp = get_gdal_func('Warp')
res_ds = gdal_Warp(
'', in_ds, format='MEM',
dstSRS=get_SRS(out_prj),
outputType=get_GDT(out_dtype) if out_dtype else get_GDT(ndarray.dtype),
outputType=get_GDT(out_dtype) if out_dtype else in_dtype,
xRes=out_gsd[0],
yRes=out_gsd[1],
outputBounds=out_bounds,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment