1 /******************************************************************************
2  * $Id: Band.i 4218d17781fe3847a754c85800ef0ce2cc57a551 2021-03-14 14:11:22 +0100 Even Rouault $
3  *
4  * Name:     Band.i
5  * Project:  GDAL Python Interface
6  * Purpose:  GDAL Core SWIG Interface declarations.
7  * Author:   Kevin Ruland, kruland@ku.edu
8  *
9  ******************************************************************************
10  * Copyright (c) 2005, Kevin Ruland
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included
20  * in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28  * DEALINGS IN THE SOFTWARE.
29  *****************************************************************************/
30 
31 /************************************************************************
32  *
33  * Define the extensions for Band (nee GDALRasterBandShadow)
34  *
35 *************************************************************************/
36 
37 %{
38 /* Returned size is in bytes or 0 if an error occurred. */
39 static
ComputeBandRasterIOSize(int buf_xsize,int buf_ysize,int nPixelSize,GIntBig nPixelSpace,GIntBig nLineSpace,int bSpacingShouldBeMultipleOfPixelSize)40 GIntBig ComputeBandRasterIOSize (int buf_xsize, int buf_ysize, int nPixelSize,
41                                  GIntBig nPixelSpace, GIntBig nLineSpace,
42                                  int bSpacingShouldBeMultipleOfPixelSize )
43 {
44     if (buf_xsize <= 0 || buf_ysize <= 0)
45     {
46         CPLError(CE_Failure, CPLE_IllegalArg, "Illegal values for buffer size");
47         return 0;
48     }
49 
50     if (nPixelSpace < 0 || nLineSpace < 0)
51     {
52         CPLError(CE_Failure, CPLE_IllegalArg, "Illegal values for space arguments");
53         return 0;
54     }
55 
56     if (nPixelSize == 0)
57     {
58         CPLError(CE_Failure, CPLE_IllegalArg, "Illegal value for data type");
59         return 0;
60     }
61 
62     if( nPixelSpace == 0 )
63         nPixelSpace = nPixelSize;
64     else if ( bSpacingShouldBeMultipleOfPixelSize && (nPixelSpace % nPixelSize) != 0 )
65     {
66         CPLError(CE_Failure, CPLE_IllegalArg, "nPixelSpace should be a multiple of nPixelSize");
67         return 0;
68     }
69 
70     if( nLineSpace == 0 )
71     {
72         nLineSpace = nPixelSpace * buf_xsize;
73     }
74     else if ( bSpacingShouldBeMultipleOfPixelSize && (nLineSpace % nPixelSize) != 0 )
75     {
76         CPLError(CE_Failure, CPLE_IllegalArg, "nLineSpace should be a multiple of nPixelSize");
77         return 0;
78     }
79 
80     GIntBig nRet = (GIntBig)(buf_ysize - 1) * nLineSpace + (GIntBig)(buf_xsize - 1) * nPixelSpace + nPixelSize;
81 #if SIZEOF_VOIDP == 4
82     if (nRet > INT_MAX)
83     {
84         CPLError(CE_Failure, CPLE_IllegalArg, "Integer overflow");
85         return 0;
86     }
87 #endif
88 
89     return nRet;
90 }
91 %}
92 
93 #if defined(SWIGPERL)
94 %{
95 static
ReadRaster_internal(GDALRasterBandShadow * obj,int xoff,int yoff,int xsize,int ysize,int buf_xsize,int buf_ysize,GDALDataType buf_type,GIntBig * buf_size,char ** buf,GIntBig pixel_space,GIntBig line_space,GDALRasterIOExtraArg * psExtraArg)96 CPLErr ReadRaster_internal( GDALRasterBandShadow *obj,
97                             int xoff, int yoff, int xsize, int ysize,
98                             int buf_xsize, int buf_ysize,
99                             GDALDataType buf_type,
100                             GIntBig *buf_size, char **buf,
101                             GIntBig pixel_space, GIntBig line_space,
102                             GDALRasterIOExtraArg* psExtraArg )
103 {
104   CPLErr result;
105 
106   *buf_size = ComputeBandRasterIOSize( buf_xsize, buf_ysize, GDALGetDataTypeSize( buf_type ) / 8,
107                                        pixel_space, line_space, FALSE );
108 
109   if ( *buf_size == 0 )
110   {
111       *buf = 0;
112       return CE_Failure;
113   }
114 
115   *buf = (char*) malloc( *buf_size );
116   if ( *buf )
117   {
118     result =  GDALRasterIOEx( obj, GF_Read, xoff, yoff, xsize, ysize,
119                                     (void *) *buf, buf_xsize, buf_ysize,
120                                     buf_type, pixel_space, line_space, psExtraArg );
121     if ( result != CE_None )
122     {
123         free( *buf );
124         *buf = 0;
125         *buf_size = 0;
126     }
127   }
128   else
129   {
130     CPLError(CE_Failure, CPLE_OutOfMemory, "Not enough memory to allocate " CPL_FRMT_GIB " bytes", *buf_size);
131     result = CE_Failure;
132     *buf = 0;
133     *buf_size = 0;
134   }
135 
136   return result;
137 }
138 %}
139 #endif
140 
141 #if defined(SWIGPYTHON) || defined(SWIGPERL)
142 %{
143 static
WriteRaster_internal(GDALRasterBandShadow * obj,int xoff,int yoff,int xsize,int ysize,int buf_xsize,int buf_ysize,GDALDataType buf_type,GIntBig buf_size,char * buffer,GIntBig pixel_space,GIntBig line_space,GDALRasterIOExtraArg * psExtraArg)144 CPLErr WriteRaster_internal( GDALRasterBandShadow *obj,
145                              int xoff, int yoff, int xsize, int ysize,
146                              int buf_xsize, int buf_ysize,
147                              GDALDataType buf_type,
148                              GIntBig buf_size, char *buffer,
149                              GIntBig pixel_space, GIntBig line_space,
150                              GDALRasterIOExtraArg* psExtraArg )
151 {
152     GIntBig min_buffer_size = ComputeBandRasterIOSize (buf_xsize, buf_ysize, GDALGetDataTypeSize( buf_type ) / 8,
153                                                    pixel_space, line_space, FALSE );
154     if ( min_buffer_size == 0 )
155       return CE_Failure;
156 
157     if ( buf_size < min_buffer_size ) {
158       CPLError(CE_Failure, CPLE_AppDefined, "Buffer too small");
159       return CE_Failure;
160     }
161 
162     return GDALRasterIOEx( obj, GF_Write, xoff, yoff, xsize, ysize,
163                            (void *) buffer, buf_xsize, buf_ysize, buf_type, pixel_space, line_space, psExtraArg );
164 }
165 %}
166 
167 #endif
168 
169 %rename (Band) GDALRasterBandShadow;
170 
171 class GDALRasterBandShadow : public GDALMajorObjectShadow {
172 private:
173   GDALRasterBandShadow();
174   ~GDALRasterBandShadow();
175 public:
176 %extend {
177 
178 %immutable;
179   int XSize;
180   int YSize;
181   GDALDataType DataType;
182 %mutable;
183 
184   /* Interface method added for GDAL 1.12.0 */
GetDataset()185   GDALDatasetShadow* GetDataset()
186   {
187     return (GDALDatasetShadow*) GDALGetBandDataset(self);
188   }
189 
190   /* Interface method added for GDAL 1.7.0 */
GetBand()191   int GetBand()
192   {
193     return GDALGetBandNumber(self);
194   }
195 
196 %apply (int *OUTPUT){int *pnBlockXSize, int *pnBlockYSize}
197 
GetBlockSize(int * pnBlockXSize,int * pnBlockYSize)198   void GetBlockSize(int *pnBlockXSize, int *pnBlockYSize) {
199       GDALGetBlockSize(self, pnBlockXSize, pnBlockYSize);
200   }
201 
202 #if defined(SWIGPYTHON)
GetActualBlockSize(int nXBlockOff,int nYBlockOff,int * pnxvalid,int * pnyvalid,int * pisvalid)203   void GetActualBlockSize(int nXBlockOff, int nYBlockOff, int* pnxvalid, int* pnyvalid, int* pisvalid)
204   {
205     *pisvalid = (GDALGetActualBlockSize(self, nXBlockOff, nYBlockOff, pnxvalid, pnyvalid) == CE_None);
206   }
207 #endif
208 
209   // Preferred name to match C++ API
210   /* Interface method added for GDAL 1.7.0 */
GetColorInterpretation()211   GDALColorInterp GetColorInterpretation() {
212     return GDALGetRasterColorInterpretation(self);
213   }
214 
215   // Deprecated name
GetRasterColorInterpretation()216   GDALColorInterp GetRasterColorInterpretation() {
217     return GDALGetRasterColorInterpretation(self);
218   }
219 
220   // Preferred name to match C++ API
221   /* Interface method added for GDAL 1.7.0 */
SetColorInterpretation(GDALColorInterp val)222   CPLErr SetColorInterpretation( GDALColorInterp val ) {
223     return GDALSetRasterColorInterpretation( self, val );
224   }
225 
226   // Deprecated name
SetRasterColorInterpretation(GDALColorInterp val)227   CPLErr SetRasterColorInterpretation( GDALColorInterp val ) {
228     return GDALSetRasterColorInterpretation( self, val );
229   }
230 
GetNoDataValue(double * val,int * hasval)231   void GetNoDataValue( double *val, int *hasval ) {
232     *val = GDALGetRasterNoDataValue( self, hasval );
233   }
234 
SetNoDataValue(double d)235   CPLErr SetNoDataValue( double d) {
236     return GDALSetRasterNoDataValue( self, d );
237   }
238 
DeleteNoDataValue()239   CPLErr DeleteNoDataValue() {
240     return GDALDeleteRasterNoDataValue(self);
241   }
242 
243   /* Interface method added for GDAL 1.7.0 */
GetUnitType()244   const char* GetUnitType() {
245       return GDALGetRasterUnitType(self);
246   }
247 
248   /* Interface method added for GDAL 1.8.0 */
SetUnitType(const char * val)249   CPLErr SetUnitType( const char* val ) {
250     return GDALSetRasterUnitType( self, val );
251   }
252 
253   %apply (char **options) { (char **) };
GetRasterCategoryNames()254   char** GetRasterCategoryNames( ) {
255     return GDALGetRasterCategoryNames(self);
256   }
257   %clear (char **);
258 
259   %apply (char **options) { (char **names) };
SetRasterCategoryNames(char ** names)260   CPLErr SetRasterCategoryNames( char **names ) {
261     return GDALSetRasterCategoryNames( self, names );
262   }
263   %clear (char **names);
264 
GetMinimum(double * val,int * hasval)265   void GetMinimum( double *val, int *hasval ) {
266     *val = GDALGetRasterMinimum( self, hasval );
267   }
268 
GetMaximum(double * val,int * hasval)269   void GetMaximum( double *val, int *hasval ) {
270     *val = GDALGetRasterMaximum( self, hasval );
271   }
272 
GetOffset(double * val,int * hasval)273   void GetOffset( double *val, int *hasval ) {
274     *val = GDALGetRasterOffset( self, hasval );
275   }
276 
GetScale(double * val,int * hasval)277   void GetScale( double *val, int *hasval ) {
278     *val = GDALGetRasterScale( self, hasval );
279   }
280 
281   /* Interface method added for GDAL 1.8.0 */
SetOffset(double val)282   CPLErr SetOffset( double val ) {
283     return GDALSetRasterOffset( self, val );
284   }
285 
286   /* Interface method added for GDAL 1.8.0 */
SetScale(double val)287   CPLErr SetScale( double val ) {
288     return GDALSetRasterScale( self, val );
289   }
290 
291 %apply (double *OUTPUT){double *min, double *max, double *mean, double *stddev};
292 %apply (IF_ERROR_RETURN_NONE) { (CPLErr) };
GetStatistics(int approx_ok,int force,double * min,double * max,double * mean,double * stddev)293   CPLErr GetStatistics( int approx_ok, int force,
294                       double *min, double *max, double *mean, double *stddev ){
295     if (min) *min = 0;
296     if (max) *max = 0;
297     if (mean) *mean = 0;
298     if (stddev) *stddev = -1; /* This is the only way to recognize from Python if GetRasterStatistics() has updated the values */
299     return GDALGetRasterStatistics( self, approx_ok, force,
300 				    min, max, mean, stddev );
301   }
302 %clear (CPLErr);
303 
304   /* Interface method added for GDAL 1.7.0 */
305 %apply (double *OUTPUT){double *min, double *max, double *mean, double *stddev};
306 %apply (IF_ERROR_RETURN_NONE) { (CPLErr) };
307   CPLErr ComputeStatistics( bool approx_ok, double *min = NULL, double *max = NULL, double *mean = NULL, double *stddev = NULL,
308                             GDALProgressFunc callback = NULL, void* callback_data=NULL){
309     return GDALComputeRasterStatistics( self, approx_ok, min, max, mean, stddev, callback, callback_data );
310   }
311 %clear (CPLErr);
312 
SetStatistics(double min,double max,double mean,double stddev)313   CPLErr SetStatistics( double min, double max, double mean, double stddev ) {
314     return GDALSetRasterStatistics( self, min, max, mean, stddev );
315   }
316 
GetOverviewCount()317   int GetOverviewCount() {
318     return GDALGetOverviewCount(self);
319   }
320 
GetOverview(int i)321   GDALRasterBandShadow *GetOverview(int i) {
322     return (GDALRasterBandShadow*) GDALGetOverview( self, i );
323   }
324 
325 #if defined (SWIGJAVA)
Checksum(int xoff,int yoff,int xsize,int ysize)326   int Checksum( int xoff, int yoff, int xsize, int ysize) {
327     return GDALChecksumImage( self, xoff, yoff, xsize, ysize );
328   }
329 #else
330 %apply (int *optional_int) {(int*)};
331 %feature ("kwargs") Checksum;
332   int Checksum( int xoff = 0, int yoff = 0, int *xsize = 0, int *ysize = 0) {
333     int nxsize = (xsize!=0) ? *xsize : GDALGetRasterBandXSize( self );
334     int nysize = (ysize!=0) ? *ysize : GDALGetRasterBandYSize( self );
335     return GDALChecksumImage( self, xoff, yoff, nxsize, nysize );
336   }
337 %clear (int*);
338 #endif
339 
340   void ComputeRasterMinMax( double argout[2], int approx_ok = 0) {
341     GDALComputeRasterMinMax( self, approx_ok, argout );
342   }
343 
344   void ComputeBandStats( double argout[2], int samplestep = 1) {
345     GDALComputeBandStats( self, samplestep, argout+0, argout+1,
346                           NULL, NULL );
347   }
348 
349   CPLErr Fill( double real_fill, double imag_fill =0.0 ) {
350     return GDALFillRaster( self, real_fill, imag_fill );
351   }
352 
353 #if defined(SWIGPERL)
354 %apply (GIntBig *nLen, char **pBuf) { (GIntBig *buf_len, char **buf) };
355 %apply (GIntBig *optional_GIntBig) { (GIntBig*) };
356 %apply ( int *optional_int ) {(int*)};
357 %feature( "kwargs" ) ReadRaster;
358   CPLErr ReadRaster( int xoff, int yoff, int xsize, int ysize,
359                      GIntBig *buf_len, char **buf,
360                      int *buf_xsize = 0,
361                      int *buf_ysize = 0,
362                      int *buf_type = 0,
363                      GIntBig *buf_pixel_space = 0,
364                      GIntBig *buf_line_space = 0,
365                      GDALRIOResampleAlg resample_alg = GRIORA_NearestNeighbour,
366                      GDALProgressFunc callback = NULL,
367                      void* callback_data=NULL ) {
368     int nxsize = (buf_xsize==0) ? xsize : *buf_xsize;
369     int nysize = (buf_ysize==0) ? ysize : *buf_ysize;
370     GDALDataType ntype  = (buf_type==0) ? GDALGetRasterDataType(self)
371                                         : (GDALDataType)*buf_type;
372     GIntBig pixel_space = (buf_pixel_space == 0) ? 0 : *buf_pixel_space;
373     GIntBig line_space = (buf_line_space == 0) ? 0 : *buf_line_space;
374 
375     GDALRasterIOExtraArg sExtraArg;
376     INIT_RASTERIO_EXTRA_ARG(sExtraArg);
377     sExtraArg.eResampleAlg = resample_alg;
378     sExtraArg.pfnProgress = callback;
379     sExtraArg.pProgressData = callback_data;
380 
381     return ReadRaster_internal( self, xoff, yoff, xsize, ysize,
382                                 nxsize, nysize, ntype, buf_len, buf, pixel_space, line_space,
383                                 &sExtraArg );
384   }
385 %clear (GIntBig *buf_len, char **buf );
386 %clear (int*);
387 %clear (GIntBig*);
388 #endif
389 
390 #if defined(SWIGPYTHON) || defined(SWIGPERL)
391 %apply (GIntBig nLen, char *pBuf) { (GIntBig buf_len, char *buf_string) };
392 %apply (GIntBig *optional_GIntBig) { (GIntBig*) };
393 %apply ( int *optional_int ) {(int*)};
394 #if defined(SWIGPYTHON)
395 %apply (GDALDataType *optional_GDALDataType) { (GDALDataType *buf_type) };
396 #else
397 %apply (int *optional_int) { (GDALDataType *buf_type) };
398 #endif
399 %feature( "kwargs" ) WriteRaster;
400   CPLErr WriteRaster( int xoff, int yoff, int xsize, int ysize,
401                       GIntBig buf_len, char *buf_string,
402                       int *buf_xsize = 0,
403                       int *buf_ysize = 0,
404                       GDALDataType *buf_type = 0,
405                       GIntBig *buf_pixel_space = 0,
406                       GIntBig *buf_line_space = 0) {
407     int nxsize = (buf_xsize==0) ? xsize : *buf_xsize;
408     int nysize = (buf_ysize==0) ? ysize : *buf_ysize;
409     GDALDataType ntype  = (buf_type==0) ? GDALGetRasterDataType(self)
410                                         : *buf_type;
411     GIntBig pixel_space = (buf_pixel_space == 0) ? 0 : *buf_pixel_space;
412     GIntBig line_space = (buf_line_space == 0) ? 0 : *buf_line_space;
413     GDALRasterIOExtraArg* psExtraArg = NULL;
414     return WriteRaster_internal( self, xoff, yoff, xsize, ysize,
415                                  nxsize, nysize, ntype, buf_len, buf_string, pixel_space, line_space, psExtraArg );
416   }
417 %clear (GIntBig buf_len, char *buf_string);
418 %clear (GDALDataType *buf_type);
419 %clear (int*);
420 %clear (GIntBig*);
421 #endif
422 
FlushCache()423   void FlushCache() {
424     GDALFlushRasterCache( self );
425   }
426 
427   // Deprecated name
GetRasterColorTable()428   GDALColorTableShadow *GetRasterColorTable() {
429     return (GDALColorTableShadow*) GDALGetRasterColorTable( self );
430   }
431 
432   // Preferred name to match C++ API
GetColorTable()433   GDALColorTableShadow *GetColorTable() {
434     return (GDALColorTableShadow*) GDALGetRasterColorTable( self );
435   }
436 
437   // Deprecated name
SetRasterColorTable(GDALColorTableShadow * arg)438   int SetRasterColorTable( GDALColorTableShadow *arg ) {
439     return GDALSetRasterColorTable( self, arg );
440   }
441 
442   // Preferred name to match C++ API
SetColorTable(GDALColorTableShadow * arg)443   int SetColorTable( GDALColorTableShadow *arg ) {
444     return GDALSetRasterColorTable( self, arg );
445   }
446 
GetDefaultRAT()447   GDALRasterAttributeTableShadow *GetDefaultRAT() {
448       return (GDALRasterAttributeTableShadow*) GDALGetDefaultRAT(self);
449   }
450 
SetDefaultRAT(GDALRasterAttributeTableShadow * table)451   int SetDefaultRAT( GDALRasterAttributeTableShadow *table ) {
452       return GDALSetDefaultRAT(self, table);
453   }
454 
GetMaskBand()455   GDALRasterBandShadow *GetMaskBand() {
456       return (GDALRasterBandShadow *) GDALGetMaskBand( self );
457   }
458 
GetMaskFlags()459   int GetMaskFlags() {
460       return GDALGetMaskFlags( self );
461   }
462 
CreateMaskBand(int nFlags)463   CPLErr CreateMaskBand( int nFlags ) {
464       return GDALCreateMaskBand( self, nFlags );
465   }
466 
467 #if defined(SWIGPYTHON) || defined(SWIGPERL)
468 #if defined(SWIGPERL)
469 %apply (int len, GUIntBig *output) {(int buckets, GUIntBig *panHistogram)};
470 %apply (IF_ERROR_RETURN_NONE) { (CPLErr) };
471 #endif
472 %feature( "kwargs" ) GetHistogram;
473   CPLErr GetHistogram( double min=-0.5,
474                      double max=255.5,
475                      int buckets=256,
476                      GUIntBig *panHistogram = NULL,
477                      int include_out_of_range = 0,
478                      int approx_ok = 1,
479                      GDALProgressFunc callback = NULL,
480                      void* callback_data=NULL ) {
481     CPLErrorReset();
482     CPLErr err = GDALGetRasterHistogramEx( self, min, max, buckets, panHistogram,
483                                          include_out_of_range, approx_ok,
484                                          callback, callback_data );
485     return err;
486   }
487 #if defined(SWIGPERL)
488 %clear (int buckets, int *panHistogram);
489 %clear (CPLErr);
490 #endif
491 #else
492 #ifndef SWIGJAVA
493 #if defined(SWIGCSHARP)
494 %apply (int inout[ANY]) {int *panHistogram};
495 #endif
496 %feature( "kwargs" ) GetHistogram;
497   CPLErr GetHistogram( double min=-0.5,
498                      double max=255.5,
499                      int buckets=256,
500                      int *panHistogram = NULL,
501                      int include_out_of_range = 0,
502                      int approx_ok = 1,
503                      GDALProgressFunc callback = NULL,
504                      void* callback_data=NULL ) {
505     CPLErrorReset();
506     CPLErr err = GDALGetRasterHistogram( self, min, max, buckets, panHistogram,
507                                          include_out_of_range, approx_ok,
508                                          callback, callback_data );
509     return err;
510   }
511 #if defined(SWIGCSHARP)
512 %clear int *panHistogram;
513 #endif
514 #endif
515 #endif
516 
517 #if defined(SWIGPYTHON) || defined(SWIGPERL)
518 #if defined(SWIGPERL)
519 %apply (double *OUTPUT){double *min_ret, double *max_ret}
520 %apply (int *nLen, const GUIntBig **pList) {(int *buckets_ret, GUIntBig **ppanHistogram)};
521 %apply (IF_ERROR_RETURN_NONE) { (CPLErr) };
522 #endif
523 %feature ("kwargs") GetDefaultHistogram;
524 CPLErr GetDefaultHistogram( double *min_ret=NULL, double *max_ret=NULL, int *buckets_ret = NULL,
525                             GUIntBig **ppanHistogram = NULL, int force = 1,
526                             GDALProgressFunc callback = NULL,
527                             void* callback_data=NULL ) {
528     return GDALGetDefaultHistogramEx( self, min_ret, max_ret, buckets_ret,
529                                     ppanHistogram, force,
530                                     callback, callback_data );
531 }
532 #if defined(SWIGPERL)
533 %clear (double *min_ret, double *max_ret);
534 %clear (int *buckets_ret, int **ppanHistogram);
535 %clear (CPLErr);
536 #endif
537 #else
538 #ifndef SWIGJAVA
539 %feature ("kwargs") GetDefaultHistogram;
540 CPLErr GetDefaultHistogram( double *min_ret=NULL, double *max_ret=NULL, int *buckets_ret = NULL,
541                             int **ppanHistogram = NULL, int force = 1,
542 			    GDALProgressFunc callback = NULL,
543                             void* callback_data=NULL ) {
544     return GDALGetDefaultHistogram( self, min_ret, max_ret, buckets_ret,
545                                     ppanHistogram, force,
546                                     callback, callback_data );
547 }
548 #endif
549 #endif
550 
551 #if defined(SWIGPYTHON) || defined(SWIGPERL)
552 %apply (int nList, GUIntBig* pList) {(int buckets_in, GUIntBig *panHistogram_in)}
SetDefaultHistogram(double min,double max,int buckets_in,GUIntBig * panHistogram_in)553 CPLErr SetDefaultHistogram( double min, double max,
554                             int buckets_in, GUIntBig *panHistogram_in ) {
555     return GDALSetDefaultHistogramEx( self, min, max,
556                                     buckets_in, panHistogram_in );
557 }
558 %clear (int buckets_in, GUIntBig *panHistogram_in);
559 #else
560 #if defined(SWIGJAVA)
561 %apply (int nList, int* pList) {(int buckets_in, int *panHistogram_in)}
562 #endif
SetDefaultHistogram(double min,double max,int buckets_in,int * panHistogram_in)563 CPLErr SetDefaultHistogram( double min, double max,
564        			    int buckets_in, int *panHistogram_in ) {
565     return GDALSetDefaultHistogram( self, min, max,
566     	   			    buckets_in, panHistogram_in );
567 }
568 #if defined(SWIGJAVA)
569 %clear (int buckets_in, int *panHistogram_in);
570 #endif
571 #endif
572 
573   /* Interface method added for GDAL 1.7.0 */
HasArbitraryOverviews()574   bool HasArbitraryOverviews() {
575       return (GDALHasArbitraryOverviews( self ) != 0) ? true : false;
576   }
577 
578   /* Interface method added for GDAL 1.9.0 */
579 %apply (char **options) {char **};
GetCategoryNames()580   char **GetCategoryNames() {
581     return GDALGetRasterCategoryNames( self );
582   }
583 %clear char **;
584 
585 %apply (char **options) { char ** papszCategoryNames };
SetCategoryNames(char ** papszCategoryNames)586   CPLErr SetCategoryNames( char ** papszCategoryNames ) {
587     return GDALSetRasterCategoryNames( self, papszCategoryNames );
588   }
589 %clear char **papszMetadata;
590 
591 #if defined(SWIGPYTHON)
592 %feature( "kwargs" ) GetVirtualMem;
593 %newobject GetVirtualMem;
594   CPLVirtualMemShadow* GetVirtualMem( GDALRWFlag eRWFlag,
595                                       int nXOff, int nYOff,
596                                       int nXSize, int nYSize,
597                                       int nBufXSize, int nBufYSize,
598                                       GDALDataType eBufType,
599                                       size_t nCacheSize,
600                                       size_t nPageSizeHint,
601                                       char **options = NULL )
602     {
603         CPLVirtualMem* vmem = GDALRasterBandGetVirtualMem( self,
604                                          eRWFlag,
605                                          nXOff, nYOff,
606                                          nXSize, nYSize,
607                                          nBufXSize, nBufYSize,
608                                          eBufType,
609                                          0,
610                                          0,
611                                          nCacheSize,
612                                          nPageSizeHint,
613                                          FALSE,
614                                          options );
615         if( vmem == NULL )
616             return NULL;
617         CPLVirtualMemShadow* vmemshadow = (CPLVirtualMemShadow*)calloc(1, sizeof(CPLVirtualMemShadow));
618         vmemshadow->vmem = vmem;
619         vmemshadow->eBufType = eBufType;
620         vmemshadow->bIsBandSequential = TRUE;
621         vmemshadow->bReadOnly = (eRWFlag == GF_Read);
622         vmemshadow->nBufXSize = nBufXSize;
623         vmemshadow->nBufYSize = nBufYSize;
624         vmemshadow->nBandCount = 1;
625         return vmemshadow;
626     }
627 
628 %feature( "kwargs" ) GetVirtualMemAuto;
629 %newobject GetVirtualMemAuto;
630   CPLVirtualMemShadow* GetVirtualMemAuto( GDALRWFlag eRWFlag,
631                                           char **options = NULL )
632     {
633         int            nPixelSpace;
634         GIntBig        nLineSpace;
635         CPLVirtualMem* vmem = GDALGetVirtualMemAuto( self,
636                                          eRWFlag,
637                                          &nPixelSpace,
638                                          &nLineSpace,
639                                          options );
640         if( vmem == NULL )
641             return NULL;
642         CPLVirtualMemShadow* vmemshadow = (CPLVirtualMemShadow*)calloc(1, sizeof(CPLVirtualMemShadow));
643         vmemshadow->vmem = vmem;
644         vmemshadow->eBufType = GDALGetRasterDataType( self );
645         vmemshadow->bAuto = TRUE;
646         vmemshadow->bReadOnly = (eRWFlag == GF_Read);
647         vmemshadow->nBandCount = 1;
648         vmemshadow->nPixelSpace = nPixelSpace;
649         vmemshadow->nLineSpace = nLineSpace;
650         vmemshadow->nBufXSize = GDALGetRasterBandXSize(self);
651         vmemshadow->nBufYSize = GDALGetRasterBandYSize(self);
652         return vmemshadow;
653     }
654 
655 %feature( "kwargs" ) GetTiledVirtualMem;
656 %newobject GetTiledVirtualMem;
657   CPLVirtualMemShadow* GetTiledVirtualMem( GDALRWFlag eRWFlag,
658                                       int nXOff, int nYOff,
659                                       int nXSize, int nYSize,
660                                       int nTileXSize, int nTileYSize,
661                                       GDALDataType eBufType,
662                                       size_t nCacheSize,
663                                       char **options = NULL )
664     {
665         CPLVirtualMem* vmem = GDALRasterBandGetTiledVirtualMem( self,
666                                          eRWFlag,
667                                          nXOff, nYOff,
668                                          nXSize, nYSize,
669                                          nTileXSize, nTileYSize,
670                                          eBufType,
671                                          nCacheSize,
672                                          FALSE,
673                                          options );
674         if( vmem == NULL )
675             return NULL;
676         CPLVirtualMemShadow* vmemshadow = (CPLVirtualMemShadow*)calloc(1, sizeof(CPLVirtualMemShadow));
677         vmemshadow->vmem = vmem;
678         vmemshadow->eBufType = eBufType;
679         vmemshadow->bIsBandSequential = -1;
680         vmemshadow->bReadOnly = (eRWFlag == GF_Read);
681         vmemshadow->nBufXSize = nXSize;
682         vmemshadow->nBufYSize = nYSize;
683         vmemshadow->eTileOrganization = GTO_BSQ;
684         vmemshadow->nTileXSize = nTileXSize;
685         vmemshadow->nTileYSize = nTileYSize;
686         vmemshadow->nBandCount = 1;
687         return vmemshadow;
688     }
689 
690 #endif /* #if defined(SWIGPYTHON) */
691 
692 #if defined(SWIGPYTHON)
693     // Check with other bindings how to return both the integer status and
694     // *pdfDataPct
695 
696     %apply (double *OUTPUT) {(double *)};
697     int GetDataCoverageStatus( int nXOff, int nYOff,
698                                int nXSize, int nYSize,
699                                int nMaskFlagStop = 0,
700                                double* pdfDataPct = NULL)
701     {
702         return GDALGetDataCoverageStatus(self, nXOff, nYOff,
703                                          nXSize, nYSize,
704                                          nMaskFlagStop,
705                                          pdfDataPct);
706     }
707     %clear (double *);
708 #endif
709 
710 %apply (int *optional_int) { (GDALDataType *buf_type) };
711 CPLErr AdviseRead(  int xoff, int yoff, int xsize, int ysize,
712                     int *buf_xsize = 0, int *buf_ysize = 0,
713                     GDALDataType *buf_type = 0,
714                     char** options = NULL )
715 {
716     int nxsize = (buf_xsize==0) ? xsize : *buf_xsize;
717     int nysize = (buf_ysize==0) ? ysize : *buf_ysize;
718     GDALDataType ntype;
719     if ( buf_type != 0 ) {
720       ntype = (GDALDataType) *buf_type;
721     } else {
722       ntype = GDALGetRasterDataType( self );
723     }
724     return GDALRasterAdviseRead(self, xoff, yoff, xsize, ysize,
725                                 nxsize, nysize, ntype, options);
726 }
727 %clear (GDALDataType *buf_type);
728 %clear (int band_list, int *pband_list );
729 
730 %newobject AsMDArray;
AsMDArray()731   GDALMDArrayHS *AsMDArray()
732   {
733     return GDALRasterBandAsMDArray(self);
734   }
735 
736 } /* %extend */
737 
738 };
739 
740 %{
GDALRasterBandShadow_DataType_get(GDALRasterBandShadow * h)741 GDALDataType GDALRasterBandShadow_DataType_get( GDALRasterBandShadow *h ) {
742   return GDALGetRasterDataType( h );
743 }
GDALRasterBandShadow_XSize_get(GDALRasterBandShadow * h)744 int GDALRasterBandShadow_XSize_get( GDALRasterBandShadow *h ) {
745   return GDALGetRasterBandXSize( h );
746 }
GDALRasterBandShadow_YSize_get(GDALRasterBandShadow * h)747 int GDALRasterBandShadow_YSize_get( GDALRasterBandShadow *h ) {
748   return GDALGetRasterBandYSize( h );
749 }
750 %}
751