Quantcast
Channel: Question and Answer » postgresql
Viewing all articles
Browse latest Browse all 1138

Capturing points slightly out at sea

$
0
0

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?

  1. Should I create a buffer area around each polygon before ST_Contains? (Problem: My polygons are contiguous, then ST_Contains will return two matches in border areas, if any point happens to be there)
  2. Should I set up a two-steps query? Buffering areas only after then first attempts match all points with polygons?

Viewing all articles
Browse latest Browse all 1138

Trending Articles