Create a network from a collection of line strings.
Arguments
- edges
A data frame with the network edges
- flatten
Whether all intersections between edges should be converted to nodes
- clean
Whether general cleaning tasks should be run on the generated network (see
clean_network()
for the description of tasks)
Examples
edges <- sf::st_sfc(
sf::st_linestring(matrix(c(0, 0, 1, 1), ncol = 2, byrow = TRUE)),
sf::st_linestring(matrix(c(0, 1, 1, 0), ncol = 2, byrow = TRUE))
)
sf::st_crs(edges) <- sf::st_crs("EPSG:4326")
as_network(edges)
#> although coordinates are longitude/latitude, st_crosses assumes that they are
#> planar
#> although coordinates are longitude/latitude, st_intersection assumes that they
#> are planar
#> # A sfnetwork with 5 nodes and 4 edges
#> #
#> # CRS: EPSG:4326
#> #
#> # An unrooted tree with spatially explicit edges
#> #
#> # Node data: 5 × 1 (active)
#> x
#> <POINT [°]>
#> 1 (0 0)
#> 2 (0.5 0.5)
#> 3 (1 1)
#> 4 (0 1)
#> 5 (1 0)
#> #
#> # Edge data: 4 × 3
#> from to x
#> <int> <int> <LINESTRING [°]>
#> 1 2 3 (0.5 0.5, 1 1)
#> 2 2 4 (0 1, 0.5 0.5)
#> 3 1 2 (0 0, 0.5 0.5)
#> # ℹ 1 more row