Skip to content

Connect nodes based on proximity #205

Answered by agila5
luukvdmeer asked this question in Q&A
Discussion options

You must be logged in to vote

Hi! My proposal:

# packages
library(tidygraph)
library(sf)
library(sfnetworks)

# data
pts = st_centroid(roxel[1:10, ])
#> Warning in st_centroid.sf(roxel[1:10, ]): st_centroid assumes attributes are
#> constant over geometries of x

# Compute adj list
(adj = st_is_within_distance(pts, dist = 250))
#> Sparse geometry binary predicate list of length 10, where the predicate
#> was `is_within_distance'
#>  1: 1, 2
#>  2: 1, 2, 3
#>  3: 2, 3
#>  4: 4, 5, 7, 8, 9, 10
#>  5: 4, 5, 7, 8
#>  6: 6, 9, 10
#>  7: 4, 5, 7, 8, 9, 10
#>  8: 4, 5, 7, 8
#>  9: 4, 6, 7, 9, 10
#>  10: 4, 6, 7, 9, 10

# build edges table
edges <- data.frame(
  from = rep(seq_along(adj), times = lengths(adj)), 
  to = unlist(a…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by luukvdmeer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants