Skip to main content
edited title
Link
Taras
  • 34k
  • 4
  • 73
  • 148

Creating temporaytemporary layer out of selection in QGIS

added 5 characters in body; edited tags; edited title
Source Link
Taras
  • 34k
  • 4
  • 73
  • 148

Creating a temporay layer out of a selection in QGIS

I want to create a temporytemporary 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 pyqgisPyQGIS 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)
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)

Creating a temporay layer out of a selection in QGIS

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)

Creating temporay layer out of selection in QGIS

I want to create a temporary 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.

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)
corrected my pyqgis example
Source Link
LaughU
  • 4.2k
  • 5
  • 23
  • 42

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 filenew 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(featuresfeat)

selection.commitChanges()
selection.updateExtents()

QgsMapLayerRegistry.instance().addMapLayer(selection)

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(features)

selection.commitChanges()
selection.updateExtents()

QgsMapLayerRegistry.instance().addMapLayer(selection)

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)
Tweeted twitter.com/StackGIS/status/926247201650638853
Source Link
LaughU
  • 4.2k
  • 5
  • 23
  • 42
Loading