Determine if a polygon is not enclosed by other polygons

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












enter image description hereDoes anyone know of a routine/function or transformer that would identify if a polygon is not fully enclosed/surrounded by other polygons?



The polygons have no gaps or slivers between them so if a certain section of polygon is not attached to another polygon then these are the ones I want to keep.



I am happy to use any of PostGIS/FME/QGIS I just cannot seem to find a function or transformer that would do it.



EDIT



I have added a picture to help explain:



I am after the purple polygons and ignore the yellow ones as they are not fully enclosed by other squares







share|improve this question





















  • Are the polygons on the same layer? And if you worked with USA data then Texas would be selected but Colorado not, or?
    – user30184
    12 hours ago










  • Yes the same layer. Thats exactly what I am after.
    – tjmgis
    11 hours ago










  • I undestood that if a certain section of polygon is not attached to another polygon then these are the ones I want to keep means the purple polygons.
    – user30184
    11 hours ago










  • sorry - yes your are right, i just edited. Mondays!
    – tjmgis
    11 hours ago






  • 1




    So your question is "How can I tell if a feature in a set of features has any external boundaries?". Test the linear intersection of A with the dissolved features.
    – Spacedman
    9 hours ago

















up vote
1
down vote

favorite












enter image description hereDoes anyone know of a routine/function or transformer that would identify if a polygon is not fully enclosed/surrounded by other polygons?



The polygons have no gaps or slivers between them so if a certain section of polygon is not attached to another polygon then these are the ones I want to keep.



I am happy to use any of PostGIS/FME/QGIS I just cannot seem to find a function or transformer that would do it.



EDIT



I have added a picture to help explain:



I am after the purple polygons and ignore the yellow ones as they are not fully enclosed by other squares







share|improve this question





















  • Are the polygons on the same layer? And if you worked with USA data then Texas would be selected but Colorado not, or?
    – user30184
    12 hours ago










  • Yes the same layer. Thats exactly what I am after.
    – tjmgis
    11 hours ago










  • I undestood that if a certain section of polygon is not attached to another polygon then these are the ones I want to keep means the purple polygons.
    – user30184
    11 hours ago










  • sorry - yes your are right, i just edited. Mondays!
    – tjmgis
    11 hours ago






  • 1




    So your question is "How can I tell if a feature in a set of features has any external boundaries?". Test the linear intersection of A with the dissolved features.
    – Spacedman
    9 hours ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











enter image description hereDoes anyone know of a routine/function or transformer that would identify if a polygon is not fully enclosed/surrounded by other polygons?



The polygons have no gaps or slivers between them so if a certain section of polygon is not attached to another polygon then these are the ones I want to keep.



I am happy to use any of PostGIS/FME/QGIS I just cannot seem to find a function or transformer that would do it.



EDIT



I have added a picture to help explain:



I am after the purple polygons and ignore the yellow ones as they are not fully enclosed by other squares







share|improve this question













enter image description hereDoes anyone know of a routine/function or transformer that would identify if a polygon is not fully enclosed/surrounded by other polygons?



The polygons have no gaps or slivers between them so if a certain section of polygon is not attached to another polygon then these are the ones I want to keep.



I am happy to use any of PostGIS/FME/QGIS I just cannot seem to find a function or transformer that would do it.



EDIT



I have added a picture to help explain:



I am after the purple polygons and ignore the yellow ones as they are not fully enclosed by other squares









share|improve this question












share|improve this question




share|improve this question








edited 5 hours ago









Spacedman

19.2k13046




19.2k13046









asked 13 hours ago









tjmgis

2,0801325




2,0801325











  • Are the polygons on the same layer? And if you worked with USA data then Texas would be selected but Colorado not, or?
    – user30184
    12 hours ago










  • Yes the same layer. Thats exactly what I am after.
    – tjmgis
    11 hours ago










  • I undestood that if a certain section of polygon is not attached to another polygon then these are the ones I want to keep means the purple polygons.
    – user30184
    11 hours ago










  • sorry - yes your are right, i just edited. Mondays!
    – tjmgis
    11 hours ago






  • 1




    So your question is "How can I tell if a feature in a set of features has any external boundaries?". Test the linear intersection of A with the dissolved features.
    – Spacedman
    9 hours ago

















  • Are the polygons on the same layer? And if you worked with USA data then Texas would be selected but Colorado not, or?
    – user30184
    12 hours ago










  • Yes the same layer. Thats exactly what I am after.
    – tjmgis
    11 hours ago










  • I undestood that if a certain section of polygon is not attached to another polygon then these are the ones I want to keep means the purple polygons.
    – user30184
    11 hours ago










  • sorry - yes your are right, i just edited. Mondays!
    – tjmgis
    11 hours ago






  • 1




    So your question is "How can I tell if a feature in a set of features has any external boundaries?". Test the linear intersection of A with the dissolved features.
    – Spacedman
    9 hours ago
















