geolibs.txt 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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
  11. :doc:`GDAL <../gdal>` Geospatial Data Abstraction Library Yes 3.8, 3.7, 3.6, 3.5, 3.4, 3.3, 3.2, 3.1, 3.0
  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. GDAL 3.0.0 2019-05
  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. PostGIS 3.1.0 2020-12-18
  35. PostGIS 3.2.0 2021-12-18
  36. PostGIS 3.3.0 2022-08-27
  37. PostGIS 3.4.0 2023-08-15
  38. PROJ 9.0.0 2022-03-01
  39. PROJ 8.0.0 2021-03-01
  40. PROJ 8.0.0 2021-03-01
  41. PROJ 7.0.0 2020-02-25
  42. PROJ 6.0.0 2019-02-26
  43. SpatiaLite 4.3.0 2015-09-07
  44. SpatiaLite 5.0.0 2020-08-23
  45. SpatiaLite 5.1.0 2023-08-04
  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. .. code-block:: shell
  70. $ sudo make install
  71. $ sudo ldconfig
  72. .. note::
  73. macOS users must install `Xcode`_ in order to compile software from source.
  74. .. _Xcode: https://developer.apple.com/xcode/
  75. .. _geosbuild:
  76. GEOS
  77. ----
  78. GEOS is a C++ library for performing geometric operations, and is the default
  79. internal geometry representation used by GeoDjango (it's behind the "lazy"
  80. geometries). Specifically, the C API library is called (e.g., ``libgeos_c.so``)
  81. directly from Python using ctypes.
  82. First, download GEOS from the GEOS website and untar the source archive:
  83. .. code-block:: shell
  84. $ wget https://download.osgeo.org/geos/geos-X.Y.Z.tar.bz2
  85. $ tar xjf geos-X.Y.Z.tar.bz2
  86. Then step into the GEOS directory, create a ``build`` folder, and step into
  87. it:
  88. .. code-block:: shell
  89. $ cd geos-X.Y.Z
  90. $ mkdir build
  91. $ cd build
  92. Then build and install the package:
  93. .. code-block:: shell
  94. $ cmake -DCMAKE_BUILD_TYPE=Release ..
  95. $ cmake --build .
  96. $ sudo cmake --build . --target install
  97. Troubleshooting
  98. ~~~~~~~~~~~~~~~
  99. Can't find GEOS library
  100. ^^^^^^^^^^^^^^^^^^^^^^^
  101. When GeoDjango can't find GEOS, this error is raised:
  102. .. code-block:: text
  103. ImportError: Could not find the GEOS library (tried "geos_c"). Try setting GEOS_LIBRARY_PATH in your settings.
  104. The most common solution is to properly configure your :ref:`libsettings` *or* set
  105. :ref:`geoslibrarypath` in your settings.
  106. If using a binary package of GEOS (e.g., on Ubuntu), you may need to :ref:`binutils`.
  107. .. _geoslibrarypath:
  108. ``GEOS_LIBRARY_PATH``
  109. ^^^^^^^^^^^^^^^^^^^^^
  110. If your GEOS library is in a non-standard location, or you don't want to
  111. modify the system's library path then the :setting:`GEOS_LIBRARY_PATH`
  112. setting may be added to your Django settings file with the full path to the
  113. GEOS C library. For example:
  114. .. code-block:: shell
  115. GEOS_LIBRARY_PATH = '/home/bob/local/lib/libgeos_c.so'
  116. .. note::
  117. The setting must be the *full* path to the **C** shared library; in
  118. other words you want to use ``libgeos_c.so``, not ``libgeos.so``.
  119. See also :ref:`My logs are filled with GEOS-related errors <geos-exceptions-in-logfile>`.
  120. .. _proj4:
  121. PROJ
  122. ----
  123. `PROJ`_ is a library for converting geospatial data to different coordinate
  124. reference systems.
  125. First, download the PROJ source code:
  126. .. code-block:: shell
  127. $ wget https://download.osgeo.org/proj/proj-X.Y.Z.tar.gz
  128. ... and datum shifting files (download ``proj-datumgrid-X.Y.tar.gz`` for
  129. PROJ < 7.x) [#]_:
  130. .. code-block:: shell
  131. $ wget https://download.osgeo.org/proj/proj-data-X.Y.tar.gz
  132. Next, untar the source code archive, and extract the datum shifting files in the
  133. ``data`` subdirectory. This must be done *prior* to configuration:
  134. .. code-block:: shell
  135. $ tar xzf proj-X.Y.Z.tar.gz
  136. $ cd proj-X.Y.Z/data
  137. $ tar xzf ../../proj-data-X.Y.tar.gz
  138. $ cd ../..
  139. For PROJ 9.x and greater, releases only support builds using ``CMake`` (see
  140. `PROJ RFC-7`_).
  141. To build with ``CMake`` ensure your system meets the `build requirements`_.
  142. Then create a ``build`` folder in the PROJ directory, and step into it:
  143. .. code-block:: shell
  144. $ cd proj-X.Y.Z
  145. $ mkdir build
  146. $ cd build
  147. Finally, configure, make and install PROJ:
  148. .. code-block:: shell
  149. $ cmake ..
  150. $ cmake --build .
  151. $ sudo cmake --build . --target install
  152. .. _PROJ RFC-7: https://proj.org/community/rfc/rfc-7.html#rfc7
  153. .. _build requirements: https://proj.org/install.html#build-requirements
  154. .. _gdalbuild:
  155. GDAL
  156. ----
  157. `GDAL`__ is an excellent open source geospatial library that has support for
  158. reading most vector and raster spatial data formats. Currently, GeoDjango only
  159. supports :doc:`GDAL's vector data <../gdal>` capabilities [#]_.
  160. :ref:`geosbuild` and :ref:`proj4` should be installed prior to building GDAL.
  161. First download the latest GDAL release version and untar the archive:
  162. .. code-block:: shell
  163. $ wget https://download.osgeo.org/gdal/X.Y.Z/gdal-X.Y.Z.tar.gz
  164. $ tar xzf gdal-X.Y.Z.tar.gz
  165. For GDAL 3.6.x and greater, releases only support builds using ``CMake``. To
  166. build with ``CMake`` create a ``build`` folder in the GDAL directory, and step
  167. into it:
  168. .. code-block:: shell
  169. $ cd gdal-X.Y.Z
  170. $ mkdir build
  171. $ cd build
  172. Finally, configure, make and install GDAL:
  173. .. code-block:: shell
  174. $ cmake ..
  175. $ cmake --build .
  176. $ sudo cmake --build . --target install
  177. If you have any problems, please see the troubleshooting section below for
  178. suggestions and solutions.
  179. __ https://gdal.org/
  180. .. _gdaltrouble:
  181. Troubleshooting
  182. ~~~~~~~~~~~~~~~
  183. Can't find GDAL library
  184. ^^^^^^^^^^^^^^^^^^^^^^^
  185. When GeoDjango can't find the GDAL library, configure your :ref:`libsettings`
  186. *or* set :ref:`gdallibrarypath` in your settings.
  187. .. _gdallibrarypath:
  188. ``GDAL_LIBRARY_PATH``
  189. ^^^^^^^^^^^^^^^^^^^^^
  190. If your GDAL library is in a non-standard location, or you don't want to
  191. modify the system's library path then the :setting:`GDAL_LIBRARY_PATH`
  192. setting may be added to your Django settings file with the full path to
  193. the GDAL library. For example:
  194. .. code-block:: shell
  195. GDAL_LIBRARY_PATH = '/home/sue/local/lib/libgdal.so'
  196. .. rubric:: Footnotes
  197. .. [#] The datum shifting files are needed for converting data to and from
  198. certain projections.
  199. For example, the PROJ string for the `Google projection (900913 or 3857)
  200. <https://spatialreference.org/ref/epsg/3857/>`_ requires the ``null``
  201. grid file only included in the extra datum shifting files. It is easier
  202. to install the shifting files now, then to have debug a problem caused
  203. by their absence later.
  204. .. [#] Specifically, GeoDjango provides support for the `OGR
  205. <https://gdal.org/user/vector_data_model.html>`_ library, a component of
  206. GDAL.