From 81083bd0b31bdd8900a5baf63f8c35b0b6645664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Bergstr=C3=B8m=20Aarnseth?= Date: Tue, 12 Mar 2024 00:24:57 +0100 Subject: [PATCH] SWIG: Exposes additional Dataset methods for the csharp wrapper (fixes #918) (#9398) SWIG: Exposes additional Dataset methods for the csharp wrapper: - GetNextFeature (exposing _ppoBelongingLayer_ as a ref IntPtr and _pdfProgressPct_ as ref double), - GetLayerCount, - GetLayer, - GetLayerByName, - ResetReading --- swig/include/Dataset.i | 60 ++++++++++++++++++--------- swig/include/csharp/gdal_csharp.i | 2 + swig/include/csharp/typemaps_csharp.i | 16 +++++++ 3 files changed, 58 insertions(+), 20 deletions(-) diff --git a/swig/include/Dataset.i b/swig/include/Dataset.i index fe4945f95f66..f7ddfbbdabbb 100644 --- a/swig/include/Dataset.i +++ b/swig/include/Dataset.i @@ -805,32 +805,12 @@ CPLErr AdviseRead( int xoff, int yoff, int xsize, int ysize, return GDALDatasetDeleteLayer(self, index); } - int GetLayerCount() { - return GDALDatasetGetLayerCount(self); - } - bool IsLayerPrivate( int index ) { return GDALDatasetIsLayerPrivate(self, index); } -#ifdef SWIGJAVA - OGRLayerShadow *GetLayerByIndex( int index ) { -#else - OGRLayerShadow *GetLayerByIndex( int index=0) { -#endif - OGRLayerShadow* layer = (OGRLayerShadow*) GDALDatasetGetLayer(self, index); - return layer; - } - OGRLayerShadow *GetLayerByName( const char* layer_name) { - OGRLayerShadow* layer = (OGRLayerShadow*) GDALDatasetGetLayerByName(self, layer_name); - return layer; - } - void ResetReading() - { - GDALDatasetResetReading( self ); - } #ifdef SWIGPYTHON %newobject GetNextFeature; @@ -890,6 +870,46 @@ CPLErr AdviseRead( int xoff, int yoff, int xsize, int ysize, #endif /* defined(SWIGPYTHON) || defined(SWIGJAVA) */ +#ifdef SWIGJAVA + OGRLayerShadow *GetLayerByIndex( int index ) { +#elif SWIGPYTHON + OGRLayerShadow *GetLayerByIndex( int index=0) { +#else + OGRLayerShadow *GetLayer( int index ) { +#endif + OGRLayerShadow* layer = (OGRLayerShadow*) GDALDatasetGetLayer(self, index); + return layer; + } + + OGRLayerShadow *GetLayerByName(const char* layer_name) { + OGRLayerShadow* layer = (OGRLayerShadow*) GDALDatasetGetLayerByName(self, layer_name); + return layer; + } + + void ResetReading() + { + GDALDatasetResetReading(self); + } + + int GetLayerCount() { + return GDALDatasetGetLayerCount(self); + } + +#ifdef SWIGCSHARP + + %newobject GetNextFeature; + OGRFeatureShadow *GetNextFeature( OGRLayerShadow** ppoBelongingLayer = NULL, + double* pdfProgressPct = NULL, + GDALProgressFunc callback = NULL, + void* callback_data=NULL ) + { + return GDALDatasetGetNextFeature( self, ppoBelongingLayer, pdfProgressPct, + callback, callback_data ); + } + + +#endif + OGRErr AbortSQL() { return GDALDatasetAbortSQL(self); } diff --git a/swig/include/csharp/gdal_csharp.i b/swig/include/csharp/gdal_csharp.i index 23b5abe76a98..39a4e0587662 100644 --- a/swig/include/csharp/gdal_csharp.i +++ b/swig/include/csharp/gdal_csharp.i @@ -86,6 +86,8 @@ typedef struct } GDALRasterIOExtraArg; DEFINE_EXTERNAL_CLASS(OGRLayerShadow, OSGeo.OGR.Layer) +DEFINE_EXTERNAL_CLASS(OGRFeatureShadow, OSGeo.OGR.Feature) + %define %rasterio_functions(GDALTYPE,CSTYPE) public CPLErr ReadRaster(int xOff, int yOff, int xSize, int ySize, CSTYPE[] buffer, int buf_xSize, int buf_ySize, int pixelSpace, int lineSpace) { diff --git a/swig/include/csharp/typemaps_csharp.i b/swig/include/csharp/typemaps_csharp.i index ef706e6de018..509db618aee4 100644 --- a/swig/include/csharp/typemaps_csharp.i +++ b/swig/include/csharp/typemaps_csharp.i @@ -599,3 +599,19 @@ OPTIONAL_POD(int, int); %typemap(imtype) (void* callback_data) "string" %typemap(cstype) (void* callback_data) "string" %typemap(csin) (void* callback_data) "$csinput" + + +/****************************************************************************** + * GDALGetNextFeature typemaps * + *****************************************************************************/ + +%apply (double *defaultval) {double* pdfProgressPct}; + +%typemap(imtype) (OGRLayerShadow **ppoBelongingLayer) "ref IntPtr" +%typemap(cstype) (OGRLayerShadow **ppoBelongingLayer) "ref IntPtr" +%typemap(csin) (OGRLayerShadow **ppoBelongingLayer) "ref $csinput" + +/****************************************************************************** + * GDALGetLayerByName typemaps * + *****************************************************************************/ +%apply ( const char *utf8_path ) { const char* layer_name };