Wednesday 19 July 2017

pyqgis - Action: Move pointfeature to other layer - Point becomes Multipoint


I'm trying to write an action that moves a pointfeature from one layer to another. It works fine until i try to save the layer with the new feature on. He says he can't save a MULTIPOINT to a point-layer.



Any idea why it suddenly becomes a Multipoint?


I based this code on the following question: How to create a QGIS action which copies features between layers?


Here is my code:


def getVectorLayerByName( layerName ): 
layerMap = QgsMapLayerRegistry.instance().mapLayers()
for name, layer in layerMap.iteritems():
if layer.type() == QgsMapLayer.VectorLayer and layer.name() == layerName:
if layer.isValid():
return layer
else:

return None

iface = qgis.utils.iface
sourcelayer = getVectorLayerByName('plane')
iface.setActiveLayer(sourcelayer)
sourcelayer.startEditing()
iface.actionCutFeatures().trigger()
sourcelayer.commitChanges()
targetlayer = getVectorLayerByName('dots')
iface.setActiveLayer(targetlayer)

targetlayer.startEditing()
iface.actionPasteFeatures().trigger()
targetlayer.commitChanges()


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...