geolibs.txt 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. .. _geospatial_libs:
  2. ===============================
  3. Installing Geospatial libraries
  4. ===============================
  5. GeoDjango uses and/or provides interfaces for the following open source
  6. geospatial libraries:
  7. ======================== ==================================== ================================ ==========================
  8. Program Description Required Supported Versions
  9. ======================== ==================================== ================================ ==========================
  10. :ref:`GEOS <ref-geos>` Geometry Engine Open Source Yes 3.3, 3.2, 3.1, 3.0
  11. `PROJ.4`_ Cartographic Projections library Yes (PostgreSQL and SQLite only) 4.8, 4.7, 4.6, 4.5, 4.4
  12. :ref:`GDAL <ref-gdal>` Geospatial Data Abstraction Library No (but, required for SQLite) 1.9, 1.8, 1.7, 1.6, 1.5
  13. :ref:`GeoIP <ref-geoip>` IP-based geolocation library No 1.4
  14. `PostGIS`__ Spatial extensions for PostgreSQL Yes (PostgreSQL only) 2.0, 1.5, 1.4, 1.3
  15. `SpatiaLite`__ Spatial extensions for SQLite Yes (SQLite only) 3.0, 2.4, 2.3
  16. ======================== ==================================== ================================ ==========================
  17. .. admonition:: Install GDAL
  18. While :ref:`gdalbuild` is technically not required, it is *recommended*.
  19. Important features of GeoDjango (including the :ref:`ref-layermapping`,
  20. geometry reprojection, and the geographic admin) depend on its
  21. functionality.
  22. .. note::
  23. The GeoDjango interfaces to GEOS, GDAL, and GeoIP may be used
  24. independently of Django. In other words, no database or settings file
  25. required -- just import them as normal from :mod:`django.contrib.gis`.
  26. .. _PROJ.4: http://trac.osgeo.org/proj/
  27. __ http://postgis.refractions.net/
  28. __ http://www.gaia-gis.it/gaia-sins/
  29. On Debian/Ubuntu, you are advised to install the following packages which will
  30. install, directly or by dependency, the required geospatial libraries:
  31. .. code-block:: bash
  32. $ sudo apt-get install binutils libproj-dev gdal-bin
  33. Optional packages to consider:
  34. * ``libgeoip1``: for :ref:`GeoIP <ref-geoip>` support
  35. * ``gdal-bin``: for GDAL command line programs like ``ogr2ogr``
  36. * ``python-gdal`` for GDAL's own Python bindings -- includes interfaces for raster manipulation
  37. Please also consult platform-specific instructions if you are on :ref:`macosx`
  38. or :ref:`windows`.
  39. .. _build_from_source:
  40. Building from source
  41. ====================
  42. When installing from source on UNIX and GNU/Linux systems, please follow
  43. the installation instructions carefully, and install the libraries in the
  44. given order. If using MySQL or Oracle as the spatial database, only GEOS
  45. is required.
  46. .. note::
  47. On Linux platforms, it may be necessary to run the ``ldconfig``
  48. command after installing each library. For example::
  49. $ sudo make install
  50. $ sudo ldconfig
  51. .. note::
  52. OS X users are required to install `Apple Developer Tools`_ in order
  53. to compile software from source. This is typically included on your
  54. OS X installation DVDs.
  55. .. _Apple Developer Tools: https://developer.apple.com/technologies/tools/
  56. .. _geosbuild:
  57. GEOS
  58. ----
  59. GEOS is a C++ library for performing geometric operations, and is the default
  60. internal geometry representation used by GeoDjango (it's behind the "lazy"
  61. geometries). Specifically, the C API library is called (e.g., ``libgeos_c.so``)
  62. directly from Python using ctypes.
  63. First, download GEOS 3.3.5 from the refractions Web site and untar the source
  64. archive::
  65. $ wget http://download.osgeo.org/geos/geos-3.3.5.tar.bz2
  66. $ tar xjf geos-3.3.5.tar.bz2
  67. Next, change into the directory where GEOS was unpacked, run the configure
  68. script, compile, and install::
  69. $ cd geos-3.3.5
  70. $ ./configure
  71. $ make
  72. $ sudo make install
  73. $ cd ..
  74. Troubleshooting
  75. ^^^^^^^^^^^^^^^
  76. Can't find GEOS library
  77. ~~~~~~~~~~~~~~~~~~~~~~~
  78. When GeoDjango can't find GEOS, this error is raised:
  79. .. code-block:: text
  80. ImportError: Could not find the GEOS library (tried "geos_c"). Try setting GEOS_LIBRARY_PATH in your settings.
  81. The most common solution is to properly configure your :ref:`libsettings` *or* set
  82. :ref:`geoslibrarypath` in your settings.
  83. If using a binary package of GEOS (e.g., on Ubuntu), you may need to :ref:`binutils`.
  84. .. _geoslibrarypath:
  85. ``GEOS_LIBRARY_PATH``
  86. ~~~~~~~~~~~~~~~~~~~~~
  87. If your GEOS library is in a non-standard location, or you don't want to
  88. modify the system's library path then the :setting:`GEOS_LIBRARY_PATH`
  89. setting may be added to your Django settings file with the full path to the
  90. GEOS C library. For example:
  91. .. code-block:: python
  92. GEOS_LIBRARY_PATH = '/home/bob/local/lib/libgeos_c.so'
  93. .. note::
  94. The setting must be the *full* path to the **C** shared library; in
  95. other words you want to use ``libgeos_c.so``, not ``libgeos.so``.
  96. See also :ref:`My logs are filled with GEOS-related errors <geos-exceptions-in-logfile>`.
  97. .. _proj4:
  98. PROJ.4
  99. ------
  100. `PROJ.4`_ is a library for converting geospatial data to different coordinate
  101. reference systems.
  102. First, download the PROJ.4 source code and datum shifting files [#]_::
  103. $ wget http://download.osgeo.org/proj/proj-4.8.0.tar.gz
  104. $ wget http://download.osgeo.org/proj/proj-datumgrid-1.5.tar.gz
  105. Next, untar the source code archive, and extract the datum shifting files in the
  106. ``nad`` subdirectory. This must be done *prior* to configuration::
  107. $ tar xzf proj-4.8.0.tar.gz
  108. $ cd proj-4.8.0/nad
  109. $ tar xzf ../../proj-datumgrid-1.5.tar.gz
  110. $ cd ..
  111. Finally, configure, make and install PROJ.4::
  112. $ ./configure
  113. $ make
  114. $ sudo make install
  115. $ cd ..
  116. .. _gdalbuild:
  117. GDAL
  118. ----
  119. `GDAL`__ is an excellent open source geospatial library that has support for
  120. reading most vector and raster spatial data formats. Currently, GeoDjango only
  121. supports :ref:`GDAL's vector data <ref-gdal>` capabilities [#]_.
  122. :ref:`geosbuild` and :ref:`proj4` should be installed prior to building GDAL.
  123. First download the latest GDAL release version and untar the archive::
  124. $ wget http://download.osgeo.org/gdal/gdal-1.9.1.tar.gz
  125. $ tar xzf gdal-1.9.1.tar.gz
  126. $ cd gdal-1.9.1
  127. Configure, make and install::
  128. $ ./configure
  129. $ make # Go get some coffee, this takes a while.
  130. $ sudo make install
  131. $ cd ..
  132. .. note::
  133. Because GeoDjango has it's own Python interface, the preceding instructions
  134. do not build GDAL's own Python bindings. The bindings may be built by
  135. adding the ``--with-python`` flag when running ``configure``. See
  136. `GDAL/OGR In Python`__ for more information on GDAL's bindings.
  137. If you have any problems, please see the troubleshooting section below for
  138. suggestions and solutions.
  139. __ http://trac.osgeo.org/gdal/
  140. __ http://trac.osgeo.org/gdal/wiki/GdalOgrInPython
  141. .. _gdaltrouble:
  142. Troubleshooting
  143. ^^^^^^^^^^^^^^^
  144. Can't find GDAL library
  145. ~~~~~~~~~~~~~~~~~~~~~~~
  146. When GeoDjango can't find the GDAL library, the ``HAS_GDAL`` flag
  147. will be false:
  148. .. code-block:: pycon
  149. >>> from django.contrib.gis import gdal
  150. >>> gdal.HAS_GDAL
  151. False
  152. The solution is to properly configure your :ref:`libsettings` *or* set
  153. :ref:`gdallibrarypath` in your settings.
  154. .. _gdallibrarypath:
  155. ``GDAL_LIBRARY_PATH``
  156. ~~~~~~~~~~~~~~~~~~~~~
  157. If your GDAL library is in a non-standard location, or you don't want to
  158. modify the system's library path then the :setting:`GDAL_LIBRARY_PATH`
  159. setting may be added to your Django settings file with the full path to
  160. the GDAL library. For example:
  161. .. code-block:: python
  162. GDAL_LIBRARY_PATH = '/home/sue/local/lib/libgdal.so'
  163. .. _gdaldata:
  164. Can't find GDAL data files (``GDAL_DATA``)
  165. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  166. When installed from source, GDAL versions 1.5.1 and below have an autoconf bug
  167. that places data in the wrong location. [#]_ This can lead to error messages
  168. like this:
  169. .. code-block:: text
  170. ERROR 4: Unable to open EPSG support file gcs.csv.
  171. ...
  172. OGRException: OGR failure.
  173. The solution is to set the ``GDAL_DATA`` environment variable to the location of the
  174. GDAL data files before invoking Python (typically ``/usr/local/share``; use
  175. ``gdal-config --datadir`` to find out). For example::
  176. $ export GDAL_DATA=`gdal-config --datadir`
  177. $ python manage.py shell
  178. If using Apache, you may need to add this environment variable to your configuration
  179. file:
  180. .. code-block:: apache
  181. SetEnv GDAL_DATA /usr/local/share
  182. .. rubric:: Footnotes
  183. .. [#] The datum shifting files are needed for converting data to and from
  184. certain projections.
  185. For example, the PROJ.4 string for the `Google projection (900913 or 3857)
  186. <http://spatialreference.org/ref/sr-org/6864/prj/>`_ requires the
  187. ``null`` grid file only included in the extra datum shifting files.
  188. It is easier to install the shifting files now, then to have debug a
  189. problem caused by their absence later.
  190. .. [#] Specifically, GeoDjango provides support for the `OGR
  191. <http://gdal.org/ogr>`_ library, a component of GDAL.
  192. .. [#] See `GDAL ticket #2382 <http://trac.osgeo.org/gdal/ticket/2382>`_.