Ich habe diesen Code ausprobiert:
Code: Select all
dbPfad = "C:\QGis\MyDb.sqlite"
layerObjekte = QgsVectorLayer(f"dbname='{dbPfad}' table='objekte' (geometry) sql=", "layerObjekte", "spatialite")
layerObjekte.startEditing()
if not layerObjekte.isEditable():
return
points = [QgsPointXY(100 , 100),
QgsPointXY(200, 100),
QgsPointXY(200, 200),
QgsPointXY(100, 200),
QgsPointXY(100, 100)]
square_geom = QgsGeometry.fromPolygonXY([points])
new_feature = QgsFeature()
new_feature.setFields(layerObjekte.fields(), True)
new_feature.setGeometry(square_geom)
if not new_feature.geometry().isGeosValid():
return
# The table also has an attribute "id" (autoincrement).
# I was hinted not to set this attribute.
#new_feature.setAttribute("id", 999)
new_feature.setAttribute("lfdnr", 1)
new_feature.setAttribute("status", 0)
if not new_feature.isValid():
return
success = layerObjekte.addFeature(new_feature)
layerObjekte.commitChanges()
Datenanbieterfehler
SQLite-Fehler:unbekannte Ursache
INSERT INTO "objekte"("geometry","lfdnr","status") VALUES
(ST_Multi(GeomFromWKB(?, 25832)),?,?,?)
Übersetzt ins Englische:
Datenproviderfehler
SQLite-Fehler: unbekannte Ursache
INSERT...
Irgendwelche Ideen?
Mobile version