SpatiaLite X with QGIS and Python?

222 views
Skip to first unread message

wnstn...@gmail.com

unread,
Feb 9, 2013, 8:24:06 AM2/9/13
to spatiali...@googlegroups.com
As you might have seen from my other post, I've recently installed SpatiaLite 4 on Ubuntu.

It turned out that I should have thought a little more before doing things: The thing I actually want is a fully compliant system between SQLite, SpatiaLite, QGIS and Python.

What I have right now is a SQLite database with a lot of raw data that needs to be processed by Python (needs RegExp and the like) and then imported into a SpatiaLite database. This database
should in turn be connected to QGIS in order to visualize the data. So I need a functioning SpatiaLite adaptor (pyspatialite?) in order to to the migration with a Python script and I need
a functioning connection to SpatiaLite from QGIS. All on Ubuntu.

I don't really care about the latest versions anymore, and I can start from scratch (spend so much time already it doesn't really matter anymore... ;-)
The only thing given is Python 2.7.x and SQLite 3.7.9, I would be happy to retain these versions.

So could someone point me out what versions to install, how to install them, and how to connect everything?
Thanks a lot.

a.fu...@lqt.it

unread,
Feb 9, 2013, 8:57:16 AM2/9/13
to spatiali...@googlegroups.com
> I need a functioning SpatiaLite adaptor (pyspatialite?) in order to
> to
> the migration with a Python script and I need
> a functioning connection to SpatiaLite from QGIS. All on Ubuntu.
>
> I don't really care about the latest versions anymore, and I can
> start
> from scratch (spend so much time already it doesn't really matter
> anymore... ;-)
> The only thing given is Python 2.7.x and SQLite 3.7.9, I would be
> happy to retain these versions.
>

Building QGIS from sources isn't at all difficult on any Linux:
and on Ubuntu is extraordinary easy.

here you can find a really good how-to guide: you simply have to
faithfully execute all reported steps.
http://www.qgis.org/api/INSTALL.html#toc3

expected time: about 1 hour (not so bad, if you consider how huge
is QGIS). after you've successfully built and installed QGIS-trunk
against spatialite-4.0 you'll immediately discover that the updated
qgis-spatialite data-provider will nicely work even when using this
very recent version.

building pyspatialite on the top of spatialite 4.0 isn't at all
difficult; please read this document:
http://www.gaia-gis.it/gaia-sins/spatialite-cookbook/html/python.html

in your specific case, you are obviously expected to manually patch the
setup.py script so to correctly point your build at spatialite-4.0

bye Sandro

--
Il messaggio e' stato analizzato alla ricerca di virus o
contenuti pericolosi da MailScanner, ed e'
risultato non infetto.

wnstn...@gmail.com

unread,
Feb 9, 2013, 9:32:38 AM2/9/13
to spatiali...@googlegroups.com
Alright, thanks, I will try that. But when building QGIS on precise, it is written: apt-get install libspatialite-dev
Doesn't that override my 4.0.0 version? 

If not, where do I tell QGIS to use 4.0 and not some packaged version ("built and installed QGIS-trunk against spatialite-4.0")? 

I am sorry but I am a bit unexperienced when it comes to the Linux build system. 

a.fu...@lqt.it

unread,
Feb 9, 2013, 10:33:40 AM2/9/13
to spatiali...@googlegroups.com
> Alright, thanks, I will try that. But when building QGIS on precise,
> it is written: apt-get install libspatialite-dev
> Doesn't that override my 4.0.0 version?
>

certainly yes; if you want to preserve your own 4.0.0 then you simply
have to skip installing any previous version.


> If not, where do I tell QGIS to use 4.0 and not some packaged version
> ("built and installed QGIS-trunk against spatialite-4.0")?
>

ccmake nicely allows you to manually specify the INCLUDE and LIB
targets for each depending library, so selecting a specific version
between different alternatives isn't at all difficult.

wnstn...@gmail.com

unread,
Feb 9, 2013, 10:56:41 AM2/9/13
to spatiali...@googlegroups.com
Alright, should I turn WITH_INTERNAL_SPATIALITE to ON or OFF, given WITH_SPATIALITE is ON?

wnstn...@gmail.com

unread,
Feb 9, 2013, 10:59:31 AM2/9/13
to spatiali...@googlegroups.com

Guess it should be OFF; right? ;-)

a.fu...@lqt.it

unread,
Feb 9, 2013, 11:01:45 AM2/9/13
to spatiali...@googlegroups.com
> Guess it should be OFF; right? ;-)
>

