10

I want to create a tempory layer out of an existing layer and only get those features from the existing layer, which are selected. I know that ArcGIS has this functionality that you can create a layer from selected features.

However, I could not find any working solution for this in QGIS. I am aware of this question which describes, how to save a selection into a new file which is not my goal here.

Checking the context menu for "save as..." did not yield any results. In the plugin section with the search word "selection" did not give any meaningful results either.

While trying around I came up with a solution with pyqgis but I would prefer one which does not involve any coding because I need to show this to a colleague.

*pyqgis way:

layer = iface.activeLayer() # layer which has a selection 
feat = layer.selectedFeatures()
fields = layer.fields()

selection = QgsVectorLayer('Point', 'temp', 'memory')

dp = selection.dataProvider()
dp.addAttributes(fields)
dp.addFeatures(feat)

selection.commitChanges()
selection.updateExtents()

QgsMapLayerRegistry.instance().addMapLayer(selection)
15

I think there's atleast two methods:

  • Select your features and run the Save selected features tool from the Processing Toolbox.

  • As described in this answer to a related question:

    1. Select your features
    2. Copy them with either Ctrl + C or from the menubar (Edit > Copy Features)
    3. Paste the features as a temporary scratch layer (Edit > Paste Features as > Temporary Scratch Layer).
  • @LaughU - Most welcome! Glad it helped :) – Joseph Nov 2 '17 at 10:25

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.