[Gdal-dev] Re: Python Bindings - HELP!

Frank Warmerdam warmerdam at pobox.com
Fri Mar 7 17:29:14 EST 2003


Diana Esch-Mosher wrote:
> Frank,
> 
> I written some low level utility io routines for my application. To get
> to them from python I now have to hand generate the bindings and include
> into gvmodule.c? Yikes! I'm over my head. In python I have opened 2
> datasets with gdal.Open. I then want to call
> mymodule.myroutine(src_dataset,dst_dataset). Looking at something like
> the binding to gv_raster_rasterize_shapes leaves me in a panic! Can you
> give me some guidance?

Diana,

I have committed an "example" method in gvmodule.c for you.  Search in
their for MyGDALOperator.  It takes two GDALDatasetH's as input.

Feel free to change it as needed.  Note that you also have to change the
entry in the list at the end of the file.

In Python you could use something like this to access it:

         import _gv
         import gdal

         ds = gdal.Open( '/home/warmerda/openev/utm.tif' )
         x = _gv.MyGDALOperator( ds._o, ds._o )
         print x

Normally we wrap this with a Python function to make it nicer to use
from application code.

Note that there are two (three really) methods for wrapping C code for
OpenEV.

In OpenEV the wrappers for most GtkObject based stuff is auto-generated from
the gv.defs file.  In GDAL the SWIG package is used to generate most GDAL
wrappers automatically from the gdal.i.

The third method is "write it by hand" as is done in gvmodule.c for OpenEV
and sometimes in gdal.i for GDAL.

Note that your method in GDAL would be easier to wrap.  We could just add
a "int MyGDALOperation(GDALDatasetH,GDALDatasetH);" prototype to gdal.i
and the wrapper would be auto-generated.

I hope this gives you enough to go on to add your operator.

Best regards,

-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent





More information about the Gdal-dev mailing list