GDAL


NameGDAL JSON
Version 3.10.0 PyPI version JSON
download
home_pagehttp://www.gdal.org
SummaryGDAL: Geospatial Data Abstraction Library
upload_time2024-11-06 15:20:32
maintainerGDAL contributors
docs_urlNone
authorFrank Warmerdam, Howard Butler, Even Rouault
requires_python>=3.8.0
licenseMIT
keywords gis raster vector
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            
GDAL/OGR in Python
==================

This Python package and extensions are a number of tools for programming and
manipulating the GDAL_ Geospatial Data Abstraction Library.
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 https://gdal.org/api/python_bindings.html#tutorials includes Python examples.

The GDAL Python package is built using `SWIG <https://www.swig.org>`__.
The GDAL project maintains these Python bindings for GDAL/OGR within
the gdal source tree.
The SWIG-generated files are not checked in and are not part of the
gdal release tarballs.  The bindings are also made available via PyPi
where the swig-generated files are provided.

Building from source
--------------------

To build from source, there are multiple possible paths.

Dependencies
~~~~~~~~~~~~

(As usual, when a package is listed one needs the parts used to build
programs against it, called -devel on many systems.  This is not
special about gdal.)

 * SWIG (4 or greater).

 * libgdal (3.10.0 or greater).

 * numpy (1.0.0 or greater).  This is not force-required by the build,
   but many examples and utilities will not work without it.  At least
   osgeo.gdal_array requires numpy at build time; building without
   numpy and installing it later does not result in correct operation.
   apparently not and in any case it is an unwarranted leap.

 * setuptools (python)

 * wheel (python)

Building when building the rest of GDAL
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Python bindings are generated by default when building GDAL from source.
For more detail, see `Python bindings options <https://gdal.org/development/building_from_source.html#building-python-bindings>`__

Building just the bindings, from the full tree
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Another is to use the gdal source distribution with an
already-installed gdal library and headers.  To do this, one must
create a build directory and run cmake to generate build scripts.  Then,
run ``cmake --build . --target python_generated_files``. Finally, in swig/python,
one can build using setup.py like any other distributed python module.

Building from the PyPi module file
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The third is to obtain the PyPi-hosted module file, within which swig
has been run; this saves running cmake and generating bindings.   See
HOWTO-RELEASE for how this is created.  Because swig has been run, it
need not be installed.


Installation via packging systems
---------------------------------

General
~~~~~~~

Many packaging systems (on GNU/Linux, various BSDs) provide the
bindings as a package.  Specific instruction are given in cases when
that hint might not be sufficient.

pip
~~~

Due to the complex nature of GDAL and its components, different bindings may require additional packages and installation steps.
GDAL can be installed from the `Python Package Index <https://pypi.org/project/GDAL>`__:

::

    pip install gdal


In order to enable numpy-based raster support, libgdal and its development headers must be installed as well as the Python packages numpy, setuptools, and wheel.
To install the Python dependencies and build numpy-based raster support:


::

    pip install numpy>1.0.0 wheel setuptools>=67
    pip install gdal[numpy]=="$(gdal-config --version).*"


Users can verify that numpy-based raster support has been installed with:

::

    python3 -c 'from osgeo import gdal_array'


If this command raises an ImportError, numpy-based raster support has not been properly installed:

::

    Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/usr/local/lib/python3.12/dist-packages/osgeo/gdal_array.py", line 10, in <module>
      from . import _gdal_array
    ImportError: cannot import name '_gdal_array' from 'osgeo' (/usr/local/lib/python3.12/dist-packages/osgeo/__init__.py)


This is most often due to pip reusing a cached GDAL installation.
Verify that the necessary dependencies have been installed and then run the following to force a clean build:

::

    pip install --no-cache --force-reinstall gdal[numpy]=="$(gdal-config --version).*"


