Skip to main content

QGIS: Clip Data

Goal of Clipping

Users will often download a dataset that is larger than the area they need.  This will slow processing time and make the map look cluttered.  For instance, you may download nationwide census tracts, but only need the census tracts in North Carolina.  

To fix this in QGIS, users have 4 options:

  1. Query Builder:  This will not create a new shapefile. Rather, this will limit (outline) the area that you define using a SQL expression.
  2. Spatial Query: This tool will use 2 shapefiles to select features and let you save the selection as a new shapefile.
  3. Clip Tool under the Vector menu: This will create a new shapefile for vector layers.
  4. Clipper Tool under the Raster menu: This will create a new raster.

After running the appropriate tool for your needs, you will get the following results:

Query Builder

  1. Open the Layer Properties of the layer you want to shrink by double-clicking the layer or right-click the layer and select "Properties."
  2. Click on the General tab.
  3. In the lower-right hand corner click on the "Query Builder" button.  
  4. There are 4 areas you will need to be concerned with:
    1. Fields - a list of all the fields/columns in the attribute table
    2. Values - when you click on a field, you can click on All to view all the values in that particular field
    3. Operators. For details, see the w3schools SQL Operators page. (ILIKE is the case insensitive version of LIKE.)
    4. Provider specific filter expression - where the expression is written out   
  5. For this example, I have a shapefile that is nationwide census tracts and I want to query census tracts to North Carolina.  
  6. I want to use the "States FIPS" field since this filed gives a unique number for each state and every census tract has a state FIPS number attached to it (North Carolina's FIPS number is 37).
  7. Write the expression
    1. Double click the STATE_FIPS in the "Fields" box
    2. Click the = button under the Operators box
    3. Click the All button under the Values box and double click "37"
    4. Verify the Expression is "STATE_FIPS" '37' 
  8. Click OK to close the Query Builder and click OK to close the Layer Properties 
  9. You can remove the query by going back to the Query Builder and clearing the expression.

Clipper Tool

If you have raster data, you will need to use the Clipper tool.

  1. Click on the Raster menu, mouse-over Extraction, and click on Clipper...
    1. Verify the raster you want clipped is the Input file
    2. Click "Select..." next to the Output file, find your working folder, and name the output raster.
    3. Click the radio button next to Mask layer and use the drop-down arrow to select the layer you are masking the raster tool.  
    4. Click OK.                                     

Spatial Query

  1. You will need to add the Spatial Query plugin. Go to the Plugins menu at the top of QGIS, and click "Manage and Install Plugins."
  2. Type Spatial Query in the Search box, select Spatial Query, and click Install Plugin at the bottom of the screen.  Also make sure the box next to Spatial Query Plugin is checked.          
  3. Click Vector menu, Spatial Query, and click Spatial Query.
  4. Set the "Select source features from" to the larger dataset (using the same data from above, it will be the census tracts).
  5. Set the "Where the feature" option to "Within." **NOTE: this option changes amongst the different QGIS versions and you should use the one that makes the most sense to you.**
  6. Set the "Reference features of" option to the layer you want the input features to be clipped to (i.e., the "cookie cutter" layer). Using the same data from above, it will be North Carolina.
  7. Click Apply.
  8. Right click the larger layer that has the selected features (i.e. census tracts layer) and click Save As...
  9. You will need to specify an output location under the Save as area.  Under "Encoding you will need to check "Save only selected features."  Click OK.           

Clip Tool

  1. To use the Clip tool, you will need 2 shapefiles. At least in some versions of QGIS, they will need to be in the same projection. For this example, I have nationwide census tracts and a North Carolina state boundary, and I want a layer of just the census tracts in North Carolina. This tool creates a new shapefile whereas the Spatial Query only displays the new information. (With the Spatial Query tool you have not changed the dataset or created a new shapefile, it is only a visual change.)
  2. Click the Vector menu at the top of the QGIS program, mouse-over Geoprocessing Tools, and click Clip...
  3. There are 3 areas to this tool you will need to be concerned with:
    1. Input vector layer: the larger shapefile 
    2. Clip layer: the boundary you want to clip the input layer to.  This will typically be a state, country, etc.
    3. Output shapefile: the folder where you want to save the new shapefile to and the name of the new shapefile
  4. For this example, the input vector layer is the nationwide census tracts, the clip layer is the NC state boundary.                                                                                    
  5. Click OK, and the new shapefile will be added to the map.