Created
January 15, 2023 17:11
-
-
Save idshklein/3f4a5aacaa64e7a0c03005a802e37058 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pacman::p_load(tidyverse,sf,sfnetworks,nngeo,tidygraph) | |
options(scipen = 10000) | |
outer = matrix(c(0,0,1000,0,1000,1000,0,1000,0,0),ncol=2, byrow=TRUE) | |
make_grid <- function(street_length){st_polygon(list(outer)) %>% | |
st_make_grid(street_length) %>% | |
st_segments() } | |
x <- 200 | |
map_df(c(2,4,5,8,10,20),~make_grid(1000/.x) %>% | |
st_segmentize(20) %>% | |
st_segments() %>% | |
as_sfnetwork(directed = F) %E>% | |
distinct() %>% | |
st_network_cost() %>% | |
as.vector() %>% | |
data.frame() %>% | |
rename(x = 1) %>% | |
mutate(street_length = 1000/.x)) %>% | |
ggplot(aes(x =x,fill = factor(street_length))) + | |
# geom_density(alpha=.5) | |
geom_histogram() | |
map_df(c(2,4,5,8,10,20),~make_grid(1000/.x) %>% | |
st_segmentize(20) %>% | |
st_segments() %>% | |
as_sfnetwork(directed = F) %E>% | |
distinct() %N>% | |
as_tibble() %>% | |
mutate(street_length = 1000/.x)) %>% | |
ggplot()+ | |
geom_sf() + | |
facet_wrap(~street_length) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment