geolibs.txt 9.1 KB

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