geolibs.txt 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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.10, 3.9, 3.8, 3.7, 3.6
  10. `PROJ`_ Cartographic Projections library Yes (PostgreSQL and SQLite only) 9.x, 8.x, 7.x, 6.x, 5.x, 4.x
  11. :doc:`GDAL <../gdal>` Geospatial Data Abstraction Library Yes 3.4, 3.3, 3.2, 3.1, 3.0, 2.4, 2.3, 2.2
  12. :doc:`GeoIP <../geoip2>` IP-based geolocation library No 2
  13. `PostGIS`__ Spatial extensions for PostgreSQL Yes (PostgreSQL only) 3.2, 3.1, 3.0, 2.5
  14. `SpatiaLite`__ Spatial extensions for SQLite Yes (SQLite only) 5.0, 4.3
  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. ..
  19. Libs release dates:
  20. GEOS 3.6.0 2016-10-25
  21. GEOS 3.7.0 2018-09-10
  22. GEOS 3.8.0 2019-10-10
  23. GEOS 3.9.0 2020-12-14
  24. GEOS 3.10.0 2021-10-20
  25. GDAL 2.2.0 2017-05
  26. GDAL 2.3.0 2018-05
  27. GDAL 2.4.0 2018-12
  28. GDAL 3.0.0 2019-05
  29. GDAL 3.1.0 2020-05-07
  30. GDAL 3.2.0 2020-11-02
  31. GDAL 3.3.0 2021-05-03
  32. GDAL 3.4.0 2021-11-04
  33. PostGIS 2.5.0 2018-09-23
  34. PostGIS 3.0.0 2019-10-20
  35. PostGIS 3.1.0 2020-12-18
  36. PostGIS 3.2.0 2021-12-18
  37. PROJ 9.0.0 2022-03-01
  38. PROJ 8.0.0 2021-03-01
  39. PROJ 8.0.0 2021-03-01
  40. PROJ 7.0.0 2020-02-25
  41. PROJ 6.0.0 2019-02-26
  42. PROJ 5.0.0 2018-03-01
  43. PROJ 4.9.0 2014-09-14
  44. SpatiaLite 4.3.0 2015-09-07
  45. SpatiaLite 5.0.0 2020-08-23
  46. .. note::
  47. The GeoDjango interfaces to GEOS, GDAL, and GeoIP may be used
  48. independently of Django. In other words, no database or settings file
  49. required -- import them as normal from :mod:`django.contrib.gis`.
  50. .. _PROJ: https://proj.org/
  51. __ https://postgis.net/
  52. __ https://www.gaia-gis.it/gaia-sins/
  53. On Debian/Ubuntu, you are advised to install the following packages which will
  54. install, directly or by dependency, the required geospatial libraries:
  55. .. code-block:: console
  56. $ sudo apt-get install binutils libproj-dev gdal-bin
  57. Please also consult platform-specific instructions if you are on :ref:`macos`
  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`` command
  68. after installing each library. For example::
  69. $ sudo make install
  70. $ sudo ldconfig
  71. .. note::
  72. macOS users must install `Xcode`_ in order to compile software from source.
  73. .. _Xcode: https://developer.apple.com/xcode/
  74. .. _geosbuild:
  75. GEOS
  76. ----
  77. GEOS is a C++ library for performing geometric operations, and is the default
  78. internal geometry representation used by GeoDjango (it's behind the "lazy"
  79. geometries). Specifically, the C API library is called (e.g., ``libgeos_c.so``)
  80. directly from Python using ctypes.
  81. First, download GEOS from the GEOS website and untar the source archive::
  82. $ wget https://download.osgeo.org/geos/geos-X.Y.Z.tar.bz2
  83. $ tar xjf geos-X.Y.Z.tar.bz2
  84. Then step into the GEOS directory, create a ``build`` folder, and step into
  85. it::
  86. $ cd geos-X.Y.Z
  87. $ mkdir build
  88. $ cd build
  89. Then build and install the package::
  90. $ cmake -DCMAKE_BUILD_TYPE=Release ..
  91. $ cmake --build .
  92. $ sudo cmake --build . --target install
  93. Troubleshooting
  94. ~~~~~~~~~~~~~~~
  95. Can't find GEOS library
  96. ^^^^^^^^^^^^^^^^^^^^^^^
  97. When GeoDjango can't find GEOS, this error is raised:
  98. .. code-block:: text
  99. ImportError: Could not find the GEOS library (tried "geos_c"). Try setting GEOS_LIBRARY_PATH in your settings.
  100. The most common solution is to properly configure your :ref:`libsettings` *or* set
  101. :ref:`geoslibrarypath` in your settings.
  102. If using a binary package of GEOS (e.g., on Ubuntu), you may need to :ref:`binutils`.
  103. .. _geoslibrarypath:
  104. ``GEOS_LIBRARY_PATH``
  105. ^^^^^^^^^^^^^^^^^^^^^
  106. If your GEOS library is in a non-standard location, or you don't want to
  107. modify the system's library path then the :setting:`GEOS_LIBRARY_PATH`
  108. setting may be added to your Django settings file with the full path to the
  109. GEOS C library. For example::
  110. GEOS_LIBRARY_PATH = '/home/bob/local/lib/libgeos_c.so'
  111. .. note::
  112. The setting must be the *full* path to the **C** shared library; in
  113. other words you want to use ``libgeos_c.so``, not ``libgeos.so``.
  114. See also :ref:`My logs are filled with GEOS-related errors <geos-exceptions-in-logfile>`.
  115. .. _proj4:
  116. PROJ
  117. ----
  118. `PROJ`_ is a library for converting geospatial data to different coordinate
  119. reference systems.
  120. First, download the PROJ source code::
  121. $ wget https://download.osgeo.org/proj/proj-X.Y.Z.tar.gz
  122. ... and datum shifting files (download ``proj-datumgrid-X.Y.tar.gz`` for
  123. PROJ < 7.x) [#]_::
  124. $ wget https://download.osgeo.org/proj/proj-data-X.Y.tar.gz
  125. Next, untar the source code archive, and extract the datum shifting files in the
  126. ``data`` subdirectory (use ``nad`` subdirectory for PROJ < 6.x). This must be
  127. done *prior* to configuration::
  128. $ tar xzf proj-X.Y.Z.tar.gz
  129. $ cd proj-X.Y.Z/data
  130. $ tar xzf ../../proj-data-X.Y.tar.gz
  131. $ cd ../..
  132. For PROJ 9.x and greater, releases only support builds using ``CMake`` (see
  133. `PROJ RFC-7`_).
  134. To build with ``CMake`` ensure your system meets the `build requirements`_.
  135. Then create a ``build`` folder in the PROJ directory, and step into it::
  136. $ cd proj-X.Y.Z
  137. $ mkdir build
  138. $ cd build
  139. Finally, configure, make and install PROJ::
  140. $ cmake ..
  141. $ cmake --build .
  142. $ sudo cmake --build . --target install
  143. .. _PROJ RFC-7: https://proj.org/community/rfc/rfc-7.html#rfc7
  144. .. _build requirements: https://proj.org/install.html#build-requirements
  145. .. _gdalbuild:
  146. GDAL
  147. ----
  148. `GDAL`__ is an excellent open source geospatial library that has support for
  149. reading most vector and raster spatial data formats. Currently, GeoDjango only
  150. supports :doc:`GDAL's vector data <../gdal>` capabilities [#]_.
  151. :ref:`geosbuild` and :ref:`proj4` should be installed prior to building GDAL.
  152. First download the latest GDAL release version and untar the archive::
  153. $ wget https://download.osgeo.org/gdal/X.Y.Z/gdal-X.Y.Z.tar.gz
  154. $ tar xzf gdal-X.Y.Z.tar.gz
  155. $ cd gdal-X.Y.Z
  156. Configure, make and install::
  157. $ ./configure
  158. $ make # Go get some coffee, this takes a while.
  159. $ sudo make install
  160. $ cd ..
  161. .. note::
  162. Because GeoDjango has its own Python interface, the preceding instructions
  163. do not build GDAL's own Python bindings. The bindings may be built by
  164. adding the ``--with-python`` flag when running ``configure``. See
  165. `GDAL/OGR In Python`__ for more information on GDAL's bindings.
  166. If you have any problems, please see the troubleshooting section below for
  167. suggestions and solutions.
  168. __ https://gdal.org/
  169. __ https://gdal.org/api/python.html
  170. .. _gdaltrouble:
  171. Troubleshooting
  172. ~~~~~~~~~~~~~~~
  173. Can't find GDAL library
  174. ^^^^^^^^^^^^^^^^^^^^^^^
  175. When GeoDjango can't find the GDAL library, configure your :ref:`libsettings`
  176. *or* set :ref:`gdallibrarypath` in your settings.
  177. .. _gdallibrarypath:
  178. ``GDAL_LIBRARY_PATH``
  179. ^^^^^^^^^^^^^^^^^^^^^
  180. If your GDAL library is in a non-standard location, or you don't want to
  181. modify the system's library path then the :setting:`GDAL_LIBRARY_PATH`
  182. setting may be added to your Django settings file with the full path to
  183. the GDAL library. For example::
  184. GDAL_LIBRARY_PATH = '/home/sue/local/lib/libgdal.so'
  185. .. rubric:: Footnotes
  186. .. [#] The datum shifting files are needed for converting data to and from
  187. certain projections.
  188. For example, the PROJ string for the `Google projection (900913 or 3857)
  189. <https://spatialreference.org/ref/sr-org/6864/prj/>`_ requires the
  190. ``null`` grid file only included in the extra datum shifting files.
  191. It is easier to install the shifting files now, then to have debug a
  192. problem caused by their absence later.
  193. .. [#] Specifically, GeoDjango provides support for the `OGR
  194. <https://gdal.org/user/vector_data_model.html>`_ library, a component of
  195. GDAL.