I have a vector layer in a spatialite DB structured as follows:
In PyQGIS I try to create a derived vector layer from this like
from PyQt4.QtSql import * db = QSqlDatabase.addDatabase('QSPATIALITE') db.setDatabaseName('C:\\tmp\\test.sqlite') db.open() q = QSqlQuery('create table nat2000_hetzles_11 as select * from nat2000_hetzles where maes_2_06 = 11', db) q._exec()
(note that the query is just a simple example, as a matter of fact it might consist of far more complicated conditions, joins, etc.)
The table is created but I'm facing some issues.
GEOMETRY column is empty and QGIS just recognizes the result as a table (not vector layer).
The latter can be fixed by registering the geometry column in
geometry_columns table like
insert into geometry_columns values ('nat2000_hetzles_11', 'geometry', 3, 2, 31468, 0)
GEOMETRY seems to need special treatmant, but I could not figure out what.
How is the
GEOMETRY created in statements like
create my_vec as select * from my_source_vec where...?