Are the polygons on the same layer? And if you worked with USA data then Texas would be selected but Colorado not, or?
– user30184
12 hours ago




Are the polygons on the same layer? And if you worked with USA data then Texas would be selected but Colorado not, or?
– user30184
12 hours ago












Yes the same layer. Thats exactly what I am after.
– tjmgis
11 hours ago




Yes the same layer. Thats exactly what I am after.
– tjmgis
11 hours ago












I undestood that if a certain section of polygon is not attached to another polygon then these are the ones I want to keep means the purple polygons.
– user30184
11 hours ago




I undestood that if a certain section of polygon is not attached to another polygon then these are the ones I want to keep means the purple polygons.
– user30184
11 hours ago












sorry - yes your are right, i just edited. Mondays!
– tjmgis
11 hours ago




sorry - yes your are right, i just edited. Mondays!
– tjmgis
11 hours ago




1




1




So your question is "How can I tell if a feature in a set of features has any external boundaries?". Test the linear intersection of A with the dissolved features.
– Spacedman
9 hours ago





So your question is "How can I tell if a feature in a set of features has any external boundaries?". Test the linear intersection of A with the dissolved features.
– Spacedman
9 hours ago











3 Answers
3






active

oldest

votes

















up vote
2
down vote













I have an answer that should be logically correct but the SQL part is not complete. The idea is based on intersections of adjacent polygons. The intesections are either lines if polygons share segment(s), or points if polygons meet at one vertex.



The first step is to compute the intersection of one polygon and the union of all the polygons on the layer, except the selected polygon.



enter image description here



The intersection of polygon 1 and union of all the rest is a multilinestring with two members. The intersection of polygon 6 and anything else but polygon 6 consists of four linestrings members which are connected.



enter image description here



The second step is to try if it is possible to build a new polygon from the intersections. For the connected lines from polygon 6 it is possible but not for the two linestrings from polygon 1.



This is the SQL that I used for testing.



select ST_MakePolygon(ST_LineMerge(c.intersection)) from 
(select
ST_Intersection(sub_a.a,sub_b.b) as intersection from
(select ST_Union("GEOMETRY") as a from outline_test where gid!=6) as sub_a,
(select "GEOMETRY" as b from outline_test where gid=6) as sub_b) as c;


With gid=1 the result is an error:



ERROR: lwpoly_from_lwlines: shell must have at least 4 points


and with gid=2:



ERROR: lwpoly_from_lwlines: shell must be closed





