stplanr icon indicating copy to clipboard operation
stplanr copied to clipboard

Isochrone circles to dohnuts

Open Robinlovelace opened this issue 6 years ago • 1 comments
trafficstars

Idea: credit @mem48

Robinlovelace avatar Jun 12 '19 08:06 Robinlovelace

Made a first crack at this:

library(sf)

p <- st_point(c(0,0))
rings <- st_as_sfc(lapply(c(5, 10, 15, 20), function(x){st_buffer(p, dist = x)}))
rings <- st_sf(data.frame(dists = c(5, 10, 15, 20), geometry = rings))
plot(rings)

polygons2rings <- function(poly, rank = poly$dists){
  poly <- poly[order(-rank),]
  geom <- st_geometry(poly)
  for(i in seq(1,length(geom))){
    if(i < length(geom)){
      geom[i] <- st_difference(geom[i], geom[i+1])
    }
  }
  st_geometry(poly) <- geom
  return(poly)
}

res <- polygons2rings(rings)
plot(res)

It requires a rank field that defines the orders of the polygons, I thought about using something like st_within but I think it would be less robust to complex isochrones. Also raised the point that multiple ring buffers are not easy to do in sf, perhaps a case for another function?

mem48 avatar Jun 20 '19 18:06 mem48

See https://github.com/isonoi/isonoi/

Robinlovelace avatar Oct 02 '23 06:10 Robinlovelace