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

Martin Dobias wonder.sk at gmail.com
Mon Nov 5 08:25:03 EST 2007


On 10/31/07, Christopher Barker <Chris.Barker at noaa.gov> wrote:
> 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?

Hi,
this is not the biggest problem and I think we could live with it.
But conceptually, why to connect GDAL and QGIS bindings? We want to
provide API that doesn't make differences between different data
providers: that's what is already done for vector data and what will
be done at some point for raster data. This is the reason why I think
that we should use our own data types, independent from underlying
libraries.


>  > 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.

I see problem in converting between C++ and Python types. If you
instantiate a GDAL object in Python, how QGIS will get the pointer to
the real C++ object? I don't know how to tell SIP to use a type from
other library which isn't wrapped by SIP.


> 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)

But the vision is that you will use only QGIS interface to do
anything, so the will be no need to do 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?

I'm not aware of any support of numpy by PyQt or QGIS...

Regards
Martin



More information about the gdal-dev mailing list