Reputation: 137
I have point data and multipolygon data in tables. How can I find points lying on multipolygon boundary using postgis and in geodjango?
Upvotes: 1
Views: 1002
Reputation: 980
Use ST_Covers it contains own boundary. But be careful in that case one point can be included by many (multi)polygons.
SELECT ST_Covers(ST_GeomFromText('POLYGON((1 1,0 0, -1 1, 1 1))'),
ST_GeomFromText(points.g))
FROM UNNEST(ARRAY['POINT(1 1)', 'POINT(0 1)', 'POINT(0 0.5)']) points (g)
Upvotes: 0
Reputation: 29866
I can't help you with geodjango, but I can give you a PostGIS query.
SELECT ST_Contains(ST_Boundary(ST_GeomFromText('POLYGON((1 1,0 0, -1 1, 1 1))')),
ST_GeomFromText(points.g))
FROM UNNEST(ARRAY['POINT(1 1)', 'POINT(0 1)']) points (g)
The key is to use ST_Boundary
to get the polygon's boundary and check if that contains the point.
Upvotes: 1
Reputation: 4295
You can just use PostGIS SQL I guess:
SELECT points,area from points_table,area WHERE
area_geometry && points
AND ST_Contains(area_geometry,points)
Upvotes: 0