3

Regularly, I have to load layers from SQLite databases through Spatialite in Qgis 3.16 and perform some algorithms. Extension of these SQLite databases is not *.sqlite but another format (proprietary).

My step 1) is to load layers from SQLite database in Qgis through Spatialite. My step 2) is the use of models to perform algorithms on these layers.

I would like to load databases layers directly from models algorithms, thus to avoid this manual step of loading layers with Spatialite.

I tried many ways to reach this goal, and finally circumvented this issue. Inspired from Load lines from .OSM in Processing Modeler, I am now able to load temporary layers with the appropriate CRS from SQLite database into Qgis directly. Here is the scheme of the model:Modele scheme to load layer from SQLite database

Due to the "String concatenation" algorithm, I may not be able to use this model scheme to load layers for some databases (the names of the layers could slightly change). Using the QGIS documentation and Stack Exchange Q&As, I am now able to do some SQL Queries with DB Manager. I think that the use of SQL Queries could solve this issue, also may be easier and faster. However, I did not find an algorithm or a way to execute AND load SQL from a SQLite database, as the algorithm "PostgreSQL execute and load SQL" do for Postgis database.

If I understood it correctly, I also need to find a way to declare in an SQL query:

    1. an Unique ID field name
    1. a Geometry field name

for each layer. Is there a way to do it? Please be clear, I'm still not very comfortable with SQL Queries.

0

I find a better model, which load the original layers in Qgis:

enter image description here

The only limitation I have is that the layer names have to be exactly the same for each SQLite file used.

I considered the questions answered. In the future, the development of an algorithm execute AND load SQL from a SQLite database could be relevant though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.