[Qgis-user] Features geometry/attributes inconsistency ?

Jésahel Benoist djes1975 at gmail.com
Thu May 14 02:12:28 PDT 2020


As it could be useful to some people, here's a little script to copy /
paste selected features from a layer to another.

For a lot of layers, I use at first the MultipleLayerSelection (here's the
3.0 beta : https://github.com/felferrari/MultipleLayerSelection) that
permits to select features from all layers with a rectangle.

Adapts and run this script :
---
def selectedFeaturesCopy(sourceLayerName, destLayerName):

    sourceLYR = QgsProject.instance().mapLayersByName(sourceLayerName)[0]
    destLYR = QgsProject.instance().mapLayersByName(destLayerName)[0]
    destLYR.startEditing()
    # uncomment (remove the #) the following line to delete features in the
destination layer first
    #destLYR.deleteSelectedFeatures()
    iface.copySelectionToClipboard(sourceLYR)
    iface.pasteFromClipboard(destLYR)
    # uncomment the following line to commit your changes automatically.
Personally I prefer to verify first ;)
    #destLYR.commitChanges()

# Create and adapt as much as lines as you have layers to copy
selectedFeaturesCopy('source layer 1', 'destination layer 1')
selectedFeaturesCopy('source layer 2', 'destination layer 2')
---
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20200514/797e5e8d/attachment.html>


More information about the Qgis-user mailing list