spatialite.txt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. sqlite> CREATE VIRTUAL TABLE testrtree USING rtree(id,minX,maxX,minY,maxY);
  26. If you obtain an error, you will have to recompile SQLite from source. Otherwise,
  27. skip this section.
  28. To install from sources, download the latest amalgamation source archive from
  29. the `SQLite download page`__, and extract::
  30. $ wget https://www.sqlite.org/YYYY/sqlite-amalgamation-XXX0000.zip
  31. $ unzip sqlite-amalgamation-XXX0000.zip
  32. $ cd sqlite-amalgamation-XXX0000
  33. Next, run the ``configure`` script -- however the ``CFLAGS`` environment variable
  34. needs to be customized so that SQLite knows to build the R*Tree module::
  35. $ CFLAGS="-DSQLITE_ENABLE_RTREE=1" ./configure
  36. $ make
  37. $ sudo make install
  38. $ cd ..
  39. __ https://www.sqlite.org/rtree.html
  40. __ https://www.sqlite.org/download.html
  41. .. _spatialitebuild:
  42. SpatiaLite library (``libspatialite``)
  43. --------------------------------------
  44. Get the latest SpatiaLite library source bundle from the
  45. `download page`__::
  46. $ wget https://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-X.Y.Z.tar.gz
  47. $ tar xaf libspatialite-X.Y.Z.tar.gz
  48. $ cd libspatialite-X.Y.Z
  49. $ ./configure
  50. $ make
  51. $ sudo make install
  52. .. note::
  53. For macOS users building from source, the SpatiaLite library *and* tools
  54. need to have their ``target`` configured::
  55. $ ./configure --target=macosx
  56. __ https://www.gaia-gis.it/gaia-sins/libspatialite-sources/
  57. .. _spatialite_macos:
  58. macOS-specific instructions
  59. ==============================
  60. To install the SpatiaLite library and tools, macOS users can use `Homebrew`_.
  61. Homebrew
  62. --------
  63. `Homebrew`_ handles all the SpatiaLite related packages on your behalf,
  64. including SQLite, SpatiaLite, PROJ, and GEOS. Install them like this::
  65. $ brew update
  66. $ brew install spatialite-tools
  67. $ brew install gdal
  68. Finally, for GeoDjango to be able to find the SpatiaLite library, add the
  69. following to your ``settings.py``::
  70. SPATIALITE_LIBRARY_PATH='/usr/local/lib/mod_spatialite.dylib'
  71. .. _Homebrew: https://brew.sh/