eyecatch

Intersection in QGIS: Overlaps and Attributes

Published: Last updated:
This article uses QGIS 3.40. The current LTR is 3.44.

What you'll learn


  • How to extract the intersecting parts of vector layers in QGIS
  • Parameter settings for the intersection operation
  • Practical uses of intersection and how to interpret the results

Recommended for


  • Anyone who wants to learn spatial analysis operations
  • Anyone who wants to extract data that overlaps polygon data

Introduction

In GIS data analysis, you often want to extract only the parts where different layers overlap. For example, you may want to calculate the area of forest land that intersects each mesh cell, or find the length of rivers that intersect each municipality. The geoprocessing operation for extracting these “overlapping (intersecting) parts” is Intersection. This article covers Intersection in QGIS, from the basic idea to the steps for running it and how to read the results.

What is intersection?

Intersection is a spatial operation that extracts only the parts where two or more vector layers overlap in space. It looks similar to clipping at first, but the key difference is that the attributes of the output include not only those of the input layer but also those of the overlay layer used for the extraction.

When you run Intersection with a polygon layer (with multiple features) as the overlay layer, the output splits the input data along the boundaries of the polygon features.

This lets you tell “which area of the overlay layer each part overlapped” from the output.

Illustration of the intersection operation
Illustration of the intersection operation

Run an intersection

Running Intersection requires the following two layers:

  • Input layer

    The vector data you want to cut out. Points, lines, and polygons all work as input.

  • Overlay layer

    The data used to determine the intersection. The parts of the input layer that intersect this overlay layer are extracted as the output.

The example below runs Intersection on the railway lines (line data) for all of Japan and the administrative areas (polygon data) of Tokyo, both downloaded from the National Land Numerical Information Download Service.

Data used
Data used

The railway line data downloaded from National Land Numerical Information covers the whole country, so it includes railway lines across all of Japan.

Attribute table of the railway line data. The data covers railway lines nationwide.
Attribute table of the railway line data. The data covers railway lines nationwide.

From the menu bar at the top of the window, choose Vector → Geoprocessing Tools → Intersection.

Choose Vector → Geoprocessing Tools → Intersection from the menu at the top of the window
Choose Vector → Geoprocessing Tools → Intersection from the menu at the top of the window

You can also open the Processing Toolbox on the right side of the main window and search for intersect to start the tool.

You can also start the tool from Processing Toolbox → Vector overlay → Intersection
You can also start the tool from Processing Toolbox → Vector overlay → Intersection

Set the following options for the intersection.

Intersection settings dialog
Intersection settings dialog
  1. Input layer

    Select the vector layer to test for intersection from the drop-down list. The list shows the layers currently loaded in the project.

  2. Overlay layer

    Select the other vector layer for the intersection test. The input layer is cut to the shape of this layer.

  3. Input fields to keep

    Select the attribute fields to carry over from the input layer to the result. If you change nothing, all attributes are carried over.

  4. Overlay fields to keep

    Select the attribute fields to carry over from the overlay layer to the result. If you change nothing, all attributes are carried over.

  5. Advanced Parameters

    • Overlay fields prefix: Adds a prefix to the column names of the attributes that the output layer inherits from the overlay layer.
    • Grid size: If you specify a value, the output layer is snapped to a grid of the specified size.
  6. Intersection

    Specify where to save the result. To keep it as a temporary layer, choose Create Temporary Layer. To save it as a file, click the ... button and specify the location and file name.

Check the intersection result

The railway lines are cut out to the area of Tokyo. The result looks similar to clipping, but the attribute table shows that the output layer has the attributes of both the input layer and the overlay layer.

Intersection result
Intersection result
Attribute table of the intersection result layer
Attribute table of the intersection result layer

The overlay layer this time is polygon data with one feature per municipality in Tokyo. So the output layer also carries the municipality name (the N03_004 column). If you color the features by the municipality name column, you can also see which municipalities each railway line passes through.

Intersection result. Like clipping, it cuts the data to the polygon area and also inherits the attributes of the polygon features, so you can tell which municipality each railway line belongs to.
Intersection result. Like clipping, it cuts the data to the polygon area and also inherits the attributes of the polygon features, so you can tell which municipality each railway line belongs to.

Use cases for intersection

Calculate the area for each individual area

For example, suppose you set up square plots in the target area, as in the image, and want to know how much forest area each plot contains. Run Intersection on the forest area polygons and the grid.

A grid that divides the survey area every 5 km, and forest area polygons
A grid that divides the survey area every 5 km, and forest area polygons

The result is forest area polygons split by grid cell. The attribute table also keeps the grid's id numbers.

The attribute table keeps the id numbers from the grid data
The attribute table keeps the id numbers from the grid data

With the result in this state, calculate the area of each polygon and total the areas by grid ID to get the forest area in each grid cell.

Result of totaling the forest area in each grid cell
Result of totaling the forest area in each grid cell

Extract the shared sections of line data

If you run Intersection on two line layers, you can extract the sections the two lines share. For example, you can use it to detect where buried water and sewer pipes interfere with planned road work.

In this case, the two lines must overlap at the same position. Note that if one line only crosses the other, or if the lines are slightly offset, the sections are not extracted.

Intersection results for each pattern. In the left figure, one line crosses the other, and in this case the intersection extracts nothing. In the right figure, the sections where the two lines match exactly (the red dotted sections) are extracted.
Intersection results for each pattern. In the left figure, one line crosses the other, and in this case the intersection extracts nothing. In the right figure, the sections where the two lines match exactly (the red dotted sections) are extracted.

Conclusion

Intersection is one of the basic and important geoprocessing operations in GIS. With Intersection, you can extract the shared parts of two datasets while keeping the attributes of both. Note, however, that because features are split and the data becomes finer, processing takes longer and the output data is larger than with clipping.

Data sources

About the author
QGIS LAB Editorial Team
QGIS LAB Editorial Team

QGIS LAB is a comprehensive information hub for QGIS, the open-source GIS software. Under the concept of “Geospatial for Greater Good,” we share the knowledge and skills to open up the world through location data.