Commit 9ca01bad authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Fixed warp_ndarray() in case a list of ndarrays is provided.

parent 498c19c5
Pipeline #1456 passed with stages
in 1 minute and 3 seconds
......@@ -240,9 +240,9 @@ def warp_ndarray(ndarray, in_gt, in_prj=None, out_prj=None, out_dtype=None,
# type: () -> (np.ndarray, tuple, str)
"""
:param ndarray: the numpy array to be warped
:param in_gt: input GDAL geotransform
:param in_prj: input GDAL projection (WKT string, 'EPSG:1234', <EPSG_int>),
:param ndarray: numpy array to be warped (or a list of numpy arrays (requires lists for in_gt/in_prj))
:param in_gt: input GDAL geotransform (or a list of GDAL geotransforms)
:param in_prj: input GDAL projection or list of projections (WKT string, 'EPSG:1234', <EPSG_int>),
default: "LOCAL_CS[\"MAP\"]"
:param out_prj: output GDAL projection (WKT string, 'EPSG:1234', <EPSG_int>),
default: "LOCAL_CS[\"MAP\"]"
......@@ -309,6 +309,8 @@ def warp_ndarray(ndarray, in_gt, in_prj=None, out_prj=None, out_dtype=None,
def get_GDT(DT): return dTypeDic_NumPy2GDAL[str(np.dtype(DT))]
in_dtype_np = ndarray.dtype if not isinstance(ndarray, list) else ndarray[0].dtype
# # not yet implemented
# # TODO cutline from OGR datasource. => implement input shapefile or Geopandas dataframe
# cutlineDSName = 'data/cutline.vrt' # '/vsimem/cutline.shp'
......@@ -423,12 +425,11 @@ 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 in_dtype,
outputType=get_GDT(out_dtype) if out_dtype else get_GDT(in_dtype_np),
xRes=out_gsd[0],
yRes=out_gsd[1],
outputBounds=out_bounds,
......@@ -469,8 +470,8 @@ def warp_ndarray(ndarray, in_gt, in_prj=None, out_prj=None, out_dtype=None,
del in_ds, res_ds
# dtype check -> possibly dtype had to be changed for GDAL compatibility
if ndarray.dtype != res_arr.dtype:
res_arr = res_arr.astype(ndarray.dtype)
if in_dtype_np != res_arr.dtype:
res_arr = res_arr.astype(in_dtype_np)
# test output
if out_prj and prj_equal(out_prj, 4626):
......
Supports Markdown
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