spatialite.txt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. =====================
  2. Installing Spatialite
  3. =====================
  4. `SpatiaLite`__ adds spatial support to SQLite, turning it into a full-featured
  5. spatial database.
  6. Check first if you can install Spatialite from system packages or binaries. For
  7. example, on Debian-based distributions, try to install the ``spatialite-bin``
  8. package. For Mac OS X, follow the
  9. :ref:`specific instructions below<spatialite_macosx>`. For Windows, you may
  10. find binaries on `Gaia-SINS`__ home page. In any case, you should always
  11. be able to :ref:`install from source<spatialite_source>`.
  12. When you are done with the installation process, skip to :ref:`create_spatialite_db`.
  13. __ https://www.gaia-gis.it/fossil/libspatialite
  14. __ http://www.gaia-gis.it/gaia-sins/
  15. .. _spatialite_source:
  16. Installing from source
  17. ~~~~~~~~~~~~~~~~~~~~~~
  18. :doc:`GEOS and PROJ.4</ref/contrib/gis/install/geolibs>` should be installed
  19. prior to building SpatiaLite.
  20. SQLite
  21. ^^^^^^
  22. Check first if SQLite is compiled with the `R*Tree module`__. Run the sqlite3
  23. command line interface and enter the following query::
  24. sqlite> CREATE VIRTUAL TABLE testrtree USING rtree(id,minX,maxX,minY,maxY);
  25. If you obtain an error, you will have to recompile SQLite from source. Otherwise,
  26. just skip this section.
  27. To install from sources, download the latest amalgamation source archive from
  28. the `SQLite download page`__, and extract::
  29. $ wget https://sqlite.org/sqlite-amalgamation-3.6.23.1.tar.gz
  30. $ tar xzf sqlite-amalgamation-3.6.23.1.tar.gz
  31. $ cd sqlite-3.6.23.1
  32. Next, run the ``configure`` script -- however the ``CFLAGS`` environment variable
  33. needs to be customized so that SQLite knows to build the R*Tree module::
  34. $ CFLAGS="-DSQLITE_ENABLE_RTREE=1" ./configure
  35. $ make
  36. $ sudo make install
  37. $ cd ..
  38. __ https://www.sqlite.org/rtree.html
  39. __ https://www.sqlite.org/download.html
  40. .. _spatialitebuild:
  41. SpatiaLite library (``libspatialite``)
  42. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  43. Get the latest SpatiaLite library source bundle from the
  44. `download page`__::
  45. $ wget http://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-4.1.0.tar.gz
  46. $ tar xaf libspatialite-4.1.0.tar.gz
  47. $ cd libspatialite-4.1.0
  48. $ ./configure
  49. $ make
  50. $ sudo make install
  51. .. note::
  52. For Mac OS X users building from source, the SpatiaLite library *and* tools
  53. need to have their ``target`` configured::
  54. $ ./configure --target=macosx
  55. __ http://www.gaia-gis.it/gaia-sins/libspatialite-sources/
  56. .. _spatialite_macosx:
  57. Mac OS X-specific instructions
  58. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  59. To install the SpatiaLite library and tools, Mac OS X users can choose between
  60. :ref:`kyngchaos` and `Homebrew`_.
  61. KyngChaos
  62. ^^^^^^^^^
  63. First, follow the instructions in the :ref:`kyngchaos` section.
  64. When :ref:`create_spatialite_db`, the ``spatialite`` program is required.
  65. However, instead of attempting to compile the SpatiaLite tools from source,
  66. download the `SpatiaLite Binaries`__ for OS X, and install ``spatialite`` in a
  67. location available in your ``PATH``. For example::
  68. $ curl -O http://www.gaia-gis.it/spatialite/spatialite-tools-osx-x86-2.3.1.tar.gz
  69. $ tar xzf spatialite-tools-osx-x86-2.3.1.tar.gz
  70. $ cd spatialite-tools-osx-x86-2.3.1/bin
  71. $ sudo cp spatialite /Library/Frameworks/SQLite3.framework/Programs
  72. Finally, for GeoDjango to be able to find the KyngChaos SpatiaLite library,
  73. add the following to your ``settings.py``::
  74. SPATIALITE_LIBRARY_PATH='/Library/Frameworks/SQLite3.framework/SQLite3'
  75. __ http://www.gaia-gis.it/spatialite-2.3.1/binaries.html
  76. Homebrew
  77. ^^^^^^^^
  78. `Homebrew`_ handles all the SpatiaLite related packages on your behalf,
  79. including SQLite3, SpatiaLite, PROJ, and GEOS. Install them like this::
  80. $ brew update
  81. $ brew install spatialite-tools
  82. $ brew install gdal
  83. Finally, for GeoDjango to be able to find the SpatiaLite library, add the
  84. following to your ``settings.py``::
  85. SPATIALITE_LIBRARY_PATH='/usr/local/lib/mod_spatialite.dylib'
  86. .. _Homebrew: http://brew.sh/
  87. .. _create_spatialite_db:
  88. Creating a spatial database for SpatiaLite
  89. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  90. When running ``manage.py migrate`` with a SQLite or SpatiaLite database, the
  91. database file will be automatically created if it doesn't exist. Django will
  92. also ensure that the spatial metadata are initialized in the database.