Invalid Polygon Geometry: How to Find It, Fix It and Check You Haven’t Made It Worse
About Author: Puneet, SM Datum
Most GIS users meet invalid geometry by accident. A dissolve fails with a cryptic “TopologyException”. An intersect quietly returns fewer features than expected. A buffer around a parcel layer produces a strange spike. An area total stops matching last month’s figure. The analysis looks broken, but the data is the real problem: one or more polygons break the rules that geometry engines rely on.
This article explains what “invalid” actually means, walks through the six problems that cause most of the trouble, compares the common ways of fixing them, and ends with a short checklist. The checklist will catch the mistake people make most often, which is “fixing” a layer in a way that silently changes its data.
What
makes a polygon valid?
Almost every GIS library you use, including QGIS, GDAL/OGR, PostGIS, Shapely, GeoPandas and many web tools, relies on the GEOS geometry engine or follows the same rules. Those rules come from the OGC Simple Features specification. In plain language, a valid polygon has:
- closed rings: each ring ends where it starts;
- simple rings: a boundary never crosses itself;
- holes inside the shell: every hole lies inside the outer boundary, and holes do not overlap each other;
- a connected interior: rings may touch at a single point, but they must not split the polygon into pieces.
Algorithms such as overlay, union, dissolve and area calculation assume these rules hold. When they don’t, results range from a clean error message to quietly wrong output, and the wrong output is worse.
Six common problems
Figure 1 shows six small test polygons, each with one common defect, together with the message GEOS returns for it through Shapely’s explain_validity() function. QGIS’s Check Validity tool and PostGIS’s ST_IsValidReason() report the same kinds of reasons.

- Self-intersection (“bowtie”). The boundary crosses itself, usually because two vertices were digitised in the wrong order. A naive area calculation on this shape gives zero, because the two lobes cancel each other out.
- Ring self-touch (“figure-8”). The boundary passes through the same point twice. This often happens where a digitiser snapped back to an earlier vertex.
- Hole outside the shell. An inner ring sits outside the outer ring. It is common in data converted between formats that store holes differently.
- Spike. The boundary runs out to a point and comes straight back along the same line. Spikes come from stray clicks and from snapping to a distant vertex.
- Zero-area sliver. All vertices lie on one line, so the “polygon” has no area. Slivers are usually left over from overlay or clipping operations.
- Duplicate consecutive vertex. The same coordinate appears twice in a row. GEOS accepts it as valid, but it inflates vertex counts, upsets some editing tools, and is often flagged by stricter validators and data-quality checks.
One more issue deserves a mention: ring orientation. GeoJSON (RFC 7946) expects outer rings to run counter-clockwise, while the Esri Shapefile specification expects outer rings to run clockwise. Wrong orientation does not make a polygon invalid under OGC rules, and most software is tolerant. Still, it explains why the same file can pass in one tool and be flagged in another.
Finding invalid features
Before fixing anything, count the problems and read the reasons.
- QGIS: Processing Toolbox, then Vector geometry, then Check Validity. It writes separate valid, invalid and error outputs, so you can see exactly which features fail and where.
- PostGIS: SELECT id, ST_IsValidReason(geom) FROM parcels WHERE NOT ST_IsValid(geom);
- Python: gdf[~gdf.is_valid] in GeoPandas, with shapely.validation.explain_validity() for each geometry.
Note the number of invalid features, the total feature count and the total area before you change anything. Those three numbers are your baseline for checking the result.
Fixing: the methods are not equivalent
There are three widely used ways to repair invalid polygons, and they do not give the same result.
buffer(0) is the old trick: buffer each geometry by a distance of zero and let the engine rebuild it. It is quick and still widely recommended, but it can throw data away. Figure 2 shows why. For the bowtie, buffer(0) keeps only one of the two lobes and halves the area from 8 to 4 square units. For the hole outside the shell, it drops the stray ring completely.
make_valid (ST_MakeValid in PostGIS, shapely.make_valid in Python, ogr2ogr -makevalid in GDAL 3.1 and later, and Fix Geometries in QGIS) is designed to keep every vertex and as much area as possible. In the same examples, it splits the bowtie into two triangles and keeps the full 8 square units. It also turns the misplaced hole into a separate small polygon. Newer versions offer a choice between the original linework method and a structure method. The structure method rebuilds polygons from their shell and holes, and it can discard collapsed parts.
Manual editing is still the right answer for a handful of features where the intended shape is not obvious, such as a parcel boundary that crosses a neighbour’s.

The trade-off with make_valid is that the geometry type can change. In our tests with Shapely 2.2 (GEOS 3.14), the results were as follows:
- The bowtie and the misplaced hole both became MultiPolygons.
- The figure-8 and the spike became GeometryCollections: a polygon plus a leftover line segment.
- The zero-area sliver became a MultiLineString, because there was no area left to keep.
That matters as soon as you write the result back out. A shapefile holds only one geometry type per file. Many databases have typed geometry columns. Most analysis tools expect polygons in a polygon layer. A geometry collection in a polygon layer can cause the next tool to fail, or to skip the feature entirely.
So after make_valid, normalise the types:
- Keep only the polygon parts of each result. In PostGIS, use ST_CollectionExtract(geom, 3); in Shapely or GeoPandas, filter the parts to Polygon and MultiPolygon.
- Decide what to do with the rest. Features that collapse to lines or points, such as slivers, usually belong in a separate “rejected” layer for review, not quietly deleted.
- Choose single or multi. Either explode multipolygons into single parts, or promote everything to MultiPolygon, depending on what the destination requires. Exploding changes the feature count, so make sure every part keeps the original attributes and ID.
Verify: the step most people skip
A layer that passes the validity check is not necessarily a correct layer. After repair, compare the result against the baseline you recorded:
- Feature count. Any difference should be fully explained: exploded parts added, collapsed slivers removed. A feature that has disappeared without an explanation is a bug in your workflow.
- Total area. It should be almost unchanged. A drop of several per cent usually means buffer(0) or a similar step discarded parts of polygons.
- Geometry types. Check that only the types you expect remain.
- Validity, again. Run the check a second time. Some repairs, especially after reprojection or coordinate rounding on export, can introduce new problems.
- A visual look. Inspect the features that changed most, especially those whose area or part count changed.

Prevention
Most invalid geometry is created at the start of a workflow, not the end.
- Turn on snapping and topological editing when you digitise.
- Avoid rounding coordinates aggressively on export, since that can make nearly touching rings cross.
- Validate data whenever it changes hands, not only when an analysis fails.
- When converting between formats, keep an eye on ring orientation and on how holes are stored.
Tools
Everything above can be done in QGIS, PostGIS, GDAL or a few lines of Python. For quick checks without a desktop install, browser tools can also help. SM Datum’s free Vector Data Repair tool (https://smdatum.com/tools/data_repair/) accepts zipped shapefiles, GeoJSON, GeoPackage, KML/KMZ and spreadsheets. It reports problems by category before changing anything and lets you choose which repairs to apply. Whichever tool you use, the verification step is the same: compare counts, area and types before and after, and do not accept a “fixed” layer until those numbers make sense.
Figures 1 and 2 were produced by the author with Shapely 2.2.0 (GEOS 3.14.1) from small synthetic test polygons. The results quoted for each method come from those runs.


