1. =====================
    
  2. Installing SpatiaLite
    
  3. =====================
    
  4. 
    
  5. `SpatiaLite`__ adds spatial support to SQLite, turning it into a full-featured
    
  6. spatial database.
    
  7. 
    
  8. First, check if you can install SpatiaLite from system packages or binaries.
    
  9. 
    
  10. For example, on Debian-based distributions that package SpatiaLite 4.3+, try to
    
  11. install the ``libsqlite3-mod-spatialite`` package. For older releases install
    
  12. ``spatialite-bin``.
    
  13. 
    
  14. For macOS, follow the :ref:`instructions below<spatialite_macos>`.
    
  15. 
    
  16. For Windows, you may find binaries on the `Gaia-SINS`__ home page.
    
  17. 
    
  18. In any case, you should always be able to :ref:`install from source
    
  19. <spatialite_source>`.
    
  20. 
    
  21. __ https://www.gaia-gis.it/fossil/libspatialite/index
    
  22. __ https://www.gaia-gis.it/gaia-sins/
    
  23. 
    
  24. .. _spatialite_source:
    
  25. 
    
  26. Installing from source
    
  27. ======================
    
  28. 
    
  29. :doc:`GEOS and PROJ</ref/contrib/gis/install/geolibs>` should be installed
    
  30. prior to building SpatiaLite.
    
  31. 
    
  32. SQLite
    
  33. ------
    
  34. 
    
  35. Check first if SQLite is compiled with the `R*Tree module`__. Run the sqlite3
    
  36. command line interface and enter the following query::
    
  37. 
    
  38.     sqlite> CREATE VIRTUAL TABLE testrtree USING rtree(id,minX,maxX,minY,maxY);
    
  39. 
    
  40. If you obtain an error, you will have to recompile SQLite from source. Otherwise,
    
  41. skip this section.
    
  42. 
    
  43. To install from sources, download the latest amalgamation source archive from
    
  44. the `SQLite download page`__, and extract::
    
  45. 
    
  46.     $ wget https://www.sqlite.org/YYYY/sqlite-amalgamation-XXX0000.zip
    
  47.     $ unzip sqlite-amalgamation-XXX0000.zip
    
  48.     $ cd sqlite-amalgamation-XXX0000
    
  49. 
    
  50. Next, run the ``configure`` script -- however the ``CFLAGS`` environment variable
    
  51. needs to be customized so that SQLite knows to build the R*Tree module::
    
  52. 
    
  53.     $ CFLAGS="-DSQLITE_ENABLE_RTREE=1" ./configure
    
  54.     $ make
    
  55.     $ sudo make install
    
  56.     $ cd ..
    
  57. 
    
  58. __ https://www.sqlite.org/rtree.html
    
  59. __ https://www.sqlite.org/download.html
    
  60. 
    
  61. .. _spatialitebuild:
    
  62. 
    
  63. SpatiaLite library (``libspatialite``)
    
  64. --------------------------------------
    
  65. 
    
  66. Get the latest SpatiaLite library source bundle from the
    
  67. `download page`__::
    
  68. 
    
  69.     $ wget https://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-X.Y.Z.tar.gz
    
  70.     $ tar xaf libspatialite-X.Y.Z.tar.gz
    
  71.     $ cd libspatialite-X.Y.Z
    
  72.     $ ./configure
    
  73.     $ make
    
  74.     $ sudo make install
    
  75. 
    
  76. .. note::
    
  77. 
    
  78.     For macOS users building from source, the SpatiaLite library *and* tools
    
  79.     need to have their ``target`` configured::
    
  80. 
    
  81.         $ ./configure --target=macosx
    
  82. 
    
  83. __ https://www.gaia-gis.it/gaia-sins/libspatialite-sources/
    
  84. 
    
  85. .. _spatialite_macos:
    
  86. 
    
  87. macOS-specific instructions
    
  88. ==============================
    
  89. 
    
  90. To install the SpatiaLite library and tools, macOS users can use `Homebrew`_.
    
  91. 
    
  92. Homebrew
    
  93. --------
    
  94. 
    
  95. `Homebrew`_ handles all the SpatiaLite related packages on your behalf,
    
  96. including SQLite, SpatiaLite, PROJ, and GEOS. Install them like this::
    
  97. 
    
  98.     $ brew update
    
  99.     $ brew install spatialite-tools
    
  100.     $ brew install gdal
    
  101. 
    
  102. Finally, for GeoDjango to be able to find the SpatiaLite library, add the
    
  103. following to your ``settings.py``::
    
  104. 
    
  105.     SPATIALITE_LIBRARY_PATH='/usr/local/lib/mod_spatialite.dylib'
    
  106. 
    
  107. .. _Homebrew: https://brew.sh/