Splitting polygons at narrowest part using R?Removing slivers after splitting a polygon with a lineMapping...

Deleting millions of records on SQL Server 14.0

How to anonymously report the Establishment Clause being broken?

How to disambiguate between various meditation practices?

How does Harry wear the invisibility cloak?

Why do we need explainable AI?

Adding transparency to ink drawing

IEEE Registration Authority mac prefix

std::tuple sizeof, is it a missed optimization?

How to encode a class with 24,000 categories?

Did Alan Turing's student Robin Gandy assert that Charles Babbage had no notion of a universal computing machine?

Does POSIX guarantee the paths to any standard utilities?

Do mortgage points get applied directly to the principal?

co-son-in-law or co-brother

How do I stop making people jump at home and at work?

Generate points for smooth movement between two given points

Is it possible to observe space debris with Binoculars?

Why do old games use flashing as means of showing damage?

How many days for hunting?

Is it rude to ask my opponent to resign an online game when they have a lost endgame?

Can I sleep overnight at Stansted Airport

Would you recommend a keyboard for beginners with or without lights in keys for learning?

Why did the VIC-II and SID use 6 µm technology in the era of 3 µm and 1.5 µm?

Travel to USA with a stuffed puppet

Powering an offset stacked array of pistons



Splitting polygons at narrowest part using R?


Removing slivers after splitting a polygon with a lineMapping Russia - Int'l dateline splitting polygonHow to merge single polygons to multi part polygons by maximum distances?Cutting polygon using line - cutter, cut() - using ArcPy?QGIS split line into segments on polygonSplit polygons based on raster layer and defined target sizeSplitting Polygons at midpoint using ArcPy?Splitting polygons with line grid in QGIS?Identifying polygons in two separate layers with a large (>85%) overlapFilling or splitting polygons proportionally based on variables using QGIS?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







3















I have a dataset of polygons like this one:



enter image description here



I would like to split these polygons in separate parts at their most narrow location (if they have one). For example the two small polygons should not be split. So I would need to identify narrow locations and then split the polygon there.



How could this be done using R?










share|improve this question






















  • 2





    Why shouldn't the two smaller polygons be split? They must have a narrowest point if they have any variable width at all. The one lower right looks like its narrowest would cut off the left-most "blob".

    – Spacedman
    9 hours ago








  • 1





    But the small polygon have a narrowest part, how did you determine that they should not split (minimum area, narrowest part smaller than X, other....)

    – J.R
    9 hours ago











  • That's true – maybe some sort of polygon complexity and a size criterion should determine wether a polygon is split or not.

    – Mario
    9 hours ago






  • 2





    Sure, but if you didn't know your own requirement how could we propose a solution ?

    – J.R
    9 hours ago











  • One algorithm might be to find the smallest negative distance (ie internal) buffer that splits the polygon into two polygons, and then somehow use that to decide where to split the polygon. I've not fully worked this out yet...

    – Spacedman
    9 hours ago


















3















I have a dataset of polygons like this one:



enter image description here



I would like to split these polygons in separate parts at their most narrow location (if they have one). For example the two small polygons should not be split. So I would need to identify narrow locations and then split the polygon there.



How could this be done using R?










share|improve this question






















  • 2





    Why shouldn't the two smaller polygons be split? They must have a narrowest point if they have any variable width at all. The one lower right looks like its narrowest would cut off the left-most "blob".

    – Spacedman
    9 hours ago








  • 1





    But the small polygon have a narrowest part, how did you determine that they should not split (minimum area, narrowest part smaller than X, other....)

    – J.R
    9 hours ago











  • That's true – maybe some sort of polygon complexity and a size criterion should determine wether a polygon is split or not.

    – Mario
    9 hours ago






  • 2





    Sure, but if you didn't know your own requirement how could we propose a solution ?

    – J.R
    9 hours ago











  • One algorithm might be to find the smallest negative distance (ie internal) buffer that splits the polygon into two polygons, and then somehow use that to decide where to split the polygon. I've not fully worked this out yet...

    – Spacedman
    9 hours ago














3












3








3


1






I have a dataset of polygons like this one:



enter image description here



I would like to split these polygons in separate parts at their most narrow location (if they have one). For example the two small polygons should not be split. So I would need to identify narrow locations and then split the polygon there.



How could this be done using R?










share|improve this question
















I have a dataset of polygons like this one:



enter image description here



I would like to split these polygons in separate parts at their most narrow location (if they have one). For example the two small polygons should not be split. So I would need to identify narrow locations and then split the polygon there.



How could this be done using R?







