Skip to main content

GDAL: Geospatial Data Abstraction Library

Project description

This Python package and extensions are a number of tools for programming and manipulating the GDAL Geospatial Data Abstraction Library. Actually, it is two libraries – GDAL for manipulating geospatial raster data and OGR for manipulating geospatial vector data – but we’ll refer to the entire package as the GDAL library for the purposes of this document.

The GDAL project (primarily Howard Butler) 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.

Dependencies

  • libgdal (1.6.0 or greater) and header files (gdal-devel)

  • numpy (1.0.0 or greater) and header files (numpy-devel) (not explicitly required, but many examples and utilities will not work without it)

Installation

Unix

The GDAL Python bindings support both distutils and setuptools, with a preference for using setuptools. If setuptools can be imported, setup will use that to build an egg by default. If setuptools cannot be imported, a simple distutils root install of the GDAL package (and no dependency chaining for numpy) will be made.

easy_install

GDAL can be installed from the Python CheeseShop:

$ sudo easy_install GDAL

It may be necessary to have libgdal and its development headers installed if easy_install is expected to do a source build because no egg is available for your specified platform and Python version.

setup.py

Most of setup.py’s important variables are controlled with the setup.cfg file. In setup.cfg, you can modify pointers to include files and libraries. The most important option that will likely need to be modified is the gdal_config parameter. If you installed GDAL from a package, the location of this program is likely /usr/bin/gdal-config, but it may be in another place depending on how your packager arranged things.

After modifying the location of gdal-config, you can build and install with the setup script:

$ python setup.py build
$ python setup.py install

If you have setuptools installed, you can also generate an egg:

$ python setup.py bdist_egg

Building as part of the GDAL library source tree

You can also have the GDAL Python bindings built as part of a source build by specifying –with-python as part of your configure line:

$ ./configure --with-python

Use the typical make and make install commands to complete the installation:

$ make
$ make install

A note about setuptools

./configure attempts to detect if you have setuptools installed in the tree of the Python binary it was given (or detected on the execution path), and it will use an egg build by default in that instance. If you have a need to use a distutils-only install, you will have to edit setup.py to ensure that the HAVE_SETUPTOOLS variable is ultimately set to False and proceed with a typical ‘python setup.py install’ command.

Windows

You will need the following items to complete an install of the GDAL Python bindings on Windows:

  • GDAL Windows Binaries The basic install requires the gdalwin32exe###.zip (### is the version number). Other files you see in the directory are for various optional plugins and development headers/include files. After downloading the zip file, extract it to the directory of your choosing.

  • GDAL Python Bindings available at the Python Cheeseshop. An executable installer is available for both Python 2.4 or 2.5 or as a Python egg.

As explained in the README_EXE.txt file, after unzipping the GDAL binaries you will need to modify your system path and variables. If you’re not sure how to do this, read the Microsoft KnowledgeBase doc

  1. Add the installation directory bin folder to your system PATH, remember to put a semicolon in front of it before you add to the existing path.

    C:\gdalwin32-1.6\bin
  2. Create a new user or system variable with the data folder from your installation.

    Name : GDAL_DATA
    Path : C:\gdalwin32-1.6\data

Skip down to the Usage section to test your install. Note, a reboot may be required.

SWIG

The GDAL Python package is built using SWIG. The earliest version of SWIG that is supported to generate the wrapper code is 1.3.31. It is possible that usable bindings will build with a version earlier than 1.3.31, but no development efforts are targeted at versions below it. You should not have to run SWIG in your development tree to generate the binding code, as it is usually included with the source. However, if you do need to regenerate, you can do so with the following make command from within the ./swig/python directory:

$ make generate

To ensure that all of the bindings are regenerated, you can clean the bindings code out before the generate command by issuing:

$ make veryclean

Usage

Imports

There are five major modules that are included with the GDAL Python bindings.:

>>> from osgeo import gdal
>>> from osgeo import ogr
>>> from osgeo import osr
>>> from osgeo import gdal_array
>>> from osgeo import gdalconst

Additionally, there are five compatibility modules that are included but provide notices to state that they are deprecated and will be going away. If you are using GDAL 1.6 bindings, you should update your imports to utilize the usage above, but the following will work until at least GDAL 2.0.

>>> import gdal
>>> import ogr
>>> import osr
>>> import gdalnumeric
>>> import gdalconst

If you have previous code that imported the global module and still need to support the old import, a simple try…except import can silence the deprecation warning and keep things named essentially the same as before:

>>> try:
...     from osgeo import gdal
... except ImportError:
...     import gdal

Docstrings

Currently, only the OGR module has docstrings which are generated from the C/C++ API doxygen materials. Some of the arguments and types might not match up exactly with what you are seeing from Python, but they should be enough to get you going. Docstrings for GDAL and OSR are planned for a future release.

The History of Using GDAL/OGR in Python

Python was the first set of bindings supported by GDAL/OGR and though the bindings were generated with SWIG (1.1 series), the process was very Python specific and contained a significant amount of hand written wrapper code. In 2005, Kevin Ruland launched an effort for a set of next generation bindings generated with SWIG (1.3 series) and supported by a variety of languages. With GDAL 1.4.0 the various bindings became fairly mature, and for GDAL 1.6.0, the “next-generation” bindings become the default bindings. The previous, “old-generation,” bindings will continue to be available, but they will not be widely supported and no new development will be targeted at them. From the viewpoint of a user, with GDAL 1.6.0 and above, you should not have to worry very much about the distinction between these two development efforts.

Usage of Old-Generation Python Bindings

