Hi Bas,
there is any real reason suggesting that pyspatialite is any
longer useful and required ?
few objective facts:
- pyspatialite simply was a clone derived from pysqlite, that
just added of its own two or three lines of C code intended
to initialize and register spatialite as an extension to
sqlite.
- pyspatialite was supported by an awful build script strictly
depending from a specific version of spatialite, that nowadays
is cold dead by many years (the build script contained an
hardwired URL directly pointing to a very specific tarball:
changing this URL was unsupported and required some clumsy
patch to be manually applied.
- the "capital sin": pyspatialite statically linked a private
copy of spatialite instead of dynamically linking the
system-wide spatialite's shared libraries.
this odd design choice caused many severe troubles in past
years to QGIS, that could inadvertently trigger internal
version conflicts when complex operations were based both
on C++ core modules (using the system-wide shared libraries)
and on Python plugins (using the private internal static code).
the most astonishing fact: pyspatialite is completely useless.
since many years SQLite has the intrinsic capability to dynamically
load any possible extension, obviously including SpatiaLite.
You are just required to execute this "special" SQL command
immediately after establishing a new DB connection:
SELECT load_extension('mod_spatialite');
note: dynamically loading 'mod_spatialite' at run time will
have the further positive effect to automatically ensure
that the system-wide shared libraries will be loaded, thus
making impossible any version conflict between C++ modules
and Python plugins.
the following code snippet exemplifies how to correctly
load and initialize SpatiaLite on Python just depending
on the standard sqlite3 connector and completely avoiding
to call pyspatialite (tested on Debian 8)
---------------------
import sqlite3
conn = sqlite3.connect(':memory:)
conn.enable_load_extension(True)
conn.execute("SELECT load_extension('mod_spatialite')")
# just a stupid test to check if SpatiaLite really works
for row in conn.execute("SELECT ST_AsText(MakePoint(11.5, 42.5,
4326))"):
print row
---------------------
bye Sandro