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 Even Rouault) 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 (3.6.4 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
Conda
GDAL can be quite complex to build and install, particularly on Windows and MacOS. Pre built binaries are provided for the conda system:
https://docs.conda.io/en/latest/
By the conda-forge project:
Once you have Anaconda or Miniconda installed, you should be able to install GDAL with:
conda install -c conda-forge gdal
Unix
The GDAL Python bindings requires setuptools.
pip
GDAL can be installed from the Python Package Index:
$ pip install GDAL
It will be necessary to have libgdal and its development headers installed if pip is expected to do a source build because no wheel is available for your specified platform and Python version.
To install the version of the Python bindings matching your native GDAL library:
$ pip install GDAL==”$(gdal-config –version).*”
Building as part of the GDAL library source tree
You can also have the GDAL Python bindings built as part of a source build:
$ cmake ..
Use the typical cmake build and install commands to complete the installation:
$ cmake --build . $ cmake --build . --target install
Windows
You will need the following items to complete an install of the GDAL Python bindings on Windows:
GDAL Windows Binaries Download the package that best matches your environment.
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 Knowledge Base doc
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.7\bin
Create a new user or system variable with the data folder from your installation.
Name : GDAL_DATA Path : C:\gdalwin32-1.7\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 currently supported version is SWIG 4.0.2. You should not have 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 cmake command:
$ cmake .. -DSWIG_REGENERATE_PYTHON=ON $ cmake --build .
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.7 bindings, you should update your imports to utilize the usage above, but the following will work until GDAL 3.1.
>>> 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.
Numpy
One advanced feature of the GDAL Python bindings not found in the other language 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.
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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file GDAL-3.6.4.tar.gz
.
File metadata
- Download URL: GDAL-3.6.4.tar.gz
- Upload date:
- Size: 758.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.8.1 requests/2.25.1 setuptools/60.0.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c07d548cbd6544e8a51651fc1e487ca4b39e8fe6b5b3c886082d87f0e49e8313 |
|
MD5 | ece7294f5d9730833b76394baf333232 |
|
BLAKE2b-256 | d845ce25a03268e6ccab9396acb92537b58eb5d0f4bdfa2144fd0f0e3bfdbacc |