geolibs.txt 7.9 KB

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