Hi,
I'm trying to implement a way to copy the geometry of selected parcels to an
editable layer in a qgs project.
I'm using QGIS 3.4.2.
My code looks like this:
from qgis.PyQt.QtCore import *
from qgis.core import WKB
perceellayer=None
editlayer=None
layers = [layer for layer in QgsProject.instance().mapLayers().values()]
for lyr in layers:
if lyr.name() == "Adpf1836007":
perceellayer = lyr
if lyr.type() == QgsMapLayer.VectorLayer:
cap = lyr.dataProvider().capabilities()
if cap & QgsVectorDataProvider.AddFeatures:
editlayer = lyr
percelen = []
features = perceellayer.selectedFeatures()
geom = None
for f in features:
if geom == None:
geom = f.geometry()
else:
geom = geom.combine(f.geometry())
velden = editlayer.fields()
fpad = editlayer.dataProvider().dataSourceUri()
feat = QgsFeature(velden)
feat.setGeometry(geom)
fout = QgsVectorFileWriter.writeAsVectorFormat(editlayer, fpad, "31370",
WKB.Polygon, "ESRI Shapefile")
if fout == QgsVectorFileWriter.NoError:
print("succes")
print("done")
In this example I try to write to a shapefile, but it fails complaining it
can not import WKB. I would like to write to any kind of Vectorfile
depending of the vectorfile that was set writeable. Any ideas on how to do
this? The cookbook is kind of short concerning writing features.
Regards,
--
Sent from: http://osgeo-org.1560.x6.nabble.com/QGIS-User-f4125267.html
_______________________________________________
Qgis-user mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user