geolibs.txt 9.0 KB

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