r polygon splitting






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 4 hours ago









PolyGeo

55k17 gold badges87 silver badges258 bronze badges




55k17 gold badges87 silver badges258 bronze badges










asked 9 hours ago









MarioMario

1574 bronze badges




1574 bronze badges











  • 2





    Why shouldn't the two smaller polygons be split? They must have a narrowest point if they have any variable width at all. The one lower right looks like its narrowest would cut off the left-most "blob".

    – Spacedman
    9 hours ago








  • 1





    But the small polygon have a narrowest part, how did you determine that they should not split (minimum area, narrowest part smaller than X, other....)

    – J.R
    9 hours ago











  • That's true – maybe some sort of polygon complexity and a size criterion should determine wether a polygon is split or not.

    – Mario
    9 hours ago






  • 2





    Sure, but if you didn't know your own requirement how could we propose a solution ?

    – J.R
    9 hours ago











  • One algorithm might be to find the smallest negative distance (ie internal) buffer that splits the polygon into two polygons, and then somehow use that to decide where to split the polygon. I've not fully worked this out yet...

    – Spacedman
    9 hours ago














  • 2





    Why shouldn't the two smaller polygons be split? They must have a narrowest point if they have any variable width at all. The one lower right looks like its narrowest would cut off the left-most "blob".

    – Spacedman
    9 hours ago








  • 1





    But the small polygon have a narrowest part, how did you determine that they should not split (minimum area, narrowest part smaller than X, other....)

    – J.R
    9 hours ago











  • That's true – maybe some sort of polygon complexity and a size criterion should determine wether a polygon is split or not.

    – Mario
    9 hours ago






  • 2





    Sure, but if you didn't know your own requirement how could we propose a solution ?

    – J.R
    9 hours ago











  • One algorithm might be to find the smallest negative distance (ie internal) buffer that splits the polygon into two polygons, and then somehow use that to decide where to split the polygon. I've not fully worked this out yet...

    – Spacedman
    9 hours ago








2




2





Why shouldn't the two smaller polygons be split? They must have a narrowest point if they have any variable width at all. The one lower right looks like its narrowest would cut off the left-most "blob".

– Spacedman
9 hours ago







Why shouldn't the two smaller polygons be split? They must have a narrowest point if they have any variable width at all. The one lower right looks like its narrowest would cut off the left-most "blob".

– Spacedman
9 hours ago






1




1





But the small polygon have a narrowest part, how did you determine that they should not split (minimum area, narrowest part smaller than X, other....)

– J.R
9 hours ago





But the small polygon have a narrowest part, how did you determine that they should not split (minimum area, narrowest part smaller than X, other....)

– J.R
9 hours ago













That's true – maybe some sort of polygon complexity and a size criterion should determine wether a polygon is split or not.

– Mario
9 hours ago





That's true – maybe some sort of polygon complexity and a size criterion should determine wether a polygon is split or not.

– Mario
9 hours ago




2




2





Sure, but if you didn't know your own requirement how could we propose a solution ?

– J.R
9 hours ago





Sure, but if you didn't know your own requirement how could we propose a solution ?

– J.R
9 hours ago













One algorithm might be to find the smallest negative distance (ie internal) buffer that splits the polygon into two polygons, and then somehow use that to decide where to split the polygon. I've not fully worked this out yet...

– Spacedman
9 hours ago





One algorithm might be to find the smallest negative distance (ie internal) buffer that splits the polygon into two polygons, and then somehow use that to decide where to split the polygon. I've not fully worked this out yet...

– Spacedman
9 hours ago










1 Answer
1






active

oldest

votes


















6
















Given a polygon pol, like this:



enter image description here



then:



> library(sf)
> sdist = -0.055168
> ppol = splitnarrow(pol, sdist, 1e-3)
> plot(ppol, col=1:2)


produces this:



enter image description here



Here's the source code for splitnarrow. There's a zillion places where this can go wrong, and first you have to determine sdist and eps for your polygons.



splitnarrow <- function(pol, sdist, eps){
###
### split a polygon at its narrowest point.
###

### sdist is the smallest value for internal buffering that splits the
### polygon into a MULTIPOLYGON and needs computing before running this.

### eps is another tolerance that is needed to get the points at which the
### narrowest point is to be cut.

## split the polygon into two separate polygons
bparts = st_buffer(pol, sdist)
features = st_cast(st_sfc(bparts), "POLYGON")

## find where the two separate polygons are closest, this is where
## the internal buffering pinched off into two polygons.

pinch = st_nearest_points(features[1],features[2])

## buffering the pinch point by a slightly larger buffer length should intersect with
## the polygon at the narrow point.
inter = st_intersection(
st_cast(pol,"MULTILINESTRING"),
st_buffer(pinch,-(sdist-(eps))
)
)
join = st_cast(st_sfc(inter), "LINESTRING")

## join is now two small line segments of the polygon across the "waist".
## find the line of closest approach of them:
splitline = st_nearest_points(join[1], join[2])

## that's our cut line. Now put that with the polygon and make new polygons:
mm = st_union(splitline, st_cast(pol, "LINESTRING"))
parts = st_collection_extract(st_polygonize(mm))
parts
}


