Invalid geometries can cause a lot of headache: from missing features to odd analysis results.
This post aims to illustrate one of the most common issues and presents an approach that can help with these errors.
The dataset used for this example is the Alaska Shapefile from the QGIS sample data:
This dataset has a couple of issues. One way to find out if a dataset contains errors is the Check Validity tool in the Processing toolbox:
If there are errors, a layer called Error output will be loaded. In our case, there are multiple issues:
If we try to use this dataset for spatial analysis, there will likely be errors. For example, using the Fixed distance buffer tool results in missing features:
Note the errors in the Processing log message panel:
Feature ### has invalid geometry. Skipping ...
So what can we do?
In my experience, GRASS can work wonders for fixing these kind of issues. The idea is to run v.buffer.distance with the distance set to zero:
This will import the dataset into GRASS and run the buffer algorithm without actually growing the polygons. Finally, it should export a fixed version of the geometries:
A quick validity check with the Check validity tool confirms that there are no issues left.