[Gdal-dev] [Qgis-developer] GDAL Python Bindings

Christopher Barker Chris.Barker at noaa.gov
Wed Oct 31 12:27:26 EDT 2007


Hi folks,

Sorry for the cross-post, but it seemed topical to both qgis and gdal.

Martin Dobias wrote:
 >> GDAL already uses swig ngpython bindings, can't you reuse those ? There
 >> is a gdalconst.py generated by swig which contains the enums.

 > I don't think this would be a good idea. First, we would introduce
 > dependency on GDAL python bindings.

Well, there is a dependency on GDAL already, so why not the bindings?

I really think it is better for the GDAL user community as a whole to 
work to improve one set of bindings for GDAL, rather than have multiple 
sets.

 > Second, and more importantly,
 > there seems to be a technical barrier - I have no idea how to connect
 > SIP and SWIG bindings.

What are the barriers exactly? I now nothing of SIP, and a little about 
SWIG. However, I think the key is to use Python as the intermediary, and 
not try to have SIP types dealing directly with GDAL C stuff. To do this 
efficiently, there may be a need to add a thing or two to the GDAL SWIG 
bindings and the Qgis bindings.

In particular, thinking about a raster band, it could be a pretty good 
sized bock of data, so we'd want a way to get a GDAL raster band into 
whatever type you need for QGIS without a whole lot of data copying. By 
default, we might end up with:

gdal generates a raster band. (first copy)
it is converted to a Python string (two copies)
it is converted to a QGIS raster band equivelent (three copies)

It would be nice to just allocate the memory in GDAl, and pass that 
pointer through to whatever the QGIS type is. The way to do that is to 
use the Python buffer protocol, or even better the new nd-array protocol 
introduced by numpy, and slated for inclusion in future pythons:

http://numpy.scipy.org/array_interface.shtml

http://www.python.org/dev/peps/pep-3118/

I'm hoping to add this support to the GDAL bindings anyway, for 
efficient transfer to/from numpy arrays.

By the way, does pyQt and/or Qgis support numpy arrays at all now?

-Chris




-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov



More information about the Gdal-dev mailing list