I am using the following PostGIS functions in a Postgres query:
ST_AsGeoJSON(ST_Intersection(p.geom,c.geom))
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?
ST_Makevalid()
so you might want to just exclude invalid input withST_IsValid()
.Ring Self-intersection[...]
for validity reason.ST_IsValidDetail
called on affected geoms.ST_Buffer(ST_Buffer(geom, -0.001), 0.001)
which fills small slivers.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.