stplanr
stplanr copied to clipboard
Isochrone circles to dohnuts
trafficstars
Idea: credit @mem48
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?
See https://github.com/isonoi/isonoi/