yes, you are right

wnstn...@gmail.com

unread,
Feb 9, 2013, 11:59:18 AM2/9/13
to spatiali...@googlegroups.com
Unfortunately, when doing "make"; after about 40% I get the following errors which are related to SpatiaLite, the process then exits.
As recommended I set WITH_INTERNAL_SPATIALITE to OFF and
SPATIALITE_INCLUDE_DIR           /usr/local/include/spatialite                                                                                                         
SPATIALITE_LIBRARY               /usr/local/lib/libspatialite.so
WITH_PYSPATIALITE                ON

I know this is not a QGIS support forum.. but I think there is only a little thing I am missing..

//Quantum-GIS/src/providers/spatialite/qgsspatialiteprovider.cpp: In static member function ‘static QgsVectorLayerImport::ImportError QgsSpatiaLiteProvider::createEmptyLayer(const QString&, const QgsFields&, QGis::WkbType, const QgsCoordinateReferenceSystem*, bool, QMap<int, int>*, QString*, const QMap<QString, QVariant>*)’:
//Quantum-GIS/src/providers/spatialite/qgsspatialiteprovider.cpp:131:24: error: ‘spatialite_init’ was not declared in this scope
//Quantum-GIS/src/providers/spatialite/qgsspatialiteprovider.cpp: In constructor ‘QgsSpatiaLiteProvider::QgsSpatiaLiteProvider(const QString&)’:
//Quantum-GIS/src/providers/spatialite/qgsspatialiteprovider.cpp:429:22: error: ‘spatialite_init’ was not declared in this scope
//Quantum-GIS/src/providers/spatialite/qgsspatialiteprovider.cpp:459:66: error: ‘gaiaGetVectorLayersList’ was not declared in this scope
//Quantum-GIS/src/providers/spatialite/qgsspatialiteprovider.cpp:513:38: error: ‘gaiaFreeVectorLayersList’ was not declared in this scope
//Quantum-GIS/src/providers/spatialite/qgsspatialiteprovider.cpp:522:38: error: ‘gaiaFreeVectorLayersList’ was not declared in this scope
//Quantum-GIS/src/providers/spatialite/qgsspatialiteprovider.cpp:527:36: error: ‘gaiaFreeVectorLayersList’ was not declared in this scope
//Quantum-GIS/src/providers/spatialite/qgsspatialiteprovider.cpp: In function ‘bool initializeSpatialMetadata(sqlite3*, QString&)’:
//Quantum-GIS/src/providers/spatialite/qgsspatialiteprovider.cpp:5062:42: error: ‘spatial_ref_sys_init’ was not declared in this scope
//Quantum-GIS/src/providers/spatialite/qgsspatialiteprovider.cpp: In function ‘bool createDb(const QString&, QString&)’:
//Quantum-GIS/src/providers/spatialite/qgsspatialiteprovider.cpp:5078:22: error: ‘spatialite_init’ was not declared in this scope
//Quantum-GIS/src/providers/spatialite/qgsspatialiteprovider.cpp: In function ‘bool deleteLayer(const QString&, const QString&, QString&)’:
//Quantum-GIS/src/providers/spatialite/qgsspatialiteprovider.cpp:5113:22: error: ‘spatialite_init’ was not declared in this scope
//Quantum-GIS/src/providers/spatialite/qgsspatialiteprovider.cpp:5127:72: error: ‘gaiaDropTable’ was not declared in this scope
make[2]: *** [src/providers/spatialite/CMakeFiles/spatialiteprovider.dir/qgsspatialiteprovider.cpp.o] Error 1
make[1]: *** [src/providers/spatialite/CMakeFiles/spatialiteprovider.dir/all] Error 2
make: *** [all] Error 2

wnstn...@gmail.com

unread,
Feb 9, 2013, 12:02:33 PM2/9/13
to spatiali...@googlegroups.com
Ha! Changing SPATIALITE_INCLUDE_DIR  to
/usr/local/include
solved the issue.
 

wnstn...@gmail.com

unread,
Feb 10, 2013, 4:21:12 AM2/10/13
to spatiali...@googlegroups.com
One last question (as I hope). Your installation instructions for pyspatialite are quite clear, I just need to set the SpatiaLite version.
But when I compile QGIS and have WITH_PYSPATIALITE ON, does QGIS automatically set the correct path for me?
Or is it better to turn that feature OFF and install pyspatialite like you explain in your post? Thanks a lot!
Reply all
Reply to author
Forward
0 new messages