eyecatch

How to Fix Invalid Geometry Errors in QGIS

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

What you'll learn


  • Invalid geometries, one cause of Processing tools stopping with an error
  • Typical patterns of invalid geometries (self-intersections, duplicate vertices, and more)
  • Step-by-step instructions for checking and fixing invalid geometries in QGIS

Recommended for


  • Anyone who gets errors when running spatial operations in QGIS
  • Anyone who wants to find and resolve invalid geometries
  • Anyone who wants to improve the quality and reliability of their data

Introduction

When you run a Processing tool such as clip or spatial join in QGIS, processing sometimes stops with an “invalid geometry” error.

This error means there is a problem with the shape of the data. If you leave it as it is, processing keeps failing, other GIS software may not read the data correctly, and the data may draw in unintended ways.

This article explains what an invalid geometry is, when it causes problems, and how to check and fix it in QGIS.

Processing fails to run

Processing tools such as clip and spatial join may stop with a message like Feature (...) has invalid geometry. Please fix the geometry or change the “Invalid features filtering” option for input layers or globally in Processing settings.

For example, the figure below shows the assumed flood inundation area data from the National Land Numerical Information Download Service, together with polygon data for Osaka City only, extracted from the administrative area data.

Administrative area data and assumed flood inundation area data for Osaka City
Administrative area data and assumed flood inundation area data for Osaka City

Run Clip with the flood inundation area data as the Input layer and the Osaka City polygon as the Overlay layer. An error appears as shown below and the processing fails.

Clip result. The processing fails because of invalid geometries
Clip result. The processing fails because of invalid geometries

This happens because the flood inundation area data used as the input layer contains features with problematic geometry.

Invalid geometries like these cause problems such as Processing tools failing to run.

What is an invalid geometry?

In vector data, the shapes of points, lines, and polygons are called “geometry.”

Geometries have shape rules that they must follow to be valid geospatial data. An invalid geometry is a shape that breaks those rules. Typical patterns include the following.

Polygon data

  1. Self-intersection: The boundary of the polygon crosses itself.
  2. Inner ring crosses the outer ring: A hole (inner ring) pokes through the outer boundary.
  3. Zero-area polygon: The polygon has only two vertices, or some or all of its vertices lie on one straight line.
Examples of geometry errors in polygon data. n1, n2, ... show the order of the vertices that make up the polygon
Examples of geometry errors in polygon data. n1, n2, ... show the order of the vertices that make up the polygon

Line data

  1. Zero-length line: The line consists of only a start point and an end point, and both are at the same location.
Example of a geometry error in line data. n1, n2, ... show the order of the vertices that make up the line
Example of a geometry error in line data. n1, n2, ... show the order of the vertices that make up the line

Invalid geometries like these can appear unintentionally while you create or edit data.

Check geometry validity with the Topology Checker

To check for invalid geometries, use the Topology Checker. Right-click the toolbar area and check Topology Checker Panel. The panel appears on the right side of the QGIS window.

Showing the Topology Checker panel
Showing the Topology Checker panel

First, configure the Topology Checker.

  1. Click the Configure button in the Topology Checker panel.
  2. Select the layer to check.
  3. Select the rule to check. To check for geometry errors, select must not have invalid geometries.
  4. Click the + button to add the rule.
  5. Click OK.
Topology Checker settings
Topology Checker settings

Next, run the check.

  1. Click Validate All. QGIS validates the layer against the rules you set.
  2. If QGIS finds errors, it lists the affected features. Click an item to zoom the map to that feature.
  3. Check Show errors on the canvas to highlight the features with errors on the map. This can make individual errors harder to see, so turn it on and off as needed.
Topology Checker results
Topology Checker results

Checking geometry validity and fixing invalid geometries early keeps your data quality high and prevents processing failures caused by data defects.

How to fix invalid geometries

You can fix the features with errors one by one by hand in edit mode, but this takes time when many features have errors. This section shows how to fix the errors automatically.

In the Processing Toolbox, run Vector geometry → Fix geometries.

Running Fix geometries
Running Fix geometries
  1. Input layer: Select the layer whose geometries you want to fix.
  2. Repair method: Choose the method used to repair the geometries. Structure prioritizes the correctness of the topological structure and fixes geometries more strictly. Linework prioritizes the original appearance and fixes geometries more leniently. If you are unsure, start with the default, Structure.
  3. Fixed geometries: Specify where to save the fixed layer.

When the processing finishes, QGIS outputs a layer with the errors fixed.

A layer with the errors fixed is output
A layer with the errors fixed is output

Check the output layer with the Topology Checker in the same way as before. No errors are detected, which shows that the invalid geometries are resolved.

Running the Topology Checker again on the repaired data. No errors were detected.
Running the Topology Checker again on the repaired data. No errors were detected.

Now run Clip again with the repaired data. It failed with an error earlier, but this time the processing runs without problems.

Processing such as Clip runs without problems on the repaired data
Processing such as Clip runs without problems on the repaired data

Ignore features with invalid geometries and continue processing

Instead of repairing the geometries, you can also ignore the features with invalid geometries and continue processing. However, this method excludes the features with invalid geometries from the output, so use it with care.

From the menu bar, choose Settings → Options, then select the Processing tab on the left. Open Providers → General and change Invalid features filtering to Skip (ignore) features with invalid geometries.

With this setting, Processing skips features with invalid geometries and continues.

Steps for ignoring features with invalid geometries in the Options dialog
Steps for ignoring features with invalid geometries in the Options dialog

Conclusion

Invalid geometries can appear while you create or edit data. If you leave them as they are, Processing tools fail to run and other systems cannot read the data correctly.

So before an important analysis, before delivering data, or before exporting data for another system, run a topology check to make sure there are no problems.

If you find errors, deal with them using Fix geometries or the geometry editing tools.

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.