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