I have two polygons where one should cover the other. They were created in qgis using snapping, however when I checked their topology with postgis it turned out one point on the inner polygon registered as outside the covering polygon. This seems to regularly happen when I create an inner polygon with an edge that lies on an outer polygon.

When I use ST_Equals on the point supposedly outside the polygon and the closest point on the outer polygon it returns true, but when I check whether the polygon and the point are touching it returns false.

Here's the query I'm running:

--CTE with points that are outside the outer polygon (only one in this specific case)
WITH outsidepoints AS (
SELECT dump.geom 
    SELECT geom, 
           ST_Covers((SELECT geom from zone WHERE gid = 403), geom) 
    FROM ST_DumpPoints((SELECT geom from zone WHERE gid = 416))
    ) AS dump 
WHERE st_covers = false

--Check if closest point on outer polygon and "outside" point on inner polygon are equal
--Check if "outside" point touches outer polygon
SELECT ST_Equals(geom, ST_ClosestPoint((SELECT geom from zone WHERE gid = 403), geom)), 
       ST_Touches(geom, (SELECT geom from zone WHERE gid = 403)) 
FROM outsidepoints

The result is T, F

Is this some kind of floating point error? Is there a tolerance parameter I need to set for these calculations?

  • Could you add WKT of the polygon and the point? – user30184 Apr 18 '16 at 5:31

I have tried to create a working example of this problem where the polygons are created from text, but I haven't been successful. After converting the problematic polygons using ST_AsText and then remaking them using ST_GeomFromText, the problem seems to be fixed.

So while it's not exactly efficient, my current solution is to recreate every polygon.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.