/****************************************************************************** * $Id$ * * Name: Band.i * Project: GDAL Python Interface * Purpose: GDAL Core SWIG Interface declarations. * Author: Kevin Ruland, kruland@ku.edu * * * $Log$ * Revision 1.11 2005/03/10 17:19:08 hobu * #ifdefs for csharp * * Revision 1.10 2005/02/23 17:44:00 kruland * Added GetMetadata, SetMetadata, SetRasterColorInterpretation. * * Revision 1.9 2005/02/22 23:27:39 kruland * Implement GetRasterColorTable/SetRasterColorTable. * * Revision 1.8 2005/02/20 19:42:53 kruland * Rename the Swig shadow classes so the names do not give the impression that * they are any part of the GDAL/OSR apis. There were no bugs with the old * names but they were confusing. * * Revision 1.7 2005/02/17 17:27:13 kruland * Changed the handling of fixed size double arrays to make it fit more * naturally with GDAL/OSR usage. Declare as typedef double * double_17; * If used as return argument use: function ( ... double_17 argout ... ); * If used as value argument use: function (... double_17 argin ... ); * * Revision 1.6 2005/02/17 04:12:09 kruland * Reimplement Band::ReadRaster Band::WriteRaster so they use optional int * argument. This allows keyword arguments in some languages. Added a * sanity check to WriteRaster to ensure the buffer string is long enough. * Fixed FlushCache by moving it into the class. * * Revision 1.5 2005/02/16 18:41:14 kruland * Implemented more methods. Commented the ones still missing. * * Revision 1.4 2005/02/15 19:50:39 kruland * Fixed ReadRaster/WriteRasters. They need to use buffers of char * with * explicit length because they can contain '\0'. * * Revision 1.3 2005/02/15 18:56:52 kruland * Added support for WriteRaster(). * * Revision 1.2 2005/02/15 16:56:46 kruland * Remove use of vector in ComputeRasterMinMax. Use double_2 instead. * * Revision 1.1 2005/02/15 06:23:48 kruland * Extracted Band class (GDALRasterBandShadow) into seperate .i file. Does not use * C++ API. * * */ /************************************************************************ * * Define the extensions for Band (nee GDALRasterBandShadow) * *************************************************************************/ %{ static CPLErr ReadRaster_internal( GDALRasterBandShadow *obj, int xoff, int yoff, int xsize, int ysize, int buf_xsize, int buf_ysize, GDALDataType buf_type, int *buf_size, char **buf ) { *buf_size = buf_xsize * buf_ysize * GDALGetDataTypeSize( buf_type ) / 8; *buf = (char*) malloc( *buf_size ); CPLErr result = GDALRasterIO( obj, GF_Read, xoff, yoff, xsize, ysize, (void *) *buf, buf_xsize, buf_ysize, buf_type, 0, 0 ); if ( result != CE_None ) { free( *buf ); *buf = 0; *buf_size = 0; } return result; } static CPLErr WriteRaster_internal( GDALRasterBandShadow *obj, int xoff, int yoff, int xsize, int ysize, int buf_xsize, int buf_ysize, GDALDataType buf_type, int buf_size, char *buffer ) { if ( buf_size < buf_xsize * buf_ysize * GDALGetDataTypeSize( buf_type) /8 ) { return CE_Failure; } return GDALRasterIO( obj, GF_Write, xoff, yoff, xsize, ysize, (void *) buffer, buf_xsize, buf_ysize, buf_type, 0, 0 ); } %} %rename (Band) GDALRasterBandShadow; class GDALRasterBandShadow { private: GDALRasterBandShadow(); ~GDALRasterBandShadow(); public: %extend { %immutable; int XSize; int YSize; GDALDataType DataType; %mutable; %apply (char **dict) { char ** }; char ** GetMetadata( const char * pszDomain = "" ) { return GDALGetMetadata( self, pszDomain ); } %clear char **; %apply (char **dict) { char ** papszMetadata }; CPLErr SetMetadata( char ** papszMetadata, const char * pszDomain = "" ) { return GDALSetMetadata( self, papszMetadata, pszDomain ); } %clear char **papszMetadata; GDALColorInterp GetRasterColorInterpretation() { return GDALGetRasterColorInterpretation( self ); } CPLErr SetRasterColorInterpretation( GDALColorInterp val ) { return GDALSetRasterColorInterpretation( self, val ); } double GetNoDataValue() { int noval; return GDALGetRasterNoDataValue( self, &noval ); } CPLErr SetNoDataValue( double d) { return GDALSetRasterNoDataValue( self, d ); } double GetMinimum() { int noval; return GDALGetRasterMinimum( self, &noval ); } double GetMaximum() { int noval; return GDALGetRasterMaximum( self, &noval ); } double GetOffset() { int noval; return GDALGetRasterOffset( self, &noval ); } double GetScale() { int noval; return GDALGetRasterScale( self, &noval ); } int GetOverviewCount() { return GDALGetOverviewCount( self ); } GDALRasterBandShadow *GetOverview(int i) { return (GDALRasterBandShadow*) GDALGetOverview( self, i ); } int Checksum( int xoff, int yoff, int xsize, int ysize) { return GDALChecksumImage( self, xoff, yoff, xsize, ysize ); } int Checksum( int xoff = 0, int yoff = 0 ) { int xsize = GDALGetRasterBandXSize( self ); int ysize = GDALGetRasterBandYSize( self ); return GDALChecksumImage( self, xoff, yoff, xsize, ysize ); } void ComputeRasterMinMax( double_2 argout, int approx_ok = 0) { GDALComputeRasterMinMax( self, approx_ok, argout ); } CPLErr Fill( double real_fill, double imag_fill =0.0 ) { return GDALFillRaster( self, real_fill, imag_fill ); } %apply ( int *nLen, char **pBuf ) { (int *buf_len, char **buf ) }; %apply ( int *optional_int ) {(int*)}; %feature( "kwargs" ) ReadRaster; CPLErr ReadRaster( int xoff, int yoff, int xsize, int ysize, int *buf_len, char **buf, int *buf_xsize = 0, int *buf_ysize = 0, int *buf_type = 0 ) { int nxsize = (buf_xsize==0) ? xsize : *buf_xsize; int nysize = (buf_ysize==0) ? ysize : *buf_ysize; GDALDataType ntype = (buf_type==0) ? GDALGetRasterDataType(self) : (GDALDataType)*buf_type; return ReadRaster_internal( self, xoff, yoff, xsize, ysize, nxsize, nysize, ntype, buf_len, buf ); } %clear (int *buf_len, char **buf ); %clear (int*); %apply (int nLen, char *pBuf) { (int buf_len, char *buf_string) }; %apply ( int *optional_int ) {(int*)}; %feature( "kwargs" ) WriteRaster; CPLErr WriteRaster( int xoff, int yoff, int xsize, int ysize, int buf_len, char *buf_string, int *buf_xsize = 0, int *buf_ysize = 0, int *buf_type = 0 ) { int nxsize = (buf_xsize==0) ? xsize : *buf_xsize; int nysize = (buf_ysize==0) ? ysize : *buf_ysize; GDALDataType ntype = (buf_type==0) ? GDALGetRasterDataType(self) : (GDALDataType)*buf_type; return WriteRaster_internal( self, xoff, yoff, xsize, ysize, nxsize, nysize, ntype, buf_len, buf_string ); } %clear (int buf_len, char *buf_string); %clear (int*); void FlushCache() { GDALFlushRasterCache( self ); } %newobject GetRasterColorTable; GDALColorTable *GetRasterColorTable() { return (GDALColorTable*) GDALGetRasterColorTable( self ); } int SetRasterColorTable( GDALColorTable *arg ) { return GDALSetRasterColorTable( self, arg ); } /* NEEDED */ /* ReadAsArray */ /* WriteArray */ /* GetHistogram */ /* ComputeBandStats */ /* AdviseRead */ } /* %extend */ }; %{ GDALDataType GDALRasterBandShadow_DataType_get( GDALRasterBandShadow *h ) { return GDALGetRasterDataType( h ); } int GDALRasterBandShadow_XSize_get( GDALRasterBandShadow *h ) { return GDALGetRasterBandXSize( h ); } int GDALRasterBandShadow_YSize_get( GDALRasterBandShadow *h ) { return GDALGetRasterBandYSize( h ); } %} #ifdef SWIGCSHARP %{ GDALDataType GDALRasterBandShadow_get_DataType( GDALRasterBandShadow *h ) { return GDALGetRasterDataType( h ); } int GDALRasterBandShadow_get_XSize( GDALRasterBandShadow *h ) { return GDALGetRasterBandXSize( h ); } int GDALRasterBandShadow_get_YSize( GDALRasterBandShadow *h ) { return GDALGetRasterBandYSize( h ); } %} #endif