Anju
Anju

Reputation: 137

Point on a polygon boundary using postgis & geodjango

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

Answers (3)

Grzegorz Grabek
Grzegorz Grabek

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

jpmc26
jpmc26

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

JaakL
JaakL

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

Related Questions