For certain legacy applications (most notably OpenEV 1.x), it may be necessary to continue to use the old-generation Python bindings. These can be built and installed as part of a source build from ./configure:

$ ./configure --with-ogpython=/usr/bin/python

As noted earlier, these bindings are not widely supported and no new development is expected to take place with them (including serious bug fixes).

Numpy/Numeric

One advanced feature of the GDAL Python bindings not found in the other language bindings (C#, Perl) 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.

These 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 generation bindings only support the new generation numpy package. They are mostly compatible, and by importing gdalnumeric (or osgeo.gdal_array) you will get whichever is appropriate to the current bindings type.

Examples

One example of GDAL/numpy integration is found in the val_repl.py script.

Performance Notes

ReadAsArray expects to make an entire copy of a raster band or dataset unless the data are explicitly subsetted as part of the function call. For large data, this approach is expected to be prohibitively memory intensive.

Project details


Release history Release notifications | RSS feed

This version

1.6.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

GDAL-1.6.1.tar.gz (284.3 kB view details)

Uploaded Source

Built Distributions

GDAL-1.6.1.win32-py2.6.exe (289.9 kB view details)

Uploaded Source

GDAL-1.6.1.win32-py2.5.exe (274.6 kB view details)

Uploaded Source

GDAL-1.6.1.win32-py2.4.exe (274.6 kB view details)

Uploaded Source

GDAL-1.6.1-py2.6-win32.egg (267.6 kB view details)

Uploaded Source

GDAL-1.6.1-py2.5-win32.egg (257.0 kB view details)

Uploaded Source

GDAL-1.6.1-py2.4-win32.egg (258.1 kB view details)

Uploaded Source

File details

Details for the file GDAL-1.6.1.tar.gz.

File metadata

  • Download URL: GDAL-1.6.1.tar.gz
  • Upload date:
  • Size: 284.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for GDAL-1.6.1.tar.gz
Algorithm Hash digest
SHA256 fdc7c2d83140c5a507d039fad0f5917b8219d4153fb038286e1e4be967ba7a9c
MD5 e8671d4a77041cf0f7a027f3f3e8280c
BLAKE2b-256 8116233ee7862013319c16dd282f0f443abf51593e6c3860187fb3d3cd8e3a18

See more details on using hashes here.

File details

Details for the file GDAL-1.6.1.win32-py2.6.exe.

File metadata

File hashes

Hashes for GDAL-1.6.1.win32-py2.6.exe
Algorithm Hash digest
SHA256 5714a09cbf80e99b510f2d2d401f3f762ce2b9e326a139b761be66838014b3e6
MD5 5e48c85a9ace1baad77dc26bb42ab4e1
BLAKE2b-256 3e649aea9ab17b29beea72d12cef586c709ed64d4873c06cfc5ac24c941d9707

See more details on using hashes here.

File details

Details for the file GDAL-1.6.1.win32-py2.5.exe.

File metadata

File hashes

Hashes for GDAL-1.6.1.win32-py2.5.exe
Algorithm Hash digest
SHA256 fe1cea9eddfed1867483d3aae864b9a98e5e16aac4b3e79f36e4b1c1b0843874
MD5 089ee8b47937f9abb104bbdc789925ff
BLAKE2b-256 cb3a056d4f86b8e402d1d3bbf92e8af29a3ad846a488fcf7ca89bb42c48fe5ed

See more details on using hashes here.

File details

Details for the file GDAL-1.6.1.win32-py2.4.exe.

File metadata

File hashes

Hashes for GDAL-1.6.1.win32-py2.4.exe
Algorithm Hash digest
SHA256 c6d3f988bb481cc7313cb2a4ae72a1c90d30f3e2952fac299e6466f16a64873a
MD5 d48d82cbc1fd5061e1ad49d1845b3418
BLAKE2b-256 9ecf7bae2b43381303037dd383daeda8db8b92183f164bed2a7d6b74f922f8f6

See more details on using hashes here.

File details

Details for the file GDAL-1.6.1-py2.6-win32.egg.

File metadata

File hashes

Hashes for GDAL-1.6.1-py2.6-win32.egg
Algorithm Hash digest
SHA256 f1704cbb6a3a0cd57e1d8e6b1287f04d06296d0dd8f4ffd2c1ef5c16b32dfa44
MD5 0d187c3a78279a79a12085ac6ed78711
BLAKE2b-256 3042edc77457b4a2f2027a9b60e08cb3c0708280032d01941149e7e7d0d592c9

See more details on using hashes here.

File details

Details for the file GDAL-1.6.1-py2.5-win32.egg.

File metadata

File hashes

Hashes for GDAL-1.6.1-py2.5-win32.egg
Algorithm Hash digest
SHA256 7f2151cc825cc868d0f70f37be50730267ad0f29f7afb69dc6729cc88b26eff9
MD5 3aaff6dde620794dafc38e140e54d6aa
BLAKE2b-256 3048c239130bcf4eab3a858cf2347f477a54c9d669729a34091f68a756e40f66

See more details on using hashes here.

File details

Details for the file GDAL-1.6.1-py2.4-win32.egg.

File metadata

File hashes

Hashes for GDAL-1.6.1-py2.4-win32.egg
Algorithm Hash digest
SHA256 cd03c02b8f5f8fc824097f3db9594fe10665d728645db138ee2d0d6ea434117d
MD5 e6d97e4571d11a996193714236d28506
BLAKE2b-256 5065c90fcf4b9cd0091745b5bbc500d3200282bd74ddd9aedddcf1f0d15c8239

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page