I have a table containing point
CREATE TABLE Points
{
pointID BIGSERIAL PRIMARY KEY NOT NULL,
thePoint GEOGRAPHY(POINT)
}
CREATE TABLE Polygons
{
polygonID BIGSERIAL PRIMARY KEY NOT NULL,
aPolygon GEOGRAPHY(POLYGON) NOT NULL,
}
I wish to find all the points that are contained in each polygon. i.e the result should look like
polygonID| pointID
-------------------
1 | 1
1 | 2
1 | 5
1 | 7
2 | 2
2 | 3
...
I managed to go point by point and to figure out if it's in the polygon using ST_CoveredBy(thePoint, aPolygon)
. Based on that the naive solution is going in a nested loop over all points and polygons but for sure there is a more efficient and correct way to achieve this.