Potential issues with GDAL >= 3.9, Python >= 3.9 and NumPy 2.0 (pip)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The pyproject.toml file of GDAL 3.9 requires numpy >= 2.0.0rc1 (for Python >= 3.9)
at build time to be able to build bindings that are compatible of both NumPy 1
and NumPy 2.
If for some reason the numpy >= 2.0.0rc1 build dependency can not be installed,
it is possible to manually install the build requirements, and invoke ``pip install``
with the ``--no-build-isolation`` flag.

::

    pip install numpy==<required_version> wheel setuptools>=67
    pip install gdal[numpy]=="$(gdal-config --version).*" --no-build-isolation


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:

https://conda-forge.org/

Once you have Anaconda or Miniconda installed, you should be able to install GDAL with:

``conda install -c conda-forge gdal``



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

API
~~~

API documentation is available at https://gdal.org/api/python/osgeo.html

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.

Tutorials
---------

See https://gdal.org/api/python_bindings.html#tutorials

Gotchas
-------

Although GDAL's and OGR's Python bindings provide a fairly "Pythonic" wrapper around the underlying C++ code, there are several ways in which the Python bindings differ from typical Python libraries.
These differences can catch Python programmers by surprise and lead to unexpected results. These differences result from the complexity of developing a large, long-lived library while continuing to maintain
backward compatibility. They are being addressed over time, but until they are all gone, please review this list of https://gdal.org/api/python_gotchas.html

Examples
--------

* An assortment of other samples are available in the `Python github samples directory <https://github.com/OSGeo/gdal/tree/master/swig/python/gdal-utils/osgeo_utils/samples>`__
  with some description in the https://gdal.org/api/python_bindings.html#examples.
* Several `GDAL utilities <https://github.com/OSGeo/gdal/tree/master/swig/python/gdal-utils/osgeo_utils/>`__
  are implemented in Python and can be useful examples.
* The majority of GDAL regression tests are written in Python. They are available at
  `https://github.com/OSGeo/gdal/tree/master/autotest <https://github.com/OSGeo/gdal/tree/master/autotest>`__

One example of GDAL/numpy integration is found in the `val_repl.py <https://github.com/OSGeo/gdal/tree/master/swig/python/gdal-utils/osgeo_utils/samples/val_repl.py>`__ script.

.. note::
   **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.


.. _GDAL: https://gdal.org

            

