Thank you both Sean and Even.
SWIG is too complicated for me, and I will find a work around. Shawn ________________________________ From: Even Rouault [[email protected]] Sent: November-27-17 2:10 PM To: [email protected] Cc: Sean Gillies; Shawn Gong Subject: Re: [gdal-dev] pass gdal dataset as an argument from Python to C On lundi 27 novembre 2017 11:46:50 CET Sean Gillies wrote: > I believe it's possible, yes, but it will be challenging. I'm not aware of > anybody else doing this. > > In > https://github.com/OSGeo/gdal/blob/trunk/gdal/swig/python/extensions/gdal_wr > ap.cpp you can see examples of C++ functions that access the GDAL objects > referenced by Python objects. This isn't a stable public API by any means, > and therefore I hesitate to recommend it. Maybe Even would be able to > comment more on how much support there is for the SWIG-generated C++ Python > classes. > Yes should be doable by "importing" some SWIG_ methods from gdal_wrap.cpp. This might be fragile in case the SWIG_ wrapping structures evolve. Interesting bits: SWIGINTERN PyObject *_wrap_Dataset_RasterXSize_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; int bLocalUseExceptionsCode = bUseExceptions; GDALDatasetShadow *arg1 = (GDALDatasetShadow *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; int result; if (!PyArg_ParseTuple(args,(char *)"O:Dataset_RasterXSize_get",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_GDALDatasetShadow, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Dataset_RasterXSize_get" "', argument " "1"" of type '" "GDALDatasetShadow *""'"); } arg1 = reinterpret_cast< GDALDatasetShadow * >(argp1); .... } (GDALDatasetShadow* is an alias of GDALDataset*) static PyMethodDef SwigMethods[] = { { (char *)"Dataset_RasterXSize_get", _wrap_Dataset_RasterXSize_get, METH_VARARGS, (char *)"Dataset_RasterXSize_get(Dataset self) -> int"}, } -- Spatialys - Geospatial professional services http://www.spatialys.com
_______________________________________________ gdal-dev mailing list [email protected] https://lists.osgeo.org/mailman/listinfo/gdal-dev
