geolibs.txt 8.4 KB

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