Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

3 Answers 3

Zero-length segments

Example:

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

                                    geomfromewkt                                    
------------------------------------------------------------------------------------
 0102000000020000000000000000000840000000000000104000000000000008400000000000001040

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

Example:

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
 isvalid 
---------
 f
(1 row)

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

SELECT area(geomFromEWKT('POLYGON((0 0, 1 1, 1 0, 0 1, 0 0))'));
 area 
------
    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

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

Your Answer

 
discard

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.