I have two tables one containing points (points
) and the other polygons (polygons
). I want to generate a two-columns table identifying for each point of the first table the polygon containing it. So far so good with
SELECT point_id, polygon_id
FROM points LEFT JOIN polygons
ON ST_Contains(polygons.geom, points.geom);
Yet I have a problem with a bunch of points that according to their coordinates are slightly off coast because of rounding of their coordinates. Since their are not in any polygon they fail to be assigned a polygon_id
. I am sure this is a common problem… How to solve this?
- Should I create a buffer area around each polygon before
ST_Contains
? (Problem: My polygons are contiguous, thenST_Contains
will return two matches in border areas, if any point happens to be there) - Should I set up a two-steps query? Buffering areas only after then first attempts match all points with polygons?