I'm making the transition from GIS to PostGIS and am stuck on this spatial query.

I have background geometry (purple, outlined red) which has an overlay of islands (blue, below); I need the area of only the islands within the red line. In GIS this would be a clip, using the purple shape as my mask.

background purple shape

blue islands

So I query using ST_Within() and obtain the green islands, which is great, but - logically - I'm missing those which are not fully within the mask: st_within result

And I can still find those islands overlapping the boundary of my polygon using ST_Overlap() to find these pink polygons:

st_overlap results in pink overlap polygons

But is there an efficient way to get the area of the islands only within the red outline? This will cut a percentage of the island polygons, I understand, those will be associated with the adjacent background polygon.

  • From which GIS is it that you are transitioning?
    – Vince
    May 2, 2019 at 15:10
  • 5
    You are looking for the ST_Intersection function postgis.net/docs/ST_Intersection.html
    – ziggy
    May 2, 2019 at 15:13
  • Thanks @ziggy! I'd looked at that part of the docs previously, but didn't understand the st_intersection(), st_intersects() relationship as @pdavis clarified below. While it lasts, this link may help others like me who failed at RingTFM: bostongis.com/postgis_intersection_intersects.snippet
    – Jeff
    May 3, 2019 at 8:17

1 Answer 1


This is what you're looking for:

SELECT ST_Intersection(t1.geom, t2.geom)
FROM t1 JOIN t2 ON ST_Intersects(t1.geom, t2.geom)

For more info: https://postgis.net/docs/ST_Intersection.html

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.