Skip to content

Commit

Permalink
SWIG: Exposes additional Dataset methods for the csharp wrapper (fixes
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
andreasbaa authored Mar 11, 2024
1 parent 629c1b0 commit 81083bd
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 20 deletions.
60 changes: 40 additions & 20 deletions swig/include/Dataset.i
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions swig/include/csharp/gdal_csharp.i
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 16 additions & 0 deletions swig/include/csharp/typemaps_csharp.i
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

0 comments on commit 81083bd

Please sign in to comment.