Skip to content

border_segment does not return the right number of segments #1

Description

@guyschvitz

I noticed that border_segment does not return the right number of segments if the input is a multilinestring. This seems to be a problem with st_cast, which can be fixed when using st_line_merge first, as shown in the MWE below:

library(sf)
library(SpatialRDD)

## Load example data
ch <- st_as_sf(raster::getData(name = "GADM", country = "CHE", level = 1))
ch <- st_transform(ch, 2056)

zh <- ch[grepl("Zür", ch$NAME_1),]
ag <- ch[grepl("Aar", ch$NAME_1),]

pts <- st_as_sf(st_sample(rbind(zh, ag), 1000))
border <- st_intersection(st_boundary(zh), st_boundary(ag))

## Use border_segment to split up into 10 segments
test <- border_segment(pts, border, 10)

## This creates 143 instead of 10 segments
length(unique(test))

## Try again with st_line_merge
test2 <- border_segment(pts, st_line_merge(border), 10)

## This creates 10 segments
length(unique(test2))

By the way this package is great!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions