i realize plugins to do this actions without use toolbar: copy features / paste to layer / merge selected features => define attribute to use in merge.

So, all is okay but i don't find "merge selected features" in PyQt action or others like :

qgis.utils.iface. ???

What is good expression to call "merge selected features" enter image description here action / button ?
All of this actions are in advanced digitize toolbar.

  • Try combine geometry of selected features. – DIV Dec 1 '17 at 17:56
  • Combine is one of solution but no attributes selection, just geometry combination. no ? – Gaet Dec 2 '17 at 12:11

NOTE: The whole answer is for QGIS v3.x (currently v2.99).

Copy Features / Paste to layer

These functions are now available in QGIS master (v2.99) and will be included in QGIS v3.0. You can use them from your plugin in this way:

self.iface.copySelectionToClipboard(source_layer) # A prior selection is expected



As of now, merge functionality is not exposed through the QGIS Python bindings. However, you could do one of the following:

  1. Port C++ code to Python. For instance, I've done that partially (except attribute handling) in a new plugin I'm developing. See merge-boundaries function.

  2. Trigger QGIS Merge Selected Features action. Locate the merge selected features action (button) and trigger it:

    iface.mainWindow().findChild(QAction, 'mActionMergeFeatureAttributes').trigger()
  • Good news ! This new functionnality allows to select what attributes use to merge ? – Gaet Dec 2 '17 at 11:51
  • to Trigger QGIS Merge Selected Features action i need to import QAction in my plugin python script. – Gaet Dec 2 '17 at 12:07
  • Do you know why my edit features à not save when à trigger : self.iface.mainWindow().findChild(QAction, 'mActionSaveEdits').trigger() self.iface.mainWindow().findChild(QAction, 'mActionToggleEditing').trigger() – Gaet Dec 4 '17 at 8:45
  • You have methods in iface to access those actions, e.g., actionSaveActiveLayerEdits(), actionSaveAllEdits(), actionSaveEdits(), actionToggleEditing(). Do they work for you? – Germán Carrillo Dec 4 '17 at 14:26
  • i'd already try actionToggleEditing() after trigger actionSaveEdits() and just layer.commitChanges() work... – Gaet Dec 4 '17 at 15:34

Chosen solution :

Trigger QGIS Merge Selected Features action. Locate the merge selected features action (button) and trigger it:

This code need to work with QAction

from PyQt4.QtGui import QAction

self.iface.mainWindow().findChild(QAction, 'mActionMergeFeature').trigger()

To trigger "Merge selected features" from plugin script without click on button.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.