2012-10-20 00:19:17 +08:00
|
|
|
=====================
|
2016-08-10 00:46:14 +08:00
|
|
|
Installing SpatiaLite
|
2012-10-20 00:19:17 +08:00
|
|
|
=====================
|
|
|
|
|
|
|
|
`SpatiaLite`__ adds spatial support to SQLite, turning it into a full-featured
|
|
|
|
spatial database.
|
|
|
|
|
2016-08-10 00:46:14 +08:00
|
|
|
First, check if you can install SpatiaLite from system packages or binaries.
|
2012-10-20 00:19:17 +08:00
|
|
|
|
2016-01-28 22:16:46 +08:00
|
|
|
For example, on Debian-based distributions, try to install the
|
|
|
|
``spatialite-bin`` package. For distributions that package SpatiaLite 4.2+,
|
|
|
|
install ``libsqlite3-mod-spatialite``.
|
|
|
|
|
2017-04-24 04:06:12 +08:00
|
|
|
For macOS, follow the :ref:`instructions below<spatialite_macos>`.
|
2016-01-28 22:16:46 +08:00
|
|
|
|
|
|
|
For Windows, you may find binaries on the `Gaia-SINS`__ home page.
|
|
|
|
|
|
|
|
In any case, you should always be able to :ref:`install from source
|
|
|
|
<spatialite_source>`.
|
2012-10-20 00:19:17 +08:00
|
|
|
|
|
|
|
__ https://www.gaia-gis.it/fossil/libspatialite
|
2017-03-17 02:01:45 +08:00
|
|
|
__ https://www.gaia-gis.it/gaia-sins/
|
2012-10-20 00:19:17 +08:00
|
|
|
|
2018-02-01 00:14:41 +08:00
|
|
|
.. _spatialite_source:
|
|
|
|
|
2012-10-20 00:19:17 +08:00
|
|
|
Installing from source
|
2016-01-03 18:56:22 +08:00
|
|
|
======================
|
2012-10-20 00:19:17 +08:00
|
|
|
|
2014-11-27 01:46:06 +08:00
|
|
|
:doc:`GEOS and PROJ.4</ref/contrib/gis/install/geolibs>` should be installed
|
|
|
|
prior to building SpatiaLite.
|
2012-10-20 00:19:17 +08:00
|
|
|
|
|
|
|
SQLite
|
2016-01-03 18:56:22 +08:00
|
|
|
------
|
2012-10-20 00:19:17 +08:00
|
|
|
|
|
|
|
Check first if SQLite is compiled with the `R*Tree module`__. Run the sqlite3
|
|
|
|
command line interface and enter the following query::
|
|
|
|
|
|
|
|
sqlite> CREATE VIRTUAL TABLE testrtree USING rtree(id,minX,maxX,minY,maxY);
|
|
|
|
|
|
|
|
If you obtain an error, you will have to recompile SQLite from source. Otherwise,
|
|
|
|
just skip this section.
|
|
|
|
|
|
|
|
To install from sources, download the latest amalgamation source archive from
|
|
|
|
the `SQLite download page`__, and extract::
|
|
|
|
|
2018-06-13 03:22:05 +08:00
|
|
|
$ wget https://www.sqlite.org/YYYY/sqlite-amalgamation-XXX0000.zip
|
|
|
|
$ unzip sqlite-amalgamation-XXX0000.zip
|
|
|
|
$ cd sqlite-amalgamation-XXX0000
|
2012-10-20 00:19:17 +08:00
|
|
|
|
|
|
|
Next, run the ``configure`` script -- however the ``CFLAGS`` environment variable
|
|
|
|
needs to be customized so that SQLite knows to build the R*Tree module::
|
|
|
|
|
|
|
|
$ CFLAGS="-DSQLITE_ENABLE_RTREE=1" ./configure
|
|
|
|
$ make
|
|
|
|
$ sudo make install
|
|
|
|
$ cd ..
|
|
|
|
|
2015-11-30 00:29:46 +08:00
|
|
|
__ https://www.sqlite.org/rtree.html
|
|
|
|
__ https://www.sqlite.org/download.html
|
2012-10-20 00:19:17 +08:00
|
|
|
|
2013-09-13 06:34:22 +08:00
|
|
|
.. _spatialitebuild:
|
2012-10-20 00:19:17 +08:00
|
|
|
|
2015-10-31 03:04:20 +08:00
|
|
|
SpatiaLite library (``libspatialite``)
|
2016-01-03 18:56:22 +08:00
|
|
|
--------------------------------------
|
2012-10-20 00:19:17 +08:00
|
|
|
|
2015-10-31 03:04:20 +08:00
|
|
|
Get the latest SpatiaLite library source bundle from the
|
2012-10-20 00:19:17 +08:00
|
|
|
`download page`__::
|
|
|
|
|
2018-06-13 03:22:05 +08:00
|
|
|
$ wget https://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-X.Y.Z.tar.gz
|
|
|
|
$ tar xaf libspatialite-X.Y.Z.tar.gz
|
|
|
|
$ cd libspatialite-X.Y.Z
|
2015-10-31 03:04:20 +08:00
|
|
|
$ ./configure
|
2012-10-20 00:19:17 +08:00
|
|
|
$ make
|
|
|
|
$ sudo make install
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
2017-04-24 04:06:12 +08:00
|
|
|
For macOS users building from source, the SpatiaLite library *and* tools
|
2012-10-20 00:19:17 +08:00
|
|
|
need to have their ``target`` configured::
|
|
|
|
|
|
|
|
$ ./configure --target=macosx
|
|
|
|
|
2018-09-26 14:48:47 +08:00
|
|
|
__ https://www.gaia-gis.it/gaia-sins/libspatialite-sources/
|
2012-10-20 00:19:17 +08:00
|
|
|
|
2017-04-24 04:06:12 +08:00
|
|
|
.. _spatialite_macos:
|
2012-10-20 00:19:17 +08:00
|
|
|
|
2017-04-24 04:06:12 +08:00
|
|
|
macOS-specific instructions
|
2016-01-03 18:56:22 +08:00
|
|
|
==============================
|
2012-10-20 00:19:17 +08:00
|
|
|
|
2017-04-24 04:06:12 +08:00
|
|
|
To install the SpatiaLite library and tools, macOS users can choose between
|
2014-11-26 11:48:36 +08:00
|
|
|
:ref:`kyngchaos` and `Homebrew`_.
|
|
|
|
|
|
|
|
KyngChaos
|
2016-01-03 18:56:22 +08:00
|
|
|
---------
|
2014-11-26 11:48:36 +08:00
|
|
|
|
|
|
|
First, follow the instructions in the :ref:`kyngchaos` section.
|
2012-10-20 00:19:17 +08:00
|
|
|
|
2016-01-28 22:16:46 +08:00
|
|
|
When creating a SpatiaLite database, the ``spatialite`` program is required.
|
2012-10-20 00:19:17 +08:00
|
|
|
However, instead of attempting to compile the SpatiaLite tools from source,
|
2017-04-24 04:06:12 +08:00
|
|
|
download the `SpatiaLite Binaries`__ for macOS, and install ``spatialite`` in a
|
2012-10-20 00:19:17 +08:00
|
|
|
location available in your ``PATH``. For example::
|
|
|
|
|
2017-03-17 02:01:45 +08:00
|
|
|
$ curl -O https://www.gaia-gis.it/spatialite/spatialite-tools-osx-x86-2.3.1.tar.gz
|
2012-10-20 00:19:17 +08:00
|
|
|
$ tar xzf spatialite-tools-osx-x86-2.3.1.tar.gz
|
|
|
|
$ cd spatialite-tools-osx-x86-2.3.1/bin
|
|
|
|
$ sudo cp spatialite /Library/Frameworks/SQLite3.framework/Programs
|
|
|
|
|
|
|
|
Finally, for GeoDjango to be able to find the KyngChaos SpatiaLite library,
|
2014-08-18 22:30:44 +08:00
|
|
|
add the following to your ``settings.py``::
|
2012-10-20 00:19:17 +08:00
|
|
|
|
|
|
|
SPATIALITE_LIBRARY_PATH='/Library/Frameworks/SQLite3.framework/SQLite3'
|
|
|
|
|
2017-03-17 02:01:45 +08:00
|
|
|
__ https://www.gaia-gis.it/spatialite-2.3.1/binaries.html
|
2012-10-20 00:19:17 +08:00
|
|
|
|
2014-11-26 11:48:36 +08:00
|
|
|
Homebrew
|
2016-01-03 18:56:22 +08:00
|
|
|
--------
|
2014-11-26 11:48:36 +08:00
|
|
|
|
|
|
|
`Homebrew`_ handles all the SpatiaLite related packages on your behalf,
|
2018-12-23 07:11:36 +08:00
|
|
|
including SQLite, SpatiaLite, PROJ, and GEOS. Install them like this::
|
2014-11-26 11:48:36 +08:00
|
|
|
|
|
|
|
$ brew update
|
|
|
|
$ brew install spatialite-tools
|
|
|
|
$ brew install gdal
|
|
|
|
|
|
|
|
Finally, for GeoDjango to be able to find the SpatiaLite library, add the
|
|
|
|
following to your ``settings.py``::
|
|
|
|
|
|
|
|
SPATIALITE_LIBRARY_PATH='/usr/local/lib/mod_spatialite.dylib'
|
|
|
|
|
2017-05-20 23:51:21 +08:00
|
|
|
.. _Homebrew: https://brew.sh/
|