SpatiaLite 为 SQLite 增加了空间支持,使其成为一个全功能的空间数据库。
首先,检查是否可以从系统包或二进制文件中安装 SpatiaLite。
For example, on Debian-based distributions that package SpatiaLite 4.3+, try to
install the libsqlite3-mod-spatialite
package. For older releases install
spatialite-bin
.
对于 macOS,请按照 下方的说明。
对于 Windows,你可以在 Gaia-SINS 主页上找到二进制文件。
在任何情况下,你都应该能够 从源码安装。
GEOS and PROJ should be installed prior to building SpatiaLite.
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);
如果你获得一个错误,你将不得不从源码重新编译 SQLite。否则,请跳过本节。
To install from sources, download the latest amalgamation source archive from the SQLite download page, and extract:
$ wget https://www.sqlite.org/YYYY/sqlite-amalgamation-XXX0000.zip
$ unzip sqlite-amalgamation-XXX0000.zip
$ cd sqlite-amalgamation-XXX0000
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 ..
libspatialite
)¶Get the latest SpatiaLite library source bundle from the download page:
$ 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
$ ./configure
$ make
$ sudo make install
备注
For macOS users building from source, the SpatiaLite library and tools
need to have their target
configured:
$ ./configure --target=macosx
To install the SpatiaLite library and tools, macOS users can use Homebrew.
Homebrew handles all the SpatiaLite related packages on your behalf, including SQLite, SpatiaLite, PROJ, and GEOS. Install them like this:
$ brew update
$ brew install spatialite-tools
$ brew install gdal
最后,为了让 GeoDjango 能够找到 SpatiaLite 库,在你的 settings.py
中添加以下内容:
SPATIALITE_LIBRARY_PATH = "/usr/local/lib/mod_spatialite.dylib"
12月 05, 2023