spatialite.txt 3.4 KB

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