Changes between Initial Version and Version 1 of GdalOgrInPython

Apr 1, 2007 1:40:01 PM (13 years ago)



  • GdalOgrInPython

    v1 v1  
     1= GDAL/OGR In Python =
     3The GDAL project maintains SWIG generated Python bindings for GDAL and OGR.  Generally speaking the classes and methods mostly match those of the GDAL and OGR C++ classes.  There is no python specific reference documentation, but the [ GDAL API Tutorial] includes Python examples.
     5== New vs. Old Bindings ==
     7Python was the first set of bindings supported by GDAL/OGR and though the bindings were generated with SWIG, the process was very python specific.  In 2005 Kevin Ruland launched an effort for a set of ''Next Generation'' bindings generated with SWIG and supported by a variety of languages.  With GDAL 1.4.0 the various bindings are becoming fairly mature, and the ''next generation'' python bindings are becoming the preferred set in place of the old bindings.  However for python both are still available.
     9The ''old generation'' bindings live in the gdal/pymod directory, and are mixed up with various python utility scripts, and samples.  The ''new generation'' bindings live in the gdal/swig/python directory.  On unix to build with the old generation bindings you would configure --with-python --without-ngpython.  To build with the new generation bindings you would use --without-python --with-ngpython. 
     11The new python bindings are generally compatible with the old bindings though some quirks exist.  As time goes on the new bindings will continue to be extended as GDAL is extended, but the old generation bindings will not.  At this time the test suite should pass with either the old or new bindings.  Some applications, such as OpenEV 1.x still depend on the old Python bindings (which is why FWTools still ships with the old bindings).
     13== Numpy / Numeric ==
     15One advanced feature of the GDAL python bindings not found in the other bindings is integration with the Python numerical array facilities.  The gdal.Dataset.ReadAsArray() method can be used to read raster data as numerical arrays, ready to use with the Python numerical array capabilities. 
     17These facilities have evolved somewhat over time.  In the past the package was known as "Numeric" and imported using "import Numeric".  A new generation is imported using "import numpy".  Currently the old generation bindings only support the older Numeric package, and the new generatio bindings only support the new generation numpy package.  They are mostly compatible, and by importing gdalnumeric you will get whichever is appropriate to the current bindings type.
     19One example of GDAL/numpy integration is found in the sample [ pymod/samples/] script.
     21== Examples ==
     23 * [ pymod/samples] contains some example python scripts
     24 * [ pymod] also has a few interesting python utilities, but they are mixed with the old python bindings.
     25 * Much of the GDAL [ autotest] suite is written in python and can be browsed for examples