Assuming that I have a point on a map and a multipolygon on a map. When I query with ST_Intersects or ST_Within I get the same result. I want to know what is different between these two methods?


PostGIS is well documented. Doing some research gives you following results.

For points, there is no difference. When it is inside the polygon, it also shares a portion.

On the other hand, when you do the same with lines. A line that is not entirely within the polygon will not be selected with st_within.

  • 4
    There is a difference for points. If a point is on the polygon edge (ex: a polygon vertex), the point and the polygons intersect each other but the point is not within the polygon – JGH Dec 16 '19 at 16:00
  • @PieterB thank you for response. But what about performance? When you have point and the result is same, which one has better performance? intersects or within? – Saber Solooki Dec 16 '19 at 17:23
  • @SaberSolooki Both ST_Within and ST_Intersects make use of bounding boxes and spatial indexes. As long as your geometries and spatial indices are setup correctly, there should be little performance difference. Choose the method that provides more accurate results based on JGH's comment. – Nate Wanner Aug 28 '20 at 15:59
  • so which one should we use st_intersects or st_within? – Always Sunny Jan 27 at 6:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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