Search code examples
postgresqlgeometrypostgis

Is there a function for knowing which percentage of my geometry is included in one other?


I need to know if a geometry is approximately contained in one other. Sometimes, the geomtries I have where badly designed and a very small part of it is outside of the one they are supposed to be in.

ST_Contains cannot return true with these bad geomtries

I'd like to find a POSTGIS function returning the geomtry A contains X% of the geometry B. Example: ST_containing_rate(geometry A, geometry B) returning a percentage

Or a function which will return true if the geometry A contains X% of the geometry B. Example: ST_contains_at_least(geometry A, geomtry B, percentage p) returning true or false


Solution

  • A way of doing it would be:

    ST_Area(ST_Intersection(geometry A, geometry B)) / ST_Area(geom B) > percentage