43

Is it possible to create layers from selection in QGIS? I am using QGIS 1.7.4-Wroclaw.

To make it easier for others to see this, here are some pics. I used QGIS 2.0.1-Dufour.

Selecting
enter image description here

Saving
enter image description here

Adding
enter image description here

Taras
  • 32,823
  • 4
  • 66
  • 137
Stat-R
  • 927
  • 3
  • 10
  • 18

7 Answers7

32

After making a selection in a layer, right click on it and choose save selection as.


Update for QGIS 3.2 Bonn as of 2018

As this is the accepted answer and the way of doing this has evolved somewhat, beginners might find this answer incomplete, so:

After making a selection in a layer, right click on it and choose "Export" > "Save Selected Feature As..."

menu selection

which is actually just a nice redundancy, because it takes you to the same mask as clicking "Save Feature As...", but it already checks the box "Save only selected features"

Save Vector Layer As Mask

thymaro
  • 505
  • 3
  • 17
John
  • 1,799
  • 15
  • 12
  • 3
    Note that you can make a selection using the 'select' tool, but also can run queries directly on a layer with a right-click and selecting "Query..." and then construct a search (which will then hide items that don't match). "Save as" will then save just the displayed features. – Simbamangu May 25 '12 at 15:09
  • Using can be much quicker if you have lots of features that are spread out over the map. Saves selecting them one at a time, or using the inbuilt search. – Nathan W May 26 '12 at 02:35
  • @johns that isn't the same as making a layer on a selection ... what you've described is saving a new shapefile entirely... – DPSSpatial_BoycottingGISSE Jan 24 '14 at 16:24
  • Thank you for updating the answer, made things much simpler to find :) – JeopardyTempest Nov 10 '21 at 14:39
20

A new feature just came up in QGIS 2.2 called "Paste as new vector layer":

It is a common activity in a GIS to create a sub-selection and then to create a new layer from the selection. In QGIS you can already do save selection as to save a layer from your selection, and now offers functionality that allows you to create a new file or memory layer from whatever is in your clipboard. Simply select some features, copy them to your clipboard and then do Edit -> Paste features as and choose either New vector layer or New memory layer from the submenu. The best part of this new feature is that if you have some Well Known Text (WKT) features in your clipboard from another app, you can simply paste them into QGIS as a new layer now.

DPSSpatial_BoycottingGISSE
  • 18,790
  • 4
  • 66
  • 110
  • 1
    New memory layer is the trick – geotheory Jun 17 '14 at 16:40
  • That is a great tool - thanks for sharing, very helpful! – Kristina Dec 03 '14 at 18:53
  • 1
    Sadly, it has some unlisted limits - i.e., it works if I select, say, 100 points from a vector layer but if I select some 20000 points then copying to clipboard fails silently. – Peteris Feb 23 '16 at 19:40
  • 1
    Which is the difference between "new vector layer" and "new memory vector layer"? – Andreu Amoros Oct 05 '16 at 09:25
  • 2
    When you copy a selected feature and paste as a new vector layer, it will open the 'save layer as' dialogue box and save as a new shapefile. New Memory Vector layer only persists in the QGIS document (and will persist when you open it next time if you have the memory layer saver plugin installed) @AndreuAmoros – DPSSpatial_BoycottingGISSE Oct 05 '16 at 14:11
  • For anyone else as confused as I was that "Paste as new layer" opens a dialog asking you questions you don't have the answers to - the correct option paste the selection to a new layer* is given the utterly baffling name "Paste as > Temporary scratch layer" in my version of QGIS. "Paste as layer" actually means what everyone else in this quadrant of the galaxy would call "Save selection to new file". – Jack M Jan 02 '21 at 20:01
12

In QGIS 2.6.2 Brighton, you can do the following:

  1. Select features
  2. Right click on the layer
  3. Save as...
  4. Select the option "Save only selected objects"
  5. Save

That should do

raulds77
  • 121
  • 1
  • 2
  • 5
    The "save selection as..." feature has been deprecated in favor of this new method - so this answer is now the correct way to save selected features to a new layer. – SaultDon Feb 16 '15 at 18:07
  • This also works for 2.8 Wien – Freeze Apr 15 '15 at 10:52
6

Or right-click on the layer, choose "Query", and write a SQL construct. This is analagous to creating a "Definition Query" in ArcGIS if you do not want to write a new shapefile to disk.

RyanKDalton
  • 23,068
  • 17
  • 110
  • 178
  • 1
    that still isn't the same as the arcgis 'save selection as layer' concept... If you do an ArcMap query or set of queries and end up with a selected set, how would you replicate that in a new layer based on a "query" in QGIS? I just don't think the same ability is in QGIS as in ArcMap - not saying it should be...just saying its not there. – DPSSpatial_BoycottingGISSE Jan 24 '14 at 16:27
  • An update for anyone who comes across this and finds this answer helpful, as I did. In QGIS 2.2, right-click on a layer and choose "Filter" and write a SQL statement. – Barbarossa Dec 17 '14 at 23:39
1

I actually miss the older version's option to Save selection as new layer. I'm using QGIS 2.6.0 Brighton and using Edit > Paste options as just doesn't work. One attempted workaround was to create a new layer, then paste features into that layer, however this does not appear to have copied any attribute data for me.

Therefore my solution has been to:

  1. Copy desired layer.
  2. Make my selection.
  3. Open attribute table.
  4. Invert selection.
  5. Delete unwanted features.
  6. Save.
Gonja
  • 497
  • 4
  • 12
0

I'm using QGIS 2.10.1-Pisa. To save selected features with PyQGIS, you can try the following:

import processing
##Once selection has been done
#Layer which contains selected features
layer= iface.activeLayer()
#Specify where you want to save your new file (in my case)
result='C:\Users\Desktop\Test\selected.shp'
#Using geoprocessing alg "Save selected features"
processing.runalg('qgis:saveselectedfeatures', layer, result)
#Add saved file to map
processing.load(result)

Reference: https://docs.qgis.org/2.8/en/docs/user_manual/processing_algs/qgis/vector_general_tools/saveselectedfeatures.html

Mauro_cL
  • 41
  • 5
0

In QGIS 2.18.17, make the selection using either a filter or manual selection then right-click on the layer in the Layer Panel, then select 'Save As'. As you only want to save the selection select the tick-box for selection only.