spatialite.txt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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, try to install the
  8. ``spatialite-bin`` package. For distributions that package SpatiaLite 4.2+,
  9. install ``libsqlite3-mod-spatialite``.
  10. For Mac OS X, follow the :ref:`instructions below<spatialite_macosx>`.
  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. .. admonition:: ``SPATIALITE_LIBRARY_PATH`` setting required for SpatiaLite 4.2+
  18. If you're using SpatiaLite 4.2+, you must put this in your settings::
  19. SPATIALITE_LIBRARY_PATH = 'mod_spatialite'
  20. Installing from source
  21. ======================
  22. :doc:`GEOS and PROJ.4</ref/contrib/gis/install/geolibs>` should be installed
  23. prior to building SpatiaLite.
  24. SQLite
  25. ------
  26. Check first if SQLite is compiled with the `R*Tree module`__. Run the sqlite3
  27. command line interface and enter the following query::
  28. sqlite> CREATE VIRTUAL TABLE testrtree USING rtree(id,minX,maxX,minY,maxY);
  29. If you obtain an error, you will have to recompile SQLite from source. Otherwise,
  30. just skip this section.
  31. To install from sources, download the latest amalgamation source archive from
  32. the `SQLite download page`__, and extract::
  33. $ wget https://sqlite.org/sqlite-amalgamation-3.6.23.1.tar.gz
  34. $ tar xzf sqlite-amalgamation-3.6.23.1.tar.gz
  35. $ cd sqlite-3.6.23.1
  36. Next, run the ``configure`` script -- however the ``CFLAGS`` environment variable
  37. needs to be customized so that SQLite knows to build the R*Tree module::
  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. $ wget https://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-4.1.0.tar.gz
  50. $ tar xaf libspatialite-4.1.0.tar.gz
  51. $ cd libspatialite-4.1.0
  52. $ ./configure
  53. $ make
  54. $ sudo make install
  55. .. note::
  56. For Mac OS X users building from source, the SpatiaLite library *and* tools
  57. need to have their ``target`` configured::
  58. $ ./configure --target=macosx
  59. __ https://www.gaia-gis.it/gaia-sins/libspatialite-sources/
  60. .. _spatialite_macosx:
  61. Mac OS X-specific instructions
  62. ==============================
  63. To install the SpatiaLite library and tools, Mac OS X users can choose between
  64. :ref:`kyngchaos` and `Homebrew`_.
  65. KyngChaos
  66. ---------
  67. First, follow the instructions in the :ref:`kyngchaos` section.
  68. When creating a SpatiaLite database, the ``spatialite`` program is required.
  69. However, instead of attempting to compile the SpatiaLite tools from source,
  70. download the `SpatiaLite Binaries`__ for OS X, and install ``spatialite`` in a
  71. location available in your ``PATH``. For example::
  72. $ curl -O https://www.gaia-gis.it/spatialite/spatialite-tools-osx-x86-2.3.1.tar.gz
  73. $ tar xzf spatialite-tools-osx-x86-2.3.1.tar.gz
  74. $ cd spatialite-tools-osx-x86-2.3.1/bin
  75. $ sudo cp spatialite /Library/Frameworks/SQLite3.framework/Programs
  76. Finally, for GeoDjango to be able to find the KyngChaos SpatiaLite library,
  77. add the following to your ``settings.py``::
  78. SPATIALITE_LIBRARY_PATH='/Library/Frameworks/SQLite3.framework/SQLite3'
  79. __ https://www.gaia-gis.it/spatialite-2.3.1/binaries.html
  80. Homebrew
  81. --------
  82. `Homebrew`_ handles all the SpatiaLite related packages on your behalf,
  83. including SQLite3, SpatiaLite, PROJ, and GEOS. Install them like this::
  84. $ brew update
  85. $ brew install spatialite-tools
  86. $ brew install gdal
  87. Finally, for GeoDjango to be able to find the SpatiaLite library, add the
  88. following to your ``settings.py``::
  89. SPATIALITE_LIBRARY_PATH='/usr/local/lib/mod_spatialite.dylib'
  90. .. _Homebrew: http://brew.sh/