[QGIS-Developer] Is PySpatiaLite needed for QGIS v3?

a.furieri at lqt.it a.furieri at lqt.it
Mon Oct 23 23:59:07 PDT 2017


On Mon, 23 Oct 2017 17:02:27 -0500, Germán Carrillo wrote:
> The easy fix for such issue could be to avoid pyspatialite ...
> and use sqlite3 instead, loading the SpatiaLite module ...
> However, loading the SpatiaLite module doesn't seem to be simple
> depending on the Operating System.
> I've attempted to do so on Windows with no success (several
> combinations, giving full path to the module, etc.).
>
> Does anybody know how to load the SpatiaLite module for sqlite3 on
> Windows?
>

Hi Germán,

SQLite has the intrinsic capability to dynamically load at run time
extension modules just by executing an SQL statement like this:

SELECT load_extension('mod_spatialite');

note: the sqlite's Python connector specifically requires to explicitly
grant an authorization for loading dynamic modules:

con.enable_load_extension(True)
con.execute("SELECT load_extension('mod_spatialite')")

it works exactly in the same way on all operating systems: the module
to be loaded will be searched within all directories covered by the
currently set searching rules for binary executable objects.
there is no need at all to explicitly specify a suffix (as e.g. .DLL
or .so or .dylib); sqlite itself will automatically add to the bare
module name ('mod_spatialite' in our case) the specific 
platform-related
suffix.

unhappily the above mentioned searching rules are platform specific;
they are clear and rational on Linux, but they are a nasty chaos on
Windows. you can anyway define your own searching rules for each
processes by appropriately setting %LD_LIBRARY_PATH on Linux or
%PATH% on Windows.
and once %PATH% is correctly set "load_extension" will successfully
work even on Windows, if all required modules (DLLs or shared
libraries or whatever else) are correctly installed.

================

most common pitfalls emerging from several post on the spatialite's
own mailing list:

- badly mixing 32 and 64 bit code: Python 32 bit strictly requires
   32 bit extension modules, exactly as Python 64 bit requires
   64 bit extensions.
- mod_spatialite depends on several further libraries: libgeos,
   libproj, libxml2 etc. if just one of these dependencies remains
   unsatisfied loading mod_spatialite will consequently fail.
- a badly set %PATH% (or badly installed dependencies) always is
   the most  probable failure cause.

bye Sandro


More information about the QGIS-Developer mailing list