share|improve this answer




























    up vote
    0
    down vote













    Another approach: The polygons you want to find have 1-dimensional intersection (lines) with the outer ring of the whole area as an union. If polygon is only touching the outer boundary the intersection is a point with dimension=0, and polygons which are totally inside to not intersect as all (so they are disjoint).



    So you can select the features with ST_Dimension=1 from SQL query like



    select outline_test.gid,ST_Dimension
    (ST_Intersection(outline_test."GEOMETRY",sub_a.geometry))
    from
    (select ST_ExteriorRing(ST_Union("GEOMETRY")) as geometry from outline_test)
    as sub_a, outline_test;


    The query does not make difference between "touches" and "disjoint" as documented in https://postgis.net/docs/ST_Dimension.html If the dimension is unknown (empty GEOMETRYCOLLECTION) 0 is returned but that does not matter in your use case. Rereffing to the data and image in my other answer, other polygons than numbers 5, 6, 8, and 10 should be found and that happens.



    1;1
    2;1
    3;1
    4;1
    5;0
    6;0
    7;1
    8;0
    9;1
    10;0
    11;1
    12;1
    13;1
    14;1


    I am sure it is possible to write more elegant queries based on the outer boundary and DE-9IM relations http://postgis.net/docs/using_postgis_dbmanagement.html#DE-9IM.






    share|improve this answer





















    • I think you've expressed the inverse problem with "The polygons you want to find have 1-dimensional intersection (lines) with the outer ring of the whole area as an union" - the required polygons are the yellow ones in the diagram and they don't have 1-d intersection with the external.
      – Spacedman
      6 hours ago










    • OP wants the purple polygons.
      – user30184
      6 hours ago










    • Oh then the title is misleading: "Determine if a polygon is enclosed by other polygons"... I'll edit..
      – Spacedman
      5 hours ago

















    up vote
    0
    down vote













    Assuming your polygons are topologically correct (no gaps, or overlaps), then a polygon A is enclosed by other polygons if its perimeter is equal to the sum of intersection length between its boundary and the boundary of other polygons. This method lends itself to use of a spatial index and avoids performing a relatively costly union of all other polygons.



    SELECT a.id
    FROM my_data a
    INNER JOIN my_data b ON (ST_Intersects(a.geom, b.geom) AND a.id != b.id)
    GROUP BY a.id
    HAVING 1e-6 >
    abs(ST_Length(ST_ExteriorRing(a.geom)) -
    sum(ST_Length(ST_Intersection(ST_Exteriorring(a.geom), ST_ExteriorRing(b.geom)))));





    share|improve this answer























      Your Answer







      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "79"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );








       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f291824%2fdetermine-if-a-polygon-is-not-enclosed-by-other-polygons%23new-answer', 'question_page');

      );

      Post as a guest






























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      2
      down vote













      I have an answer that should be logically correct but the SQL part is not complete. The idea is based on intersections of adjacent polygons. The intesections are either lines if polygons share segment(s), or points if polygons meet at one vertex.



      The first step is to compute the intersection of one polygon and the union of all the polygons on the layer, except the selected polygon.



      enter image description here



      The intersection of polygon 1 and union of all the rest is a multilinestring with two members. The intersection of polygon 6 and anything else but polygon 6 consists of four linestrings members which are connected.



      enter image description here



      The second step is to try if it is possible to build a new polygon from the intersections. For the connected lines from polygon 6 it is possible but not for the two linestrings from polygon 1.



      This is the SQL that I used for testing.



      select ST_MakePolygon(ST_LineMerge(c.intersection)) from 
      (select
      ST_Intersection(sub_a.a,sub_b.b) as intersection from
      (select ST_Union("GEOMETRY") as a from outline_test where gid!=6) as sub_a,
      (select "GEOMETRY" as b from outline_test where gid=6) as sub_b) as c;


      With gid=1 the result is an error:



      ERROR: lwpoly_from_lwlines: shell must have at least 4 points


      and with gid=2:



      ERROR: lwpoly_from_lwlines: shell must be closed





      share|improve this answer

























        up vote
        2
        down vote













        I have an answer that should be logically correct but the SQL part is not complete. The idea is based on intersections of adjacent polygons. The intesections are either lines if polygons share segment(s), or points if polygons meet at one vertex.



        The first step is to compute the intersection of one polygon and the union of all the polygons on the layer, except the selected polygon.



        enter image description here



        The intersection of polygon 1 and union of all the rest is a multilinestring with two members. The intersection of polygon 6 and anything else but polygon 6 consists of four linestrings members which are connected.



        enter image description here



        The second step is to try if it is possible to build a new polygon from the intersections. For the connected lines from polygon 6 it is possible but not for the two linestrings from polygon 1.



        This is the SQL that I used for testing.



        select ST_MakePolygon(ST_LineMerge(c.intersection)) from 
        (select
        ST_Intersection(sub_a.a,sub_b.b) as intersection from
        (select ST_Union("GEOMETRY") as a from outline_test where gid!=6) as sub_a,
        (select "GEOMETRY" as b from outline_test where gid=6) as sub_b) as c;


        With gid=1 the result is an error:



        ERROR: lwpoly_from_lwlines: shell must have at least 4 points


        and with gid=2:



        ERROR: lwpoly_from_lwlines: shell must be closed





        share|improve this answer























          up vote
          2
          down vote










          up vote
          2
          down vote









          I have an answer that should be logically correct but the SQL part is not complete. The idea is based on intersections of adjacent polygons. The intesections are either lines if polygons share segment(s), or points if polygons meet at one vertex.



          The first step is to compute the intersection of one polygon and the union of all the polygons on the layer, except the selected polygon.



          enter image description here



          The intersection of polygon 1 and union of all the rest is a multilinestring with two members. The intersection of polygon 6 and anything else but polygon 6 consists of four linestrings members which are connected.



          enter image description here



          The second step is to try if it is possible to build a new polygon from the intersections. For the connected lines from polygon 6 it is possible but not for the two linestrings from polygon 1.



          This is the SQL that I used for testing.



          select ST_MakePolygon(ST_LineMerge(c.intersection)) from 
          (select
          ST_Intersection(sub_a.a,sub_b.b) as intersection from
          (select ST_Union("GEOMETRY") as a from outline_test where gid!=6) as sub_a,
          (select "GEOMETRY" as b from outline_test where gid=6) as sub_b) as c;


          With gid=1 the result is an error:



          ERROR: lwpoly_from_lwlines: shell must have at least 4 points


          and with gid=2:



          ERROR: lwpoly_from_lwlines: shell must be closed





          share|improve this answer













          I have an answer that should be logically correct but the SQL part is not complete. The idea is based on intersections of adjacent polygons. The intesections are either lines if polygons share segment(s), or points if polygons meet at one vertex.



          The first step is to compute the intersection of one polygon and the union of all the polygons on the layer, except the selected polygon.



          enter image description here



          The intersection of polygon 1 and union of all the rest is a multilinestring with two members. The intersection of polygon 6 and anything else but polygon 6 consists of four linestrings members which are connected.



          enter image description here



          The second step is to try if it is possible to build a new polygon from the intersections. For the connected lines from polygon 6 it is possible but not for the two linestrings from polygon 1.



          This is the SQL that I used for testing.



          select ST_MakePolygon(ST_LineMerge(c.intersection)) from 
          (select
          ST_Intersection(sub_a.a,sub_b.b) as intersection from
          (select ST_Union("GEOMETRY") as a from outline_test where gid!=6) as sub_a,
          (select "GEOMETRY" as b from outline_test where gid=6) as sub_b) as c;


          With gid=1 the result is an error:



          ERROR: lwpoly_from_lwlines: shell must have at least 4 points


          and with gid=2:



          ERROR: lwpoly_from_lwlines: shell must be closed






          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered 9 hours ago









          user30184

          25.9k22749




          25.9k22749






















              up vote
              0
              down vote













              Another approach: The polygons you want to find have 1-dimensional intersection (lines) with the outer ring of the whole area as an union. If polygon is only touching the outer boundary the intersection is a point with dimension=0, and polygons which are totally inside to not intersect as all (so they are disjoint).



              So you can select the features with ST_Dimension=1 from SQL query like



              select outline_test.gid,ST_Dimension
              (ST_Intersection(outline_test."GEOMETRY",sub_a.geometry))
              from
              (select ST_ExteriorRing(ST_Union("GEOMETRY")) as geometry from outline_test)
              as sub_a, outline_test;


              The query does not make difference between "touches" and "disjoint" as documented in https://postgis.net/docs/ST_Dimension.html If the dimension is unknown (empty GEOMETRYCOLLECTION) 0 is returned but that does not matter in your use case. Rereffing to the data and image in my other answer, other polygons than numbers 5, 6, 8, and 10 should be found and that happens.



              1;1
              2;1
              3;1
              4;1
              5;0
              6;0
              7;1
              8;0
              9;1
              10;0
              11;1
              12;1
              13;1
              14;1


              I am sure it is possible to write more elegant queries based on the outer boundary and DE-9IM relations http://postgis.net/docs/using_postgis_dbmanagement.html#DE-9IM.






              share|improve this answer





















              • I think you've expressed the inverse problem with "The polygons you want to find have 1-dimensional intersection (lines) with the outer ring of the whole area as an union" - the required polygons are the yellow ones in the diagram and they don't have 1-d intersection with the external.
                – Spacedman
                6 hours ago










              • OP wants the purple polygons.
                – user30184
                6 hours ago










              • Oh then the title is misleading: "Determine if a polygon is enclosed by other polygons"... I'll edit..
                – Spacedman
                5 hours ago














              up vote
              0
              down vote













              Another approach: The polygons you want to find have 1-dimensional intersection (lines) with the outer ring of the whole area as an union. If polygon is only touching the outer boundary the intersection is a point with dimension=0, and polygons which are totally inside to not intersect as all (so they are disjoint).



              So you can select the features with ST_Dimension=1 from SQL query like



              select outline_test.gid,ST_Dimension
              (ST_Intersection(outline_test."GEOMETRY",sub_a.geometry))
              from
              (select ST_ExteriorRing(ST_Union("GEOMETRY")) as geometry from outline_test)
              as sub_a, outline_test;


              The query does not make difference between "touches" and "disjoint" as documented in https://postgis.net/docs/ST_Dimension.html If the dimension is unknown (empty GEOMETRYCOLLECTION) 0 is returned but that does not matter in your use case. Rereffing to the data and image in my other answer, other polygons than numbers 5, 6, 8, and 10 should be found and that happens.



              1;1
              2;1
              3;1
              4;1
              5;0
              6;0
              7;1
              8;0
              9;1
              10;0
              11;1
              12;1
              13;1
              14;1


              I am sure it is possible to write more elegant queries based on the outer boundary and DE-9IM relations http://postgis.net/docs/using_postgis_dbmanagement.html#DE-9IM.






              share|improve this answer





















              • I think you've expressed the inverse problem with "The polygons you want to find have 1-dimensional intersection (lines) with the outer ring of the whole area as an union" - the required polygons are the yellow ones in the diagram and they don't have 1-d intersection with the external.
                – Spacedman
                6 hours ago










              • OP wants the purple polygons.
                – user30184
                6 hours ago










              • Oh then the title is misleading: "Determine if a polygon is enclosed by other polygons"... I'll edit..
                – Spacedman
                5 hours ago












              up vote
              0
              down vote










              up vote
              0
              down vote









              Another approach: The polygons you want to find have 1-dimensional intersection (lines) with the outer ring of the whole area as an union. If polygon is only touching the outer boundary the intersection is a point with dimension=0, and polygons which are totally inside to not intersect as all (so they are disjoint).



              So you can select the features with ST_Dimension=1 from SQL query like



              select outline_test.gid,ST_Dimension
              (ST_Intersection(outline_test."GEOMETRY",sub_a.geometry))
              from
              (select ST_ExteriorRing(ST_Union("GEOMETRY")) as geometry from outline_test)
              as sub_a, outline_test;


              The query does not make difference between "touches" and "disjoint" as documented in https://postgis.net/docs/ST_Dimension.html If the dimension is unknown (empty GEOMETRYCOLLECTION) 0 is returned but that does not matter in your use case. Rereffing to the data and image in my other answer, other polygons than numbers 5, 6, 8, and 10 should be found and that happens.



              1;1
              2;1
              3;1
              4;1
              5;0
              6;0
              7;1
              8;0
              9;1
              10;0
              11;1
              12;1
              13;1
              14;1


              I am sure it is possible to write more elegant queries based on the outer boundary and DE-9IM relations http://postgis.net/docs/using_postgis_dbmanagement.html#DE-9IM.






              share|improve this answer













              Another approach: The polygons you want to find have 1-dimensional intersection (lines) with the outer ring of the whole area as an union. If polygon is only touching the outer boundary the intersection is a point with dimension=0, and polygons which are totally inside to not intersect as all (so they are disjoint).



              So you can select the features with ST_Dimension=1 from SQL query like



              select outline_test.gid,ST_Dimension
              (ST_Intersection(outline_test."GEOMETRY",sub_a.geometry))
              from
              (select ST_ExteriorRing(ST_Union("GEOMETRY")) as geometry from outline_test)
              as sub_a, outline_test;


              The query does not make difference between "touches" and "disjoint" as documented in https://postgis.net/docs/ST_Dimension.html If the dimension is unknown (empty GEOMETRYCOLLECTION) 0 is returned but that does not matter in your use case. Rereffing to the data and image in my other answer, other polygons than numbers 5, 6, 8, and 10 should be found and that happens.



              1;1
              2;1
              3;1
              4;1
              5;0
              6;0
              7;1
              8;0
              9;1
              10;0
              11;1
              12;1
              13;1
              14;1


              I am sure it is possible to write more elegant queries based on the outer boundary and DE-9IM relations http://postgis.net/docs/using_postgis_dbmanagement.html#DE-9IM.







              share|improve this answer













              share|improve this answer



              share|improve this answer











              answered 9 hours ago









              user30184

              25.9k22749




              25.9k22749











              • I think you've expressed the inverse problem with "The polygons you want to find have 1-dimensional intersection (lines) with the outer ring of the whole area as an union" - the required polygons are the yellow ones in the diagram and they don't have 1-d intersection with the external.
                – Spacedman
                6 hours ago










              • OP wants the purple polygons.
                – user30184
                6 hours ago










              • Oh then the title is misleading: "Determine if a polygon is enclosed by other polygons"... I'll edit..
                – Spacedman
                5 hours ago
















              • I think you've expressed the inverse problem with "The polygons you want to find have 1-dimensional intersection (lines) with the outer ring of the whole area as an union" - the required polygons are the yellow ones in the diagram and they don't have 1-d intersection with the external.
                – Spacedman
                6 hours ago










              • OP wants the purple polygons.
                – user30184
                6 hours ago










              • Oh then the title is misleading: "Determine if a polygon is enclosed by other polygons"... I'll edit..
                – Spacedman
                5 hours ago















              I think you've expressed the inverse problem with "The polygons you want to find have 1-dimensional intersection (lines) with the outer ring of the whole area as an union" - the required polygons are the yellow ones in the diagram and they don't have 1-d intersection with the external.
              – Spacedman
              6 hours ago




              I think you've expressed the inverse problem with "The polygons you want to find have 1-dimensional intersection (lines) with the outer ring of the whole area as an union" - the required polygons are the yellow ones in the diagram and they don't have 1-d intersection with the external.
              – Spacedman
              6 hours ago












              OP wants the purple polygons.
              – user30184
              6 hours ago




              OP wants the purple polygons.
              – user30184
              6 hours ago












              Oh then the title is misleading: "Determine if a polygon is enclosed by other polygons"... I'll edit..
              – Spacedman
              5 hours ago




              Oh then the title is misleading: "Determine if a polygon is enclosed by other polygons"... I'll edit..
              – Spacedman
              5 hours ago










              up vote
              0
              down vote













              Assuming your polygons are topologically correct (no gaps, or overlaps), then a polygon A is enclosed by other polygons if its perimeter is equal to the sum of intersection length between its boundary and the boundary of other polygons. This method lends itself to use of a spatial index and avoids performing a relatively costly union of all other polygons.



              SELECT a.id
              FROM my_data a
              INNER JOIN my_data b ON (ST_Intersects(a.geom, b.geom) AND a.id != b.id)
              GROUP BY a.id
              HAVING 1e-6 >
              abs(ST_Length(ST_ExteriorRing(a.geom)) -
              sum(ST_Length(ST_Intersection(ST_Exteriorring(a.geom), ST_ExteriorRing(b.geom)))));





              share|improve this answer



























                up vote
                0
                down vote













                Assuming your polygons are topologically correct (no gaps, or overlaps), then a polygon A is enclosed by other polygons if its perimeter is equal to the sum of intersection length between its boundary and the boundary of other polygons. This method lends itself to use of a spatial index and avoids performing a relatively costly union of all other polygons.



                SELECT a.id
                FROM my_data a
                INNER JOIN my_data b ON (ST_Intersects(a.geom, b.geom) AND a.id != b.id)
                GROUP BY a.id
                HAVING 1e-6 >
                abs(ST_Length(ST_ExteriorRing(a.geom)) -
                sum(ST_Length(ST_Intersection(ST_Exteriorring(a.geom), ST_ExteriorRing(b.geom)))));





                share|improve this answer

























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Assuming your polygons are topologically correct (no gaps, or overlaps), then a polygon A is enclosed by other polygons if its perimeter is equal to the sum of intersection length between its boundary and the boundary of other polygons. This method lends itself to use of a spatial index and avoids performing a relatively costly union of all other polygons.



                  SELECT a.id
                  FROM my_data a
                  INNER JOIN my_data b ON (ST_Intersects(a.geom, b.geom) AND a.id != b.id)
                  GROUP BY a.id
                  HAVING 1e-6 >
                  abs(ST_Length(ST_ExteriorRing(a.geom)) -
                  sum(ST_Length(ST_Intersection(ST_Exteriorring(a.geom), ST_ExteriorRing(b.geom)))));





                  share|improve this answer















                  Assuming your polygons are topologically correct (no gaps, or overlaps), then a polygon A is enclosed by other polygons if its perimeter is equal to the sum of intersection length between its boundary and the boundary of other polygons. This method lends itself to use of a spatial index and avoids performing a relatively costly union of all other polygons.



                  SELECT a.id
                  FROM my_data a
                  INNER JOIN my_data b ON (ST_Intersects(a.geom, b.geom) AND a.id != b.id)
                  GROUP BY a.id
                  HAVING 1e-6 >
                  abs(ST_Length(ST_ExteriorRing(a.geom)) -
                  sum(ST_Length(ST_Intersection(ST_Exteriorring(a.geom), ST_ExteriorRing(b.geom)))));






                  share|improve this answer















                  share|improve this answer



                  share|improve this answer








                  edited 2 hours ago


























                  answered 2 hours ago









                  dbaston

                  6,78322044




                  6,78322044






















                       

                      draft saved


                      draft discarded


























                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f291824%2fdetermine-if-a-polygon-is-not-enclosed-by-other-polygons%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      Peggy Mitchell

                      Palaiologos

                      The Forum (Inglewood, California)