[Qgis-user] How to define generic VectorFileWriter
Reginald
Reginald.Carlier at ingelmunster.be
Fri Dec 21 05:35:00 PST 2018
Hi,
For those who are interrested in the result I post this script:
////////////////////////////////////////////
#script uses selected features of parcellayer as geometry for editable other
vector layer
#make sure there is only one layer editable, otherwise only the first
occuring layer will be used
from qgis.PyQt.QtCore import *
from qgis.core import QgsWkbTypes
perceellayer=None
editlayer=None
layers = [layer for layer in QgsProject.instance().mapLayers().values()]
for lyr in layers:
if lyr.name() == "parcels":
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()
#perc = f["primarynum"] + f["bisnumber"] + f["expletter"] +
f["expnum"]
else:
geom = geom.combine(f.geometry())
velden = editlayer.fields()
prov = editlayer.dataProvider()
feat = QgsFeature(velden)
feat.setGeometry(geom)
iface.openFeatureForm(editlayer,feat,updateFeatureOnly=True)
(res, outFeats) = editlayer.dataProvider().addFeatures([feat])
print("done")
///////////////////////////////////////
Regards,
--
Sent from: http://osgeo-org.1560.x6.nabble.com/QGIS-User-f4125267.html
More information about the Qgis-user
mailing list