Skip to content

Commit 519632d

Browse files
committed
Python bindings: Add mask_resample_alg arg to ReadAsArray methods
1 parent 8704959 commit 519632d

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

swig/include/python/gdal_python.i

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -599,15 +599,18 @@ void wrapper_VSIGetMemFileBuffer(const char *utf8_path, GByte **out, vsi_l_offse
599599
def ReadAsMaskedArray(self, xoff=0, yoff=0, win_xsize=None, win_ysize=None,
600600
buf_xsize=None, buf_ysize=None, buf_type=None,
601601
resample_alg=gdalconst.GRIORA_NearestNeighbour,
602+
mask_resample_alg=gdalconst.GRIORA_NearestNeighbour,
602603
callback=None,
603604
callback_data=None):
604605
"""
605606
Read a window of this raster band into a NumPy masked array.
606607
607608
Values of the mask will be ``True`` where pixels are invalid.
609+
610+
If resampling (``buf_xsize`` != ``xsize``, or ``buf_ysize`` != ``ysize``) the mask band will be resampled
611+
using the algorithm specified by ``mask_resample_alg``.
608612
609-
See :py:meth:`ReadAsArray` for a description of arguments.
610-
613+
See :py:meth:`ReadAsArray` for a description of additional arguments.
611614
"""
612615
import numpy
613616
array = self.ReadAsArray(xoff=xoff, yoff=yoff,
@@ -625,7 +628,7 @@ void wrapper_VSIGetMemFileBuffer(const char *utf8_path, GByte **out, vsi_l_offse
625628
win_ysize=win_ysize,
626629
buf_xsize=buf_xsize,
627630
buf_ysize=buf_ysize,
628-
resample_alg=resample_alg).astype(bool)
631+
resample_alg=mask_resample_alg).astype(bool)
629632
else:
630633
mask_array = None
631634
return numpy.ma.array(array, mask=mask_array)
@@ -1113,13 +1116,19 @@ CPLErr ReadRaster1( double xoff, double yoff, double xsize, double ysize,
11131116
def ReadAsMaskedArray(self, xoff=0, yoff=0, xsize=None, ysize=None,
11141117
buf_xsize=None, buf_ysize=None, buf_type=None,
11151118
resample_alg=gdalconst.GRIORA_NearestNeighbour,
1119+
mask_resample_alg=gdalconst.GRIORA_NearestNeighbour,
11161120
callback=None,
11171121
callback_data=None,
11181122
band_list=None):
11191123
"""
11201124
Read a window from raster bands into a NumPy masked array.
11211125
1122-
Parameters are the same as for :py:meth:`ReadAsArray`.
1126+
Values of the mask will be ``True`` where pixels are invalid.
1127+
1128+
If resampling (``buf_xsize`` != ``xsize``, or ``buf_ysize`` != ``ysize``) the mask band will be resampled
1129+
using the algorithm specified by ``mask_resample_alg``.
1130+
1131+
See :py:meth:`ReadAsArray` for a description of additional arguments.
11231132
"""
11241133

11251134
import numpy as np
@@ -1140,7 +1149,7 @@ CPLErr ReadRaster1( double xoff, double yoff, double xsize, double ysize,
11401149
xoff=xoff, yoff=yoff,
11411150
win_xsize=xsize, win_ysize=ysize,
11421151
buf_xsize=buf_xsize, buf_ysize=buf_ysize,
1143-
resample_alg=gdalconst.GRIORA_Mode) != 255
1152+
resample_alg=mask_resample_alg) != 255
11441153
for band in band_list]
11451154

11461155
return np.ma.masked_array(arr, np.vstack(masks))

0 commit comments

Comments
 (0)