4

I'm trying to write a PostGIS query to do the following:

enter image description here

  1. Get polygons from a table that overlap geometry A above (in this case, B and C).
  2. Get the intersecting area.
  3. Split the intersecting area by the overlapping polygons (in this case, returning D and E).

In this case there are 2 overlapping polygons, but I need to support an arbitrary number.

I'm stuck on how to get started with this. I know I can use ST_Intersects to get the intersecting polygons and ST_Intersection to get the overlapping area, but I'm not sure the splitting will work. It looks like ST_Split only accepts two geometries Can anyone think of how I could get this to work with n polygons?

3
  • 2
    Why is the question off-topic ? Please comment when close-voting.
    – pLumo
    Mar 6, 2018 at 16:26
  • 1
    still on hold? what's unclear about this?
    – geozelot
    Mar 6, 2018 at 18:33
  • 1
    Who knows. A couple of the close votes come from people with a bit of a robo-review reputation, so hardly surprising. The question is extremely straightforward, but not unclear. Mar 6, 2018 at 20:18

1 Answer 1

4

If Table a holds your polygon "A" and Table b holds your Polygons "B" and "C", the following should return the two records with polygons "D" and "E":

SELECT ST_Intersection(a.geom,b.geom)
FROM a JOIN b
ON ST_Intersects(a.geom, b.geom);

If you want to receive only a single (multi-)polygon per a.fid, you can add st_union and group by a.fid:

SELECT ST_Union(ST_Intersection(a.geom,b.geom))
FROM a JOIN b
ON ST_Intersects(a.geom, b.geom)
GROUP BY a.fid;

Your Answer

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

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