I have points geom in gid,pt_geom and polygon geom in gid,pl_geom. Some of the points are inside polygon and some are outside polygon, others are on the polygon boundary.

enter image description here

Is there any way to identify those points on the polygon by using PostGIS functions (e.g. ST_contains() or ST_Distance())?

Maybe Select points.gid from points inner join polygon on st_contains(polygon.the_geom,points.the_geom).

  • So you only want the ones touching the border?
    – Nathan W
    Oct 30, 2013 at 3:19
  • Yes, I tried to use st_touches but it gives me false when i applied it on the points touching the polygon border.
    – Xianlin
    Oct 30, 2013 at 4:13
  • Some of my points are not on the vertex of the polygon so the ST_Touches() is not working for those points.
    – Xianlin
    Oct 30, 2013 at 4:40
  • 2
    ST_Touches also returns true if points are on the boundaryand not just on a vertex. This is proved by: "SELECT ST_Touches('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))'::geometry, 'POINT(0 0.5)'::geometry);". If ST_Touches returns false above, the points are very close to but not exactly on the boundary. If you manually digitized the example, points are infinitely small and boundaries infinitely narrow, so the likelihood of actually getting a point on the boundary is very low. If you believe the points really are directly on the boundary, your negative result could possibly be due to a rounding error. Oct 30, 2013 at 8:58
  • For any really-world example using fractions a point intersects line test- which is really what you are doing- is likely to fail due to use of floating point math. Convert the polygon boundary to a LINESTRING and use STDistance against that with a suitable buffer (a few centimeters converted to whatever units should do it). Oct 30, 2013 at 13:09

1 Answer 1

Select points.gid 
from points inner join polygon 
on st_dwithin(st_exteriorring(polygon.the_geom),points.the_geom,0.001)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.