geolibs.txt 8.8 KB

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