QGIS Tutorial 2: Exporting part of a vector layer to its own shapefile

In the first walk-through using QGIS v. 2.0.1, we loaded the US Census Bureau’s Tiger/Line Shapefiles for all counties in the US as a vector layer. We then filtered the layer to show the state of Vermont. However, all counties in the US are still  there. If we go back to the Query Builder and clear the STATEFP = 50 query, the vector layer will return, showing the counties for the entire United States. Assuming we want to work with all of the counties in the United States, this is great.

However, my focus is a single state. It is easier to carve out a single state shapefile, save file size space, computer memory and avoid having to deal with multiple queries later in the project.

Saving a smaller subset of the vector layer as a shapefile
  • click on Project | Open (or, Project | Open recent) and load the QGIS project for Vermont
  • in the Layer pane click on the layer file name, tl_2013_us_county, to ensure it is selected/highlighted
  • in the Layer menu, select Save as… (if Save as is grayed out, the layer file name was not selected)

QGIS 02-06b

The Save vector layer as dialog box will appear.

Hopefully, ESRI Shapefile is selected as the Format. If not, click on the drop down box and select this option. Note the entry I typed into the Data Source box. Documenting the source of the original data might prove useful when I need to re-work my map a year or so from now.

Also, click the check box for Add saved file to map.

Once satisfied with the settings, click on the OK button.

QGIS 02-07b

A typical Windows save dialog will launch. Navigate to where you want to save the new shapefile and save it.


Please help…

I am still looking for a way to set a default save or working directory in QGIS…without success. So far in my experience, QGIS does not always go back to the last used location. If you know how to set a default working directory within QGIS, please share in the comments.


If you forget to check the box for Add saved file to map or, for some reason want to wait and add the layer later, the process is the same as with the first walk-through; either:

  • use the Layer | Add Vector Layer, or
  • using Window’s explorer, drag the new shapfile to the map pane

Regardless of the method used, we should now have two layers in our project:

QGIS 02-08b

Notice the the check box for the tl_2013_us_county is selected. Click on the x and turn this layer off. We could just remove the entire US counties layer by clicking on the layer name and then using the Layer | Remove Layers (or, control-d, or by right-clicking on the layer name), but this layer might prove useful later. Turn it off for now.

Let’s take a look at our new shapefile
  • double-click on the smaller Vermont shapefile name in the Layer pane
  • click on Layer | Properties (or, double-click on the shapefile)
  • under General note that Query Builder is now empty

Outside of QGIS, navigate to the saved location via Windows Explorer and take a look a the file size. The new shapefile is much smaller than the original .

As with any project:

  • save  early
  • save often
Please comment

Please share in the comments any thoughts, correction, tips or tricks relating to this walk-through.

Next time: adding county level data to the shapefile

2 thoughts on “QGIS Tutorial 2: Exporting part of a vector layer to its own shapefile

  1. Thanks for explaining this so well – it is certainly not intuitive, and this is the best explanation I’ve found. Did you ever manage to write the next one about adding data to the shapefule?

    • Unfortunately, I had a hard drive crash and haven’t yet mustered enough enthusiasm to rebuild the files for this particular project. I know, I know: backup, backup, backup.

      Regardless, here is a brief summary of my experience adding data to QGis.

      You can either join two databases or use the attribute table to add your own data in a new column. I have found the join feature to be very difficult to use and by the time I go through struggling with making sure both databases are ready to join and then proofing the data (it is easy to screw up and not realize it) that I just enter the data individually in the attribute table. This process works fine for me as I’m not dealing with hundreds or thousands of data points.

      You can get the attribute table in v. 2.4.0-Chugiak by loading your shapefile and then going to Layers | Open Attribute Table. As always, back up your data before you start fooling around with your data files! I’ve found it very easy to really trash my databases in QGis. Keywords/phrases that will get you some good hits on Google include “QGis add data attribute table” and “QGis join tables”. Good luck!

Leave a Reply

Your email address will not be published. Required fields are marked *