sfnetwork | R Documentation |
sfnetwork
is a tidy data structure for geospatial networks. It
extends the tbl_graph
data structure for
relational data into the domain of geospatial networks, with nodes and
edges embedded in geographical space, and offers smooth integration with
sf
for spatial data analysis.
sfnetwork(
nodes,
edges = NULL,
directed = TRUE,
node_key = "name",
edges_as_lines = NULL,
compute_length = FALSE,
length_as_weight = deprecated(),
force = FALSE,
message = TRUE,
...
)
nodes |
The nodes of the network. Should be an object of class
|
edges |
The edges of the network. May be an object of class
|
directed |
Should the constructed network be directed? Defaults to
|
node_key |
The name of the column in the nodes table that character
represented |
edges_as_lines |
Should the edges be spatially explicit, i.e. have
|
compute_length |
Should the geographic length of the edges be stored in
a column named |
length_as_weight |
Deprecated, use |
force |
Should network validity checks be skipped? Defaults to
|
message |
Should informational messages (those messages that are
neither warnings nor errors) be printed when constructing the network?
Defaults to |
... |
Arguments passed on to |
An object of class sfnetwork
.
library(sf, quietly = TRUE)
p1 = st_point(c(7, 51))
p2 = st_point(c(7, 52))
p3 = st_point(c(8, 52))
nodes = st_as_sf(st_sfc(p1, p2, p3, crs = 4326))
e1 = st_cast(st_union(p1, p2), "LINESTRING")
e2 = st_cast(st_union(p1, p3), "LINESTRING")
e3 = st_cast(st_union(p3, p2), "LINESTRING")
edges = st_as_sf(st_sfc(e1, e2, e3, crs = 4326))
edges$from = c(1, 1, 3)
edges$to = c(2, 3, 2)
# Default.
sfnetwork(nodes, edges)
# Undirected network.
sfnetwork(nodes, edges, directed = FALSE)
# Using character encoded from and to columns.
nodes$name = c("city", "village", "farm")
edges$from = c("city", "city", "farm")
edges$to = c("village", "farm", "village")
sfnetwork(nodes, edges, node_key = "name")
# Spatially implicit edges.
sfnetwork(nodes, edges, edges_as_lines = FALSE)
# Store edge lenghts in a column named 'length'.
sfnetwork(nodes, edges, compute_length = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.