[GIS] QGIS spatialite layers ‘Could not commit changes to layer’

qgisspatialite

I am running into problems with saving spatialite layers in QGIS 2.18. To illustrate I am following this tutorial:

http://www.qgistutorials.com/en/docs/digitizing_basics.html

Creating a new spatialite layer works, and a new file is written, and I can set up a point, line or polygon layer within the db. But when any data is added (digtitzed) within the db (in this case to the 'road' layer, QGIS fails with the error:

Could not commit changes to layer roads

Errors: ERROR: 1 feature(s) not added.

  Provider errors:
      SQLite error: roads.geometry violates Geometry constraint [geom-type or SRID not allowed]
    SQL: INSERT INTO "roads"("geometry","pkuid","name","class") VALUES (GeomFromWKB(?, 4326),?,?,?)

It is then not possible to save the layer and the project closed without saving changes.
If a layer is successfully created it has a habit of becoming invisible after a random but short period of time and cannot be located. Changing symbology, zooming to layer or selecting the area know to contain the data will fail to find the point, line or polygon.

Deleting .qgis2 folder has no affect.

Problem affects QGIS 2.18.9 in Linux (Xubuntu 16.04, 64-bit)
Problem is not present in QGIS 2.14.15 in Windows (Windows 7 Ult, 64-bit)

Is there a known solution or workaround?


No, not root of the problem, or I am not following you argument. Taking your suggestion verbatim produces the same error:

Could not commit changes to layer roads

Errors: ERROR: 1 feature(s) not added.

  Provider errors:
      SQLite error: roads.linestring violates Geometry constraint [geom-type or SRID not allowed]
    SQL: INSERT INTO "roads"("linestring","pkuid","name","class") VALUES (GeomFromWKB(?, 2193),?,?,?)

And as I originally posted, this exercise works with the 'ambiguous' geometry entry in 2.14. The problem continues to occur in other geometries too (polygons, points) whatever name is given to the geometry column.

Best Answer

The issue is that your geometry column is of type 'Geometry' which is ambiguous to qgis. You need to change your dataset to be of a distinct geometry type, e.g. 'Linestring' for roads

Related Question