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