86
86
%include "python_exceptions.i"
87
87
%include "python_strings.i"
89
%import typemaps_python.i
91
/* -------------------------------------------------------------------- */
93
/* -------------------------------------------------------------------- */
95
%rename (VSIFReadL) wrapper_VSIFReadL;
97
%apply ( void **outPythonObject ) { (void **buf ) };
99
int wrapper_VSIFReadL( void **buf, int nMembSize, int nMembCount, VSILFILE *fp)
101
GIntBig buf_size = nMembSize * nMembCount;
108
#if PY_VERSION_HEX >= 0x03000000
109
*buf = (void *)PyBytes_FromStringAndSize( NULL, buf_size );
113
CPLError(CE_Failure, CPLE_OutOfMemory, "Cannot allocate result buffer");
116
PyObject* o = (PyObject*) *buf;
117
char *data = PyBytes_AsString(o);
118
GIntBig nRet = (GIntBig)VSIFReadL( data, nMembSize, nMembCount, fp );
119
if (nRet * nMembSize < buf_size)
121
_PyBytes_Resize(&o, nRet * nMembSize);
126
*buf = (void *)PyString_FromStringAndSize( NULL, buf_size );
129
CPLError(CE_Failure, CPLE_OutOfMemory, "Cannot allocate result buffer");
132
PyObject* o = (PyObject*) *buf;
133
char *data = PyString_AsString(o);
134
GIntBig nRet = (GIntBig)VSIFReadL( data, nMembSize, nMembCount, fp );
135
if (nRet * nMembSize < buf_size)
137
_PyString_Resize(&o, nRet * nMembSize);
144
%clear (void **buf );
146
/* -------------------------------------------------------------------- */
148
/* -------------------------------------------------------------------- */
89
150
%extend GDAL_GCP {
91
152
def __str__(self):
115
176
%extend GDALRasterBandShadow {
177
%apply ( void **outPythonObject ) { (void **buf ) };
178
%apply ( int *optional_int ) {(int*)};
179
%feature( "kwargs" ) ReadRaster1;
180
CPLErr ReadRaster1( int xoff, int yoff, int xsize, int ysize,
185
int *buf_pixel_space = 0,
186
int *buf_line_space = 0) {
187
int nxsize = (buf_xsize==0) ? xsize : *buf_xsize;
188
int nysize = (buf_ysize==0) ? ysize : *buf_ysize;
189
GDALDataType ntype = (buf_type==0) ? GDALGetRasterDataType(self)
190
: (GDALDataType)*buf_type;
191
int pixel_space = (buf_pixel_space == 0) ? 0 : *buf_pixel_space;
192
int line_space = (buf_line_space == 0) ? 0 : *buf_line_space;
194
GIntBig buf_size = ComputeBandRasterIOSize( nxsize, nysize, GDALGetDataTypeSize( ntype ) / 8,
195
pixel_space, line_space, FALSE );
201
%#if PY_VERSION_HEX >= 0x03000000
202
*buf = (void *)PyBytes_FromStringAndSize( NULL, buf_size );
206
CPLError(CE_Failure, CPLE_OutOfMemory, "Cannot allocate result buffer");
209
char *data = PyBytes_AsString( (PyObject *)*buf );
211
*buf = (void *)PyString_FromStringAndSize( NULL, buf_size );
214
CPLError(CE_Failure, CPLE_OutOfMemory, "Cannot allocate result buffer");
217
char *data = PyString_AsString( (PyObject *)*buf );
219
CPLErr eErr = GDALRasterIO( self, GF_Read, xoff, yoff, xsize, ysize,
220
(void *) data, nxsize, nysize, ntype,
221
pixel_space, line_space );
222
if (eErr == CE_Failure)
224
Py_DECREF((PyObject*)*buf);
229
%clear (void **buf );
234
def ReadRaster(self, xoff, yoff, xsize, ysize,
235
buf_xsize = None, buf_ysize = None, buf_type = None,
236
buf_pixel_space = None, buf_line_space = None ):
238
return _gdal.Band_ReadRaster1(self, xoff, yoff, xsize, ysize,
239
buf_xsize, buf_ysize, buf_type,
240
buf_pixel_space, buf_line_space)
117
242
def ReadAsArray(self, xoff=0, yoff=0, win_xsize=None, win_ysize=None,
118
243
buf_xsize=None, buf_ysize=None, buf_obj=None):
119
244
import gdalnumeric
136
261
%extend GDALDatasetShadow {
262
%feature("kwargs") ReadRaster1;
263
%apply (int *optional_int) { (GDALDataType *buf_type) };
264
%apply (int nList, int *pList ) { (int band_list, int *pband_list ) };
265
%apply ( void **outPythonObject ) { (void **buf ) };
266
%apply ( int *optional_int ) {(int*)};
267
CPLErr ReadRaster1( int xoff, int yoff, int xsize, int ysize,
269
int *buf_xsize = 0, int *buf_ysize = 0,
270
GDALDataType *buf_type = 0,
271
int band_list = 0, int *pband_list = 0,
272
int* buf_pixel_space = 0, int* buf_line_space = 0, int* buf_band_space = 0 )
274
int nxsize = (buf_xsize==0) ? xsize : *buf_xsize;
275
int nysize = (buf_ysize==0) ? ysize : *buf_ysize;
277
if ( buf_type != 0 ) {
278
ntype = (GDALDataType) *buf_type;
280
int lastband = GDALGetRasterCount( self ) - 1;
286
ntype = GDALGetRasterDataType( GDALGetRasterBand( self, lastband ) );
289
int pixel_space = (buf_pixel_space == 0) ? 0 : *buf_pixel_space;
290
int line_space = (buf_line_space == 0) ? 0 : *buf_line_space;
291
int band_space = (buf_band_space == 0) ? 0 : *buf_band_space;
293
GIntBig buf_size = ComputeDatasetRasterIOSize (nxsize, nysize, GDALGetDataTypeSize( ntype ) / 8,
294
band_list ? band_list : GDALGetRasterCount(self), pband_list, band_list,
295
pixel_space, line_space, band_space, FALSE);
302
%#if PY_VERSION_HEX >= 0x03000000
303
*buf = (void *)PyBytes_FromStringAndSize( NULL, buf_size );
306
CPLError(CE_Failure, CPLE_OutOfMemory, "Cannot allocate result buffer");
309
char *data = PyBytes_AsString( (PyObject *)*buf );
311
*buf = (void *)PyString_FromStringAndSize( NULL, buf_size );
314
CPLError(CE_Failure, CPLE_OutOfMemory, "Cannot allocate result buffer");
317
char *data = PyString_AsString( (PyObject *)*buf );
320
CPLErr eErr = GDALDatasetRasterIO(self, GF_Read, xoff, yoff, xsize, ysize,
321
(void*) data, nxsize, nysize, ntype,
322
band_list, pband_list, pixel_space, line_space, band_space );
323
if (eErr == CE_Failure)
325
Py_DECREF((PyObject*)*buf);
331
%clear (GDALDataType *buf_type);
332
%clear (int band_list, int *pband_list );
333
%clear (void **buf );
138
337
def ReadAsArray(self, xoff=0, yoff=0, xsize=None, ysize=None, buf_obj=None ):
139
338
import gdalnumeric
173
372
if buf_type is None:
174
373
buf_type = self.GetRasterBand(1).DataType;
175
return _gdal.Dataset_ReadRaster(self, xoff, yoff, xsize, ysize,
176
buf_xsize, buf_ysize, buf_type,
177
band_list, buf_pixel_space, buf_line_space, buf_band_space )
375
return _gdal.Dataset_ReadRaster1(self, xoff, yoff, xsize, ysize,
376
buf_xsize, buf_ysize, buf_type,
377
band_list, buf_pixel_space, buf_line_space, buf_band_space )
179
379
def GetSubDatasets(self):
189
389
sd['SUBDATASET_'+str(i)+'_DESC'] ) )
393
def BeginAsyncReader(self, xoff, yoff, xsize, ysize, buf_obj = None, buf_xsize = None, buf_ysize = None, buf_type = None, band_list = None, options=[]):
394
if band_list is None:
395
band_list = range(1, self.RasterCount + 1)
396
if buf_xsize is None:
398
if buf_ysize is None:
409
from sys import version_info
410
nRequiredSize = int(buf_xsize * buf_ysize * len(band_list) * (_gdal.GetDataTypeSize(buf_type) / 8))
411
if version_info >= (3,0,0):
412
buf_obj_ar = [ None ]
413
exec("buf_obj_ar[0] = b' ' * nRequiredSize")
414
buf_obj = buf_obj_ar[0]
416
buf_obj = ' ' * nRequiredSize
417
return _gdal.Dataset_BeginAsyncReader(self, xoff, yoff, xsize, ysize, buf_obj, buf_xsize, buf_ysize, buf_type, band_list, 0, 0, 0, options)