Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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.)

share|improve this answer
+1 A true treasure. Thanks! – Adam Matan Jun 19 '11 at 10:35

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.

share|improve this answer

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).

share|improve this answer
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 Jun 19 '11 at 6:01
@Mike Toews: Correct, converting to MULTIPOLYGON is a good solution. – Adam Matan Jun 19 '11 at 7:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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