Many a time and oft I've spent hours struggling with bizarre bugs resulting from invalid geometries. The symptoms vary greatly, including:

  • Database slowdowns
  • Incorrect\Null query results
  • Log files overloaded with errors and warnings
  • Inconsistent result with geometric operators (e.g. intersection)

I would like to categorize the types of invalid geometries, in order to help everybody here sanitize their data.

Please answer with your favorite type of invalid geometry (one type per answer). Screenshots, descriptions and solutions are welcome - but try to keep your answer short.

3 Answers 3


An 8 year old gold mine of invalid geometries is provided by the PostGIS isvalid regress tests. Many of these regression tests have been moved to GEOS, for example here and here, as well as other pockets in the tests tree. (Sorry, too many to highlight. Pick a few and paste the WKT into JTS Test builder to visualize them.)


Zero-length segments


SELECT geomFromEWKT('LINESTRING(1 1, 1 1)');


Problems: Storing zero length segment can cause bugs when calculating length ratios (division by zero) or when trying to calculate azimuths and trigonometric functions.

Detection: in PostGIS, zero length segments can be detected using isValid().

Solutions: Try to keep zero length segments as points.


Self-Intersecting polygons

enter image description here


SELECT isValid(geomFromEWKT('POLYGON((0 0, 1 1, 1 0, 0 1, 0 0))'));
NOTICE:  Self-intersection at or near point 0.5 0.5
(1 row)

Problems: Wrong calculations, For example, area():

SELECT area(geomFromEWKT('POLYGON((0 0, 1 1, 1 0, 0 1, 0 0))'));
(1 row)

This can cause zero division bugs with calling functions.

Detection: In PostGIS, self intersecting segments can be detected using isValid().

Solution: Conversion to MULTIPOLYGON (see comment).

  • That same shape is equivalent the valid: MULTIPOLYGON(((0 0, 0 1, 0.5 0.5, 0 0)),((1 1, 1 0, 0.5 0.5, 1 1)))
    – Mike T
    Commented Jun 19, 2011 at 6:01
  • @Mike Toews: Correct, converting to MULTIPOLYGON is a good solution.
    – Adam Matan
    Commented Jun 19, 2011 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.