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

Are there strategies for dealing with TopologyException errors in PostGIS 2? Nearly every function I run against two geometries results in a TopologyException (e.g. ST_Intersection, ST_SymDifference).

I always try ST_Buffer(the_geom, 0) first, then ST_MakeValid(), then (ST_Dump(the_geom).geom and repeat ST_Buffer. Sometimes a combination of one or more fixes it, sometimes not.

Perhaps my data is just not clean enough for PostGIS 2? I feel like I rarely had this issue on Postgres 9.0 with PostGIS 1.5, but now it is almost every dataset.

share|improve this question

As you suspect, this is from invalid geometries.

First, find them and identify the issue, e.g.:

SELECT gid, geom, ST_IsValidReason(geom)
FROM my_table
WHERE NOT ST_IsValid(geom);

Do this for each geometry column/table, and fix the geometries (this might be another question). Use QGIS or some tool to get a visual of the geometry to see what is going on.

Once you have them cleaned up, keep them valid with a check constraint:

ALTER TABLE my_table
  ADD CONSTRAINT enforce_valid_geom CHECK (ST_IsValid(geom));
share|improve this answer
I'm able to correct the input geometries and get PostGIS to believe they are valid (WHERE NOT ST_IsValid(geom) returns 0), but most often running ST_Intersection or similar still errors with a TopologyException. – Dylan Hettinger Apr 29 '13 at 16:14
@DylanHettinger It is possible that this is a bug, however it is difficult to isolate the offending geometry(ies). If you can, post the WKT/WKB in your question. – Mike T Apr 29 '13 at 19:59

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.