Assuming (1) your problem is not trivial (you have more then one "outer
most" polygon) and (2) there can be only one type of spatial relationship
(polygons are properly contained
https://postgis.net/docs/ST_ContainsProperly.html) below is my take on this:
select distinct on (t1.id) t1.id,t2.id
from t t1,t t2
where ST_Area(t1.geom)>ST_Area(t2.geom)
and ST_Intersects(t1.geom,t2.geom)
order by t1.id,ST_Area(t2.geom) desc;
Enclose this in CTE and then just select "outer" polygons based on left
column and "inner" based on right column.

wt., 30 lis 2021 o 07:30 <[email protected]> napisał(a):

>
>
>
>
> Hi,
>
> I have a polygon layer where polygons are inside other polygons (could be
> polygons in polygons in polygons…).
>
> I would like to separate them in 2 different layers, one layer with the
> outer most polygon and one layer with all polygons that has a surrounding
> polygon.
>
> Is there a smart way to do this in SQL?
>
>
>
> Thanks,
>
> Paul
>
>     [image: 1_LFV_svensk_96]
>
>   Paul Malm
>
>
>
>   Operations / AIM Flyginfo SE
>
>
>
>   Direkt  08-797 70 23  Mobil 070-860 11 15
>   [email protected]
>
>    Besöks- och postadress
>    LFV Flyginfo SE
>
>    Af Pontins väg 6
>
>    115 21 STOCKHOLM
>
>
>
>
>
>
>
>    Tänk på miljön innan du skriver ut detta e-postmeddelande.
>
>
>
>
>
>
> _______________________________________________
> postgis-users mailing list
> [email protected]
> https://lists.osgeo.org/mailman/listinfo/postgis-users
>
_______________________________________________
postgis-users mailing list
[email protected]
https://lists.osgeo.org/mailman/listinfo/postgis-users

Reply via email to