[gdal-dev] Can c++ types be used directly from the SWIG interfaces?

Michael mbucari1 at gmail.com
Mon Aug 31 12:50:03 PDT 2026


I want to expose the GDALGeoTransform class. It doesn't have a C struct
representation (like OGREnvelope) or an opaque C handle type. I could add C
interfaces to  GDALGeoTransfor, but that seems absurd since
GDALGeoTransfor is mostly a C++ wrapper of the C routines.

However, using the GDALGeoTransfor class directly from the SWIG interfaces
works surprisingly well (See below). What doesn't work is the 'Apply'
overloads which accept a `GDALRasterWindow` type, because SWIG can't
include gdal_rasterband.h while CPL_SUPRESS_CPLUSPLUS is defined.

So my questions are: can I use the GDALGeoTransfor c++ class directly
from SWIG and, if not, why?
-------------

%{
#include "gdal_geotransform.h"
%}

class GDALGeoTransform {
private:
  const double *data() const;
  ~GDALGeoTransform();
public:
%mutable;
  GDALGeoTransform();
  GDALGeoTransform(const double coeffs[6]);
  GDALGeoTransform(double xorigIn, double xscaleIn, double xrotIn, double
yorigIn, double yrotIn, double yscaleIn);
  void Rescale(double dfXRatio, double dfYRatio);
%immutable;
  void Apply(double dfPixel, double dfLine, double *pdfGeoX, double
*pdfGeoY) const;
  bool GetInverse(GDALGeoTransform &inverse) const;
  bool IsAxisAligned() const;
};

-- 
Michael Bucari
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20260831/471c6d26/attachment.htm>


More information about the gdal-dev mailing list