[QGIS-Developer] pyqgis: adding features to SQLite layer

Martin Landa landa.martin at gmail.com
Fri Nov 10 09:29:10 PST 2017


Hi,

I found difference when adding features (addFeature) to SQLite layer
in QGIS 2.14 and 2.18.

In QGIS 2.14 ogc_fid (primary key) column in not shown in attribute
table. Feature ID does not need to be set, by adding feature the
ogc_fid sequence is automatically incremented. Everything works, first
feature has ogc_fid set to 0, second to 1, etc.

In QGIS 2.18 ogc_fid column in show in attribute table. Adding feature
is failing on same ogc_fid value, in other words, the ogc_fid value is
not autoincremented. Even feature.setFeatureId() do not help. I solved
it by adding ogc_fid value to the list of values passed to
feature.setAttributes(). Then features are finally added to the layer.

Is it really needed in QGIS 2.18 to add ogc_fid value to attributes? I
would assume that this value is set by feature id or autoincremented.
And I also wonder why setFeatureId() does not work.

Thanks for clarification. Martin

-- 
Martin Landa
http://geo.fsv.cvut.cz/gwiki/Landa
http://gismentors.cz/mentors/landa


More information about the QGIS-Developer mailing list