GDAL/OGR in Python
==================
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 (2.3.2 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`_ 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 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.7\bin
2. 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 earliest version of SWIG_
that is supported to generate the wrapper code is 1.3.40. It is possible
that usable bindings will build with a version earlier than 1.3.40, 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.7 bindings, you should update your imports to utilize
the usage above, but the following will work until at least GDAL 2.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/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.
.. _GDAL API Tutorial: http://www.gdal.org/gdal_tutorial.html
.. _GDAL Windows Binaries: http://gisinternals.com/sdk/
.. _Microsoft Knowledge Base doc: http://support.microsoft.com/kb/310519
.. _Python Cheeseshop: http://pypi.python.org/pypi/GDAL/
.. _val_repl.py: http://trac.osgeo.org/gdal/browser/trunk/gdal/swig/python/samples/val_repl.py
.. _GDAL: http://www.gdal.org
.. _SWIG: http://www.swig.org
没有合适的资源?快使用搜索试试~ 我知道了~
GDAL-2.3.2.tar.gz
1星 需积分: 9 11 下载量 156 浏览量
2019-10-18
17:16:59
上传
评论
收藏 544KB GZ 举报
温馨提示
共54个文件
py:40个
cpp:5个
txt:4个
GDAL(Geospatial Data Abstraction Library)是一个在X/MIT许可协议下的开源栅格空间数据转换库。它利用抽象数据模型来表达所支持的各种文件格式。它还有一系列命令行工具来进行数据转换和处理。
资源推荐
资源详情
资源评论
收起资源包目录
GDAL-2.3.2.tar.gz (54个子文件)
GDAL-2.3.2
setup.cfg 120B
GDAL.egg-info
dependency_links.txt 1B
not-zip-safe 1B
PKG-INFO 10KB
SOURCES.txt 1KB
top_level.txt 45B
gdalconst.py 143B
extensions
gnm_wrap.cpp 226KB
osr_wrap.cpp 628KB
gdalconst_wrap.c 176KB
ogr_wrap.cpp 1.26MB
gdal_array_wrap.cpp 191KB
gdal_wrap.cpp 1.15MB
gdalnumeric.py 147B
osgeo
gdalconst.py 15KB
gdal_array.py 18KB
gdalnumeric.py 51B
ogr.py 249KB
__init__.py 778B
gdal.py 139KB
gnm.py 11KB
osr.py 46KB
PKG-INFO 10KB
ogr.py 125B
scripts
gdal_proximity.py 7KB
gdal_auth.py 4KB
gdal2tiles.py 117KB
esri2wkt.py 2KB
epsg_tr.py 7KB
gdal_pansharpen.py 11KB
gdalimport.py 3KB
gdalident.py 3KB
gcps2wld.py 2KB
gdal_polygonize.py 8KB
pct2rgb.py 7KB
gdalmove.py 9KB
gdal_calc.py 19KB
gcps2vec.py 5KB
gdal2xyz.py 5KB
gdal_merge.py 19KB
rgb2pct.py 7KB
gdalchksum.py 3KB
gdal_fillnodata.py 6KB
gdal_sieve.py 7KB
gdalcompare.py 10KB
gdal_edit.py 11KB
gdal_retile.py 32KB
ogrmerge.py 22KB
mkgraticule.py 7KB
README.txt 8KB
gdal.py 128B
setup.py 15KB
gnm.py 11KB
osr.py 125B
共 54 条
- 1
资源评论
- xuehaiwuya20142022-10-25python的,不是源码
- 轩Boy~2021-06-04无用!骗币啊
灯会_hust
- 粉丝: 156
- 资源: 30
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功