Raw data

            {
    "_id": null,
    "home_page": "http://www.gdal.org",
    "name": "GDAL",
    "maintainer": "GDAL contributors",
    "docs_url": null,
    "requires_python": ">=3.8.0",
    "maintainer_email": "GDAL contributors <gdal-dev@lists.osgeo.org>",
    "keywords": "gis, raster, vector",
    "author": "Frank Warmerdam, Howard Butler, Even Rouault",
    "author_email": "warmerdam@pobox.com",
    "download_url": "https://files.pythonhosted.org/packages/7d/86/1c4b3eb5b3d31584ebc694cd54b04e8cdba0d71018bbe65d4faefa489a9f/gdal-3.10.tar.gz",
    "platform": null,
    "description": "\nGDAL/OGR in Python\n==================\n\nThis Python package and extensions are a number of tools for programming and\nmanipulating the GDAL_ Geospatial Data Abstraction Library.\nGenerally speaking the classes and methods mostly\nmatch those of the GDAL and OGR C++ classes. There is no Python specific\nreference documentation, but the https://gdal.org/api/python_bindings.html#tutorials includes Python examples.\n\nThe GDAL Python package is built using `SWIG <https://www.swig.org>`__.\nThe GDAL project maintains these Python bindings for GDAL/OGR within\nthe gdal source tree.\nThe SWIG-generated files are not checked in and are not part of the\ngdal release tarballs.  The bindings are also made available via PyPi\nwhere the swig-generated files are provided.\n\nBuilding from source\n--------------------\n\nTo build from source, there are multiple possible paths.\n\nDependencies\n~~~~~~~~~~~~\n\n(As usual, when a package is listed one needs the parts used to build\nprograms against it, called -devel on many systems.  This is not\nspecial about gdal.)\n\n * SWIG (4 or greater).\n\n * libgdal (3.10.0 or greater).\n\n * numpy (1.0.0 or greater).  This is not force-required by the build,\n   but many examples and utilities will not work without it.  At least\n   osgeo.gdal_array requires numpy at build time; building without\n   numpy and installing it later does not result in correct operation.\n   apparently not and in any case it is an unwarranted leap.\n\n * setuptools (python)\n\n * wheel (python)\n\nBuilding when building the rest of GDAL\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nPython bindings are generated by default when building GDAL from source.\nFor more detail, see `Python bindings options <https://gdal.org/development/building_from_source.html#building-python-bindings>`__\n\nBuilding just the bindings, from the full tree\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nAnother is to use the gdal source distribution with an\nalready-installed gdal library and headers.  To do this, one must\ncreate a build directory and run cmake to generate build scripts.  Then,\nrun ``cmake --build . --target python_generated_files``. Finally, in swig/python,\none can build using setup.py like any other distributed python module.\n\nBuilding from the PyPi module file\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe third is to obtain the PyPi-hosted module file, within which swig\nhas been run; this saves running cmake and generating bindings.   See\nHOWTO-RELEASE for how this is created.  Because swig has been run, it\nneed not be installed.\n\n\nInstallation via packging systems\n---------------------------------\n\nGeneral\n~~~~~~~\n\nMany packaging systems (on GNU/Linux, various BSDs) provide the\nbindings as a package.  Specific instruction are given in cases when\nthat hint might not be sufficient.\n\npip\n~~~\n\nDue to the complex nature of GDAL and its components, different bindings may require additional packages and installation steps.\nGDAL can be installed from the `Python Package Index <https://pypi.org/project/GDAL>`__:\n\n::\n\n    pip install gdal\n\n\nIn order to enable numpy-based raster support, libgdal and its development headers must be installed as well as the Python packages numpy, setuptools, and wheel.\nTo install the Python dependencies and build numpy-based raster support:\n\n\n::\n\n    pip install numpy>1.0.0 wheel setuptools>=67\n    pip install gdal[numpy]==\"$(gdal-config --version).*\"\n\n\nUsers can verify that numpy-based raster support has been installed with:\n\n::\n\n    python3 -c 'from osgeo import gdal_array'\n\n\nIf this command raises an ImportError, numpy-based raster support has not been properly installed:\n\n::\n\n    Traceback (most recent call last):\n    File \"<string>\", line 1, in <module>\n    File \"/usr/local/lib/python3.12/dist-packages/osgeo/gdal_array.py\", line 10, in <module>\n      from . import _gdal_array\n    ImportError: cannot import name '_gdal_array' from 'osgeo' (/usr/local/lib/python3.12/dist-packages/osgeo/__init__.py)\n\n\nThis is most often due to pip reusing a cached GDAL installation.\nVerify that the necessary dependencies have been installed and then run the following to force a clean build:\n\n::\n\n    pip install --no-cache --force-reinstall gdal[numpy]==\"$(gdal-config --version).*\"\n\n\nPotential issues with GDAL >= 3.9, Python >= 3.9 and NumPy 2.0 (pip)\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe pyproject.toml file of GDAL 3.9 requires numpy >= 2.0.0rc1 (for Python >= 3.9)\nat build time to be able to build bindings that are compatible of both NumPy 1\nand NumPy 2.\nIf for some reason the numpy >= 2.0.0rc1 build dependency can not be installed,\nit is possible to manually install the build requirements, and invoke ``pip install``\nwith the ``--no-build-isolation`` flag.\n\n::\n\n    pip install numpy==<required_version> wheel setuptools>=67\n    pip install gdal[numpy]==\"$(gdal-config --version).*\" --no-build-isolation\n\n\nConda\n~~~~~\n\nGDAL can be quite complex to build and install, particularly on Windows and MacOS.\nPre built binaries are provided for the conda system:\n\nhttps://docs.conda.io/en/latest/\n\nBy the conda-forge project:\n\nhttps://conda-forge.org/\n\nOnce you have Anaconda or Miniconda installed, you should be able to install GDAL with:\n\n``conda install -c conda-forge gdal``\n\n\n\nUsage\n-----\n\nImports\n~~~~~~~\n\nThere are five major modules that are included with the GDAL_ Python bindings.::\n\n  >>> from osgeo import gdal\n  >>> from osgeo import ogr\n  >>> from osgeo import osr\n  >>> from osgeo import gdal_array\n  >>> from osgeo import gdalconst\n\nAPI\n~~~\n\nAPI documentation is available at https://gdal.org/api/python/osgeo.html\n\nNumpy\n-----\n\nOne advanced feature of the GDAL Python bindings not found in the other\nlanguage bindings is integration with the Python numerical array\nfacilities. The gdal.Dataset.ReadAsArray() method can be used to read raster\ndata as numerical arrays, ready to use with the Python numerical array\ncapabilities.\n\nTutorials\n---------\n\nSee https://gdal.org/api/python_bindings.html#tutorials\n\nGotchas\n-------\n\nAlthough GDAL's and OGR's Python bindings provide a fairly \"Pythonic\" wrapper around the underlying C++ code, there are several ways in which the Python bindings differ from typical Python libraries.\nThese differences can catch Python programmers by surprise and lead to unexpected results. These differences result from the complexity of developing a large, long-lived library while continuing to maintain\nbackward compatibility. They are being addressed over time, but until they are all gone, please review this list of https://gdal.org/api/python_gotchas.html\n\nExamples\n--------\n\n* An assortment of other samples are available in the `Python github samples directory <https://github.com/OSGeo/gdal/tree/master/swig/python/gdal-utils/osgeo_utils/samples>`__\n  with some description in the https://gdal.org/api/python_bindings.html#examples.\n* Several `GDAL utilities <https://github.com/OSGeo/gdal/tree/master/swig/python/gdal-utils/osgeo_utils/>`__\n  are implemented in Python and can be useful examples.\n* The majority of GDAL regression tests are written in Python. They are available at\n  `https://github.com/OSGeo/gdal/tree/master/autotest <https://github.com/OSGeo/gdal/tree/master/autotest>`__\n\nOne example of GDAL/numpy integration is found in the `val_repl.py <https://github.com/OSGeo/gdal/tree/master/swig/python/gdal-utils/osgeo_utils/samples/val_repl.py>`__ script.\n\n.. note::\n   **Performance Notes**\n\n   ReadAsArray expects to make an entire copy of a raster band or dataset\n   unless the data are explicitly subsetted as part of the function call. For\n   large data, this approach is expected to be prohibitively memory intensive.\n\n\n.. _GDAL: https://gdal.org\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "GDAL: Geospatial Data Abstraction Library",
    "version": "3.10.0",
    "project_urls": {
        "Changelog": "https://github.com/OSGeo/gdal/blob/master/NEWS.md",
        "Documentation": "https://gdal.org",
        "Homepage": "https://gdal.org",
        "Issues": "https://github.com/OSGeo/gdal/issues",
        "Repository": "https://github.com/OSGeo/GDAL.git"
    },
    "split_keywords": [
        "gis",
        " raster",
        " vector"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7d861c4b3eb5b3d31584ebc694cd54b04e8cdba0d71018bbe65d4faefa489a9f",
                "md5": "d487ae53b8d9fa6ca8203f6dd6591f89",
                "sha256": "98fed53baca2b6ec35daa56773facf425a64cd9d1293eb8be28ef9458ea24820"
            },
            "downloads": -1,
            "filename": "gdal-3.10.tar.gz",
            "has_sig": false,
            "md5_digest": "d487ae53b8d9fa6ca8203f6dd6591f89",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.0",
            "size": 848086,
            "upload_time": "2024-11-06T15:20:32",
            "upload_time_iso_8601": "2024-11-06T15:20:32.923927Z",
            "url": "https://files.pythonhosted.org/packages/7d/86/1c4b3eb5b3d31584ebc694cd54b04e8cdba0d71018bbe65d4faefa489a9f/gdal-3.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-06 15:20:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "OSGeo",
    "github_project": "gdal",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "lcname": "gdal"
}
        
Elapsed time: 0.34645s