Created
August 11, 2022 14:26
-
-
Save idshklein/749848c3114760c569c0c6cb05ee141d 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,sfdep,sfnetworks,waywiser,tidygraph) | |
nc = st_read(system.file("shape/nc.shp", package="sf")) | |
# waywiser- only polygons | |
waywiser::ww_build_neighbors(nc) | |
# sfnetworks - neighboring points connected by edges | |
st_intersects(nc,nc) %>% | |
imap_dfr(~data.frame(from=.y,to=.x)) %>% | |
filter(from!=to) %>% | |
as_tbl_graph() %>% | |
left_join(st_centroid(nc) %>% mutate(rn=row_number() %>% as.character()),by=c("name"="rn")) %>% | |
as_sfnetwork() | |
# both have 490 links/edges |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Created on 2022-08-16 by the reprex package (v2.0.1)