spatialite.txt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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.2+, 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
  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 choose between
  61. :ref:`kyngchaos` and `Homebrew`_.
  62. KyngChaos
  63. ---------
  64. First, follow the instructions in the :ref:`kyngchaos` section.
  65. When creating a SpatiaLite database, the ``spatialite`` program is required.
  66. However, instead of attempting to compile the SpatiaLite tools from source,
  67. download the `SpatiaLite Tools`__ package for macOS, and install ``spatialite``
  68. in a location available in your ``PATH``. For example::
  69. $ curl -O https://www.kyngchaos.com/files/software/frameworks/Spatialite_Tools-4.3.zip
  70. $ unzip Spatialite_Tools-4.3.zip
  71. $ cd Spatialite\ Tools/tools
  72. $ sudo cp spatialite /Library/Frameworks/SQLite3.framework/Programs
  73. Finally, for GeoDjango to be able to find the KyngChaos SpatiaLite library,
  74. add the following to your ``settings.py``::
  75. SPATIALITE_LIBRARY_PATH='/Library/Frameworks/SQLite3.framework/SQLite3'
  76. __ https://www.kyngchaos.com/software/frameworks/
  77. Homebrew
  78. --------
  79. `Homebrew`_ handles all the SpatiaLite related packages on your behalf,
  80. including SQLite, SpatiaLite, PROJ, and GEOS. Install them like this::
  81. $ brew update
  82. $ brew install spatialite-tools
  83. $ brew install gdal
  84. Finally, for GeoDjango to be able to find the SpatiaLite library, add the
  85. following to your ``settings.py``::
  86. SPATIALITE_LIBRARY_PATH='/usr/local/lib/mod_spatialite.dylib'
  87. .. _Homebrew: https://brew.sh/