sdist is the smallest value that splits the single polygon into a multipolygon, and eps is the smallest value that touches both sides when buffered from the waist intersection point. Finding these could be automated.






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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    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%2f333817%2fsplitting-polygons-at-narrowest-part-using-r%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    6
















    Given a polygon pol, like this:



    enter image description here



    then:



    > library(sf)
    > sdist = -0.055168
    > ppol = splitnarrow(pol, sdist, 1e-3)
    > plot(ppol, col=1:2)


    produces this:



    enter image description here



    Here's the source code for splitnarrow. There's a zillion places where this can go wrong, and first you have to determine sdist and eps for your polygons.



    splitnarrow <- function(pol, sdist, eps){
    ###
    ### split a polygon at its narrowest point.
    ###

    ### sdist is the smallest value for internal buffering that splits the
    ### polygon into a MULTIPOLYGON and needs computing before running this.

    ### eps is another tolerance that is needed to get the points at which the
    ### narrowest point is to be cut.

    ## split the polygon into two separate polygons
    bparts = st_buffer(pol, sdist)
    features = st_cast(st_sfc(bparts), "POLYGON")

    ## find where the two separate polygons are closest, this is where
    ## the internal buffering pinched off into two polygons.

    pinch = st_nearest_points(features[1],features[2])

    ## buffering the pinch point by a slightly larger buffer length should intersect with
    ## the polygon at the narrow point.
    inter = st_intersection(
    st_cast(pol,"MULTILINESTRING"),
    st_buffer(pinch,-(sdist-(eps))
    )
    )
    join = st_cast(st_sfc(inter), "LINESTRING")

    ## join is now two small line segments of the polygon across the "waist".
    ## find the line of closest approach of them:
    splitline = st_nearest_points(join[1], join[2])

    ## that's our cut line. Now put that with the polygon and make new polygons:
    mm = st_union(splitline, st_cast(pol, "LINESTRING"))
    parts = st_collection_extract(st_polygonize(mm))
    parts
    }


    sdist is the smallest value that splits the single polygon into a multipolygon, and eps is the smallest value that touches both sides when buffered from the waist intersection point. Finding these could be automated.






    share|improve this answer






























      6
















      Given a polygon pol, like this:



      enter image description here



      then:



      > library(sf)
      > sdist = -0.055168
      > ppol = splitnarrow(pol, sdist, 1e-3)
      > plot(ppol, col=1:2)


      produces this:



      enter image description here



      Here's the source code for splitnarrow. There's a zillion places where this can go wrong, and first you have to determine sdist and eps for your polygons.



      splitnarrow <- function(pol, sdist, eps){
      ###
      ### split a polygon at its narrowest point.
      ###

      ### sdist is the smallest value for internal buffering that splits the
      ### polygon into a MULTIPOLYGON and needs computing before running this.

      ### eps is another tolerance that is needed to get the points at which the
      ### narrowest point is to be cut.

      ## split the polygon into two separate polygons
      bparts = st_buffer(pol, sdist)
      features = st_cast(st_sfc(bparts), "POLYGON")

      ## find where the two separate polygons are closest, this is where
      ## the internal buffering pinched off into two polygons.

      pinch = st_nearest_points(features[1],features[2])

      ## buffering the pinch point by a slightly larger buffer length should intersect with
      ## the polygon at the narrow point.
      inter = st_intersection(
      st_cast(pol,"MULTILINESTRING"),
      st_buffer(pinch,-(sdist-(eps))
      )
      )
      join = st_cast(st_sfc(inter), "LINESTRING")

      ## join is now two small line segments of the polygon across the "waist".
      ## find the line of closest approach of them:
      splitline = st_nearest_points(join[1], join[2])

      ## that's our cut line. Now put that with the polygon and make new polygons:
      mm = st_union(splitline, st_cast(pol, "LINESTRING"))
      parts = st_collection_extract(st_polygonize(mm))
      parts
      }


      sdist is the smallest value that splits the single polygon into a multipolygon, and eps is the smallest value that touches both sides when buffered from the waist intersection point. Finding these could be automated.






      share|improve this answer




























        6














        6










        6









        Given a polygon pol, like this:



        enter image description here



        then:



        > library(sf)
        > sdist = -0.055168
        > ppol = splitnarrow(pol, sdist, 1e-3)
        > plot(ppol, col=1:2)


        produces this:



        enter image description here



        Here's the source code for splitnarrow. There's a zillion places where this can go wrong, and first you have to determine sdist and eps for your polygons.



        splitnarrow <- function(pol, sdist, eps){
        ###
        ### split a polygon at its narrowest point.
        ###

        ### sdist is the smallest value for internal buffering that splits the
        ### polygon into a MULTIPOLYGON and needs computing before running this.

        ### eps is another tolerance that is needed to get the points at which the
        ### narrowest point is to be cut.

        ## split the polygon into two separate polygons
        bparts = st_buffer(pol, sdist)
        features = st_cast(st_sfc(bparts), "POLYGON")

        ## find where the two separate polygons are closest, this is where
        ## the internal buffering pinched off into two polygons.

        pinch = st_nearest_points(features[1],features[2])

        ## buffering the pinch point by a slightly larger buffer length should intersect with
        ## the polygon at the narrow point.
        inter = st_intersection(
        st_cast(pol,"MULTILINESTRING"),
        st_buffer(pinch,-(sdist-(eps))
        )
        )
        join = st_cast(st_sfc(inter), "LINESTRING")

        ## join is now two small line segments of the polygon across the "waist".
        ## find the line of closest approach of them:
        splitline = st_nearest_points(join[1], join[2])

        ## that's our cut line. Now put that with the polygon and make new polygons:
        mm = st_union(splitline, st_cast(pol, "LINESTRING"))
        parts = st_collection_extract(st_polygonize(mm))
        parts
        }


        sdist is the smallest value that splits the single polygon into a multipolygon, and eps is the smallest value that touches both sides when buffered from the waist intersection point. Finding these could be automated.






        share|improve this answer













        Given a polygon pol, like this:



        enter image description here



        then:



        > library(sf)
        > sdist = -0.055168
        > ppol = splitnarrow(pol, sdist, 1e-3)
        > plot(ppol, col=1:2)


        produces this:



        enter image description here



        Here's the source code for splitnarrow. There's a zillion places where this can go wrong, and first you have to determine sdist and eps for your polygons.



        splitnarrow <- function(pol, sdist, eps){
        ###
        ### split a polygon at its narrowest point.
        ###

        ### sdist is the smallest value for internal buffering that splits the
        ### polygon into a MULTIPOLYGON and needs computing before running this.

        ### eps is another tolerance that is needed to get the points at which the
        ### narrowest point is to be cut.

        ## split the polygon into two separate polygons
        bparts = st_buffer(pol, sdist)
        features = st_cast(st_sfc(bparts), "POLYGON")

        ## find where the two separate polygons are closest, this is where
        ## the internal buffering pinched off into two polygons.

        pinch = st_nearest_points(features[1],features[2])

        ## buffering the pinch point by a slightly larger buffer length should intersect with
        ## the polygon at the narrow point.
        inter = st_intersection(
        st_cast(pol,"MULTILINESTRING"),
        st_buffer(pinch,-(sdist-(eps))
        )
        )
        join = st_cast(st_sfc(inter), "LINESTRING")

        ## join is now two small line segments of the polygon across the "waist".
        ## find the line of closest approach of them:
        splitline = st_nearest_points(join[1], join[2])

        ## that's our cut line. Now put that with the polygon and make new polygons:
        mm = st_union(splitline, st_cast(pol, "LINESTRING"))
        parts = st_collection_extract(st_polygonize(mm))
        parts
        }


        sdist is the smallest value that splits the single polygon into a multipolygon, and eps is the smallest value that touches both sides when buffered from the waist intersection point. Finding these could be automated.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 8 hours ago









        SpacedmanSpacedman

        28.5k2 gold badges37 silver badges56 bronze badges




        28.5k2 gold badges37 silver badges56 bronze badges

































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f333817%2fsplitting-polygons-at-narrowest-part-using-r%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Hudson River Historic District Contents Geography History The district today Aesthetics Cultural...

            The number designs the writing. Feandra Aversely Definition: The act of ingrafting a sprig or shoot of one...

            Ayherre Geografie Demografie Externe links Navigatiemenu43° 23′ NB, 1° 15′ WL43° 23′ NB, 1°...