# packages
library(sf)
#> Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(sfnetworks)
# create network
roxel_sfn <- as_sfnetwork(roxel, directed = FALSE)
# sample two points in that area
my_points <- st_sample(st_as_sfc(st_bbox(roxel)), size = 2)
#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
# shortest paths
st_network_paths(
x = roxel_sfn,
from = my_points[1],
to = my_points[2]
)
#> although coordinates are longitude/latitude, st_nearest_points assumes that they are planar
#> although coordinates are longitude/latitude, st_nearest_points assumes that they are planar
#> Registered S3 method overwritten by 'cli':
#> method from
#> print.boxx spatstat.geom
#> # A tibble: 1 x 2
#> node_paths edge_paths
#> <list> <list>
#> 1 <int [24]> <int [23]>
# shortest paths
suppressMessages(st_network_paths(
x = roxel_sfn,
from = my_points[1],
to = my_points[2]
))
#> # A tibble: 1 x 2
#> node_paths edge_paths
#> <list> <list>
#> 1 <int [24]> <int [23]>
Created on 2021-04-10 by the reprex package (v1.0.0)