I‘ve recently needed a spatial database for storing a large amount of point data. I first thought about PostGIS but was turned off by its Client-Server-Architecture which seemed a too big overhead for my small task. On the other hand, I already had a SQLite database running and was thus familiar with its lightweight approach. Thus I decided to try out SpatiaLite, which, like PostGIS, supports the OpenGIS specifications.
Installing all the latest versions of the SpatiaLite family on Ubuntu 12.04 turned out to be a bit tedious though. As of today, these are SpatiaLite 4.0.0 and SpatiaLite GUI 1.6. I had to compile everything from source and was often thrown back just to learn that I need to install all the *-dev versions of the needed C libraries as well.
There actually are packaged versions of SpatiaLite and SpatiaLite GUI in the package system of Ubuntu, but they are often a version or more behind the actual version.
Therefore this post will give an easy, copy-paste style how-to for compiling SpatiaLite and its GUI with all the dependencies.
SpatiaLite 4
First you need to have all the dev versions of the libraries SpatiaLite depends on:
1 2 3 4 |
sudo apt-get update sudo apt-get install libsqlite3-dev sudo apt-get install libproj-dev sudo apt-get install libgeos-dev |
Although you might not need it, you should install FreeXL since it is definitely needed by the GUI, and I ran into problems when I chose not to install it in the first place.
1 2 3 4 5 6 |
wget http://www.gaia-gis.it/gaia-sins/freexl-sources/freexl-1.0.0g.tar.gz tar -xvzf freexl-1.0.0e.tar.gz cd freexl-1.0.0e/ ./configure make -j8 sudo make install-strip |
Then, to install the main package (maybe you have to add --disable-freexl
after ./configure
if this doesn’t work, it used to work for me, see comments below):
1 2 3 4 5 6 |
wget http://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-4.0.0.tar.gz tar -xvzf libspatialite-4.0.0.tar.gz cd libspatialite-4.0.0/ ./configure --with-geosconfig=/usr/bin/geos-config make -j8 sudo make install-strip |
You should also install the command line utility (similar to the SQLite utility) and other helpful tools. In my case, I didn’t need OSM support, so I disabled it.
1 2 3 4 5 6 |
wget http://www.gaia-gis.it/gaia-sins/spatialite-tools-sources/spatialite-tools-4.0.0.tar.gz tar -xvzf spatialite-tools-4.0.0.tar.gz cd spatialite-tools-4.0.0/ ./configure --disable-readosm make -j8 sudo make install-strip |
In order for everything to work, you need to register the path to the binaries like this: Open up ld.so.conf with a text editor
1 |
sudo vim /etc/ld.so.conf |
and add
1 |
/usr/local/lib |
at the end of that file. After that, refresh:
1 |
sudo ldconfig |
If you don’t want the GUI, you’re done and can invoke the CLI via
1 |
spatialite test.db |
If you want the GUI, follow these steps…
SpatiaLite GUI 1.6
Again, you need to install dev versions of required libraries:
1 2 3 4 5 |
sudo apt-get install libjpeg-dev sudo apt-get install libgeotiff-dev sudo apt-get install libpng-dev sudo apt-get install libcairo2-dev sudo apt-get install libwxgtk2.8-dev |
You really need FreeXL for the GUI, so if you haven’t installed it yet, you might just as well start from scratch. Apart from that, you’ll need libgaiagraphics
1 2 3 4 5 6 |
wget http://www.gaia-gis.it/gaia-sins/libgaiagraphics-0.4b.tar.gz tar -xvzf libgaiagraphics-0.4b.tar.gz cd libgaiagraphics-0.4b/ ./configure make -j8 sudo make install-strip |
Finally, you can install the GUI with
1 2 3 4 5 6 |
wget http://www.gaia-gis.it/gaia-sins/spatialite_gui-1.6.0.tar.gz tar -xvzf spatialite_gui-1.6.0.tar.gz cd spatialite_gui-1.6.0/ ./configure make -j8 sudo make install-strip |
There you go!
Thanks for the help, I got it to work OK. The only problem is Qgis has no support for Spatialite 4.0 yet…
Your welcome. Concerning QGIS, this is not the whole truth. You can actually compile the latest QGIS from source and specify the path to your libspatialite files. With this I could easily connect to 4.0.0 databases in QGIS, but I am not sure whether all functionality works. See this related thread for more information: https://groups.google.com/forum/?fromgroups=#!topic/spatialite-users/vSCXOm9DNOY
a tricks for qgis : you can convert DB 4.0 to 3.0 (supported by qgis stable 1.8) with apposite tool; compile (for linux) package spatialite-tools 4 , and use spatialiteconvert -d db-name.sqlite -v 3 . for windows: http://www.gaia-gis.it/gaia-sins/windows-bin-x86/spatialiteconvert-4.0.0-win-x86.zip
Hi!
Thanks for a great how-to. For spatialite 4.1 + spatialite-gui 1.7.1 one also has to consider wether libxml2 is to be enabled or disabled since ./configure default settings differ: https://groups.google.com/forum/#!msg/spatialite-users/h8bdWISBhIQ/57m9wHfKCVoJ
I posted my own build notes, more or less a copy of your how-to with a few additions, here: http://hydrogeotools.blogspot.se/2013/07/install-spatialite-and-spatialite-gui.html
how do i use the spatialite installation in my java code …which extension do i load for spatialite function
addGeometry() ..(LINUX …..ubuntu )
but normally in windows i tried this and it worked for windows but nt for UBUNTU
stmt.execute(“SELECT load_extension(‘libspatialite.dll’)”);
stmt.execute(“SELECT InitSpatialMetaData()”);
I have no clue how it is with Java. Better ask on stackoverflow.com!
configure: error: ‘expat’ is required but it doesn’t seem to be installed on this system.
Found the packages to load for the expat error, but upon compiling spatialite-tools I see: undefined reference to `load_XL’
Second part
./configure make -j8
should be in two lines:
./configure
make -j8
I got also
“shell.c:2525: undefined reference to `load_XL'”
when compiling spatialite-tools-4.0.0, in command
sudo make install-strip
Thanks for the note, I corrected it. As for the error, I don’t really know what that could be. Haven’t installed it for quite a while. Maybe try on Stackoverflow?
Second part (libspatialite-4.0.0):
–disable-freexl shouldn’t be there. Compilation of spatialite-tools-4.0.0 works when it is removed.
Oh, and forgot to mention: the paths of the zip files are changed, they are currently:
http://www.gaia-gis.it/gaia-sins/freexl-sources/freexl-1.0.0g.tar.gz
http://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-4.0.0.tar.gz
http://www.gaia-gis.it/gaia-sins/spatialite-tools-sources/spatialite-tools-4.0.0.tar.gz
Thanks a lot, I updated the code snippets.
Pingback: Installing on Linux – SpatiaLite Talk