# [postgis-users] polygons inside polygon

paul.malm at lfv.se paul.malm at lfv.se
Tue Nov 30 04:13:49 PST 2021

```Hi,
Well I don't think so. Some of the inside polygons can have the same border as the most outer polygon with some of the vertices.
Some of the polygons can be half inside and half outside, then I would like them both to be a most outer polygon and some polygons has no inside polygons at all = most outer polygon.

Kind regards,
Paul

-----Ursprungligt meddelande-----
Från: postgis-users <postgis-users-bounces at lists.osgeo.org> För Jorge Gustavo Rocha
Skickat: den 30 november 2021 12:44
Till: postgis-users at lists.osgeo.org
Ämne: Re: [postgis-users] polygons inside polygon

Klicka bara p  l nkar och  ppna bilagor om du litar p  avs ndaren och vet att inneh llet  r s kert.
Hi Paul,

Maybe you can try to apply a ST_ConvexHull. The resulting geometry ST_touches the most outer polygon. Can you try that or this not make sense?

Regards,

Jorge

On 30/11/21 10:42, paul.malm at lfv.se wrote:
> Thank you Marcin!
>
> I’m not sure if I understand you correct. Here is what I tried to do
> to get the outer most polygons:
>
> Select * from "org" Where "fid" IN(
>
> select distinct on (t1.fid) t1.fid
>
> from "org" t1,"org" t2
>
> where ST_Area(t1.the_geom)>ST_Area(t2.the_geom)
>
> and ST_intersects(t1.the_geom,t2.the_geom)
>
> order by t1.fid,ST_Area(t2.the_geom) desc)
>
> AND "fid" NOT IN (
>
> select distinct on (t1.fid) t2.fid
>
> from "org" t1,"org" t2
>
> where ST_Area(t1.the_geom)>ST_Area(t2.the_geom)
>
> and ST_Intersects(t1.the_geom,t2.the_geom)
>
> order by t1.fid,ST_Area(t2.the_geom) desc);
>
> I’m still getting polygons inside other polygons.
>
> Kind regards,
>
> Paul
>
> *Från:*postgis-users <postgis-users-bounces at lists.osgeo.org> *För
> *Marcin Mionskowski
> *Skickat:* den 30 november 2021 08:40
> *Till:* PostGIS Users Discussion <postgis-users at lists.osgeo.org>
> *Ämne:* Re: [postgis-users] polygons inside polygon
>
> *Klicka bara på länkar och öppna bilagor om du litar på avsändaren och
> vet att innehållet är säkert.*
>
> 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
> <https://url11b.mailanyone.net/v1/?m=1mrxkX-0008NY-3a&i=57e1b682&c=E3f
> bWP_UxOp_aLqY_yLoWpoHnd9en_osfYJj-MVUi5KueBYHM1BjtHCJY7dzm-LB011qRSove
> VUqU8Wbo-SQYSOYr9IMVYP063lEVQCr3G9ErfMMDLx0JWLLcyDsdbz4OsKdCpzFuBZU-g6
> Zf2gdwauTuWm-WmCCd-yXe9BTojKOCWOHXliBKmmUzJm2IMYt21G3fa06qgsJNMVB57og9
> hfef8SNtdDMCfyM41WFZcL6sAWT7ulje7X4_yE-ywIBR2t6-OHWw7iVq5THHQ_FPz6JAbb
> D-P0i4FQ6Ze6X30U>)
> below is my take on this:
>
> select distinct on (t1.id
> <https://url11b.mailanyone.net/v1/?m=1mrxkX-0008NY-3a&i=57e1b682&c=9KJ
> uH3f7Mex6ks3lu5cPQvny5O6XFhyh-eH6svguvEFAWIQVxt2r_IF0pHeMBwTmQ0XE2xxmC
> _a38Rof5Lup9vwpMo_mGHYNGYu4f1wTbn36eA3P8CNM6_0ioVin4dzKvW5LcIMv9Lun1Vj
> fK4qpwRVaVWuelYCEa3WiGmNGu1zEEv9fA7t7zcNFT0>)
> t1.id
> <https://url11b.mailanyone.net/v1/?m=1mrxkX-0008NY-3a&i=57e1b682&c=9KJ
> uH3f7Mex6ks3lu5cPQvny5O6XFhyh-eH6svguvEFAWIQVxt2r_IF0pHeMBwTmQ0XE2xxmC
> _a38Rof5Lup9vwpMo_mGHYNGYu4f1wTbn36eA3P8CNM6_0ioVin4dzKvW5LcIMv9Lun1Vj
> fK4qpwRVaVWuelYCEa3WiGmNGu1zEEv9fA7t7zcNFT0>,t2.id
> <https://url11b.mailanyone.net/v1/?m=1mrxkX-0008NY-3a&i=57e1b682&c=MB1
> btGDh1LRWWz9_qH-7fMRyiv5SylMmhNclzuXCnly7_WjBFSzNNi8uoxskAeJ4w4vgf__ot
> NnIlUBwzIcTXhXbUpsTFsuilzyfmYd9zwlz05eB_sxpFqejtXwlOFEeYlEQLMRezJUhez4
> 0OQ4EBcMuXDxIvRB7k1Wb5YS5ejXpy-7iOFHBuUUIEB>
> 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
> <https://url11b.mailanyone.net/v1/?m=1mrxkX-0008NY-3a&i=57e1b682&c=9KJ
> uH3f7Mex6ks3lu5cPQvny5O6XFhyh-eH6svguvEFAWIQVxt2r_IF0pHeMBwTmQ0XE2xxmC
> _a38Rof5Lup9vwpMo_mGHYNGYu4f1wTbn36eA3P8CNM6_0ioVin4dzKvW5LcIMv9Lun1Vj
> fK4qpwRVaVWuelYCEa3WiGmNGu1zEEv9fA7t7zcNFT0>,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 <paul.malm at lfv.se <mailto:paul.malm at lfv.se>>
> 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
>
>     1_LFV_svensk_96
>
>     Paul Malm
>
>        Operations / AIM Flyginfo SE
>
>
>
>        Direkt  08-797 70 23  Mobil 070-860 11 15
>     paul.malm at lfv.se <mailto:paul.malm at lfv.se>
>
>         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
>     postgis-users at lists.osgeo.org <mailto:postgis-users at lists.osgeo.org>
>     https://lists.osgeo.org/mailman/listinfo/postgis-users
>
> <https://url11b.mailanyone.net/v1/?m=1mrxkX-0008NY-3a&i=57e1b682&c=_ux
> AORlsjsjbGN7PYxaRnlHKfS3HxcXJKlgGb8oZkkQQ7KeYaBvj63dVA9iAwHJFsiNVtticr
> WS07KEdiJM7B5FK1Yaq43by7MzodRIkmRm9i5TYx5AMTzK7gTO_Qito-2qIlo3A7Ie0mip
> OiHVt2vWc3OvcW4JCOK1neLV9mQTj4o8JyaGnGIG3M_sLpXMopSV6-fN3Qc5DR2cPPfCZ4
> ySDLNEacKWQP5buUcMtkzhGviuZh24fRX4mSjaR9t7d9eZEeB6bPE0YFX2AgKUEY2w9g5s
> 3z41MQ6FNL6ZvrJU>
>
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/postgis-users
>

J. Gustavo
--
Jorge Gustavo Rocha
Departamento de Informática
4710-057 Braga
Gabinete 3.29 (Piso 3)
Tel: +351 253604480
Fax: +351 253604471
Móvel: +351 910333888
skype: nabocudnosor
_______________________________________________
postgis-users mailing list
postgis-users at lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/postgis-users
```