I am using the following PostGIS functions in a Postgres query:


Where p.geom & c.geom are type multipolygon. The query works most of the time but with some layers I recieve the following error:

ERROR: Error performing intersection: TopologyException: Input geom 0 
is invalid: Ring Self-intersection at or near point... 

I tried applying ST_Makevalid() on the individual geometries in the ST_Intersection call but it doesn't seem to resolve the issue.

I also tried adding where conditions using ST_IsValid() on both table geometries and the intersection of the two. I can get the query working when I add where ST_IsValid(p.geom) but it excludes a large number of the features I'm trying to display in the application.

After running ST_IsValidReason(p.geom) I can see that several of the results have Ring Self-intersection[{long} {lat}].

How can I resolve this?

  • Can you provide a sample of the data that is causing it? It is very possible that ST_Makevalid() so you might want to just exclude invalid input with ST_IsValid().
    – RoperMaps
    May 4, 2018 at 22:28
  • @RoperMaps Unfortunately it would be difficult to provide the data since I'd have to share the entire tables. See edit, the offending geometry returns Ring Self-intersection[...] for validity reason.
    – Don
    May 5, 2018 at 0:25
  • 1
    Well you have to clean your input somehow. Can you post a representative sample of the output of ST_IsValidDetail called on affected geoms.
    – RoperMaps
    May 5, 2018 at 0:26
  • 2
    I think ST_MakeValid does this, but I assume you've tried a zero buffer? You can also do ST_Buffer(ST_Buffer(geom, -0.001), 0.001) which fills small slivers.
    – RoperMaps
    May 5, 2018 at 0:26
  • @RoperMaps so I updated the invalid geometry in the table using set geom = ST_MakeValid(geom) and now its working. If you'd like to post your suggestion as an answer, that's what worked for me.
    – Don
    May 5, 2018 at 0:30

1 Answer 1


The input of st_intersection needs to be cleaned.

You can check whether geometries are clean by using:

WHERE ST_IsValid(mySuspectTable.geom)

You can try and fix these with:

set geom = ST_MakeValid(geom)

You can also use:

ST_Buffer(ST_Buffer(geom, -0.001), 0.001)

To remove slivers.

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.