Create a spatial network from linestring geometries
Arguments
- x
- directed
Should the constructed network be directed? Defaults to
TRUE
.- compute_length
Should the geographic length of the edges be stored in a column named
length
? Usesst_length
to compute the length of the edge geometries. If there is already a column namedlength
, it will be overwritten. Please note that the values in this column are not automatically recognized as edge weights. This needs to be specified explicitly when calling a function that uses edge weights. Defaults toFALSE
.- subdivide
Should the given linestring geometries be subdivided at locations where an interior point is equal to an interior or boundary point in another feature? This will connect the features at those locations. Defaults to
FALSE
, meaning that features are only connected at their boundaries.
Value
An object of class sfnetwork
.
Details
It is assumed that the given linestring geometries form the edges in the network. Nodes are created at the line boundaries. Shared boundaries between multiple linestrings become the same node.
Note
By default sfnetworks rounds coordinates to 12 decimal places to
determine spatial equality. You can influence this behavior by explicitly
setting the precision of the linestrings using
st_set_precision
.
Examples
library(sf, quietly = TRUE)
oldpar = par(no.readonly = TRUE)
par(mar = c(1,1,1,1), mfrow = c(1,2))
net = as_sfnetwork(roxel)
net
#> # A sfnetwork: 987 nodes and 1215 edges
#> #
#> # A directed multigraph with 9 components and spatially explicit edges
#> #
#> # Dimension: XY
#> # Bounding box: xmin: 7.522595 ymin: 51.94151 xmax: 7.546705 ymax: 51.96119
#> # Geodetic CRS: WGS 84
#> #
#> # Node data: 987 × 1 (active)
#> geometry
#> <POINT [°]>
#> 1 (7.538109 51.95286)
#> 2 (7.537867 51.95282)
#> 3 (7.537815 51.95867)
#> 4 (7.537015 51.95848)
#> 5 (7.533441 51.95578)
#> 6 (7.533415 51.95561)
#> # ℹ 981 more rows
#> #
#> # Edge data: 1,215 × 5
#> from to name type geometry
#> <int> <int> <chr> <chr> <LINESTRING [°]>
#> 1 1 2 Hagemanns Kämpken residential (7.538109 51.95286, 7.537867 51.95…
#> 2 3 4 Stiegkamp residential (7.537815 51.95867, 7.537015 51.95…
#> 3 5 6 Havixbecker Straße residential (7.533441 51.95578, 7.533467 51.95…
#> # ℹ 1,212 more rows
plot(st_geometry(roxel))
plot(net)
par(oldpar)