Since sfnetwork
objects inherit igraph
objects, any igraph function can be called on a sfnetwork. However, if this
function returns a network, it will be an igraph object rather than a
sfnetwork object. With wrap_igraph
, such a function will
preserve the sfnetwork class, after checking if the network returned by
igraph still has a valid spatial network structure.
Arguments
- .data
An object of class
sfnetwork
.- .f
An function from the
igraph
package that accepts a graph as its first argument, and returns a graph.- ...
Arguments passed on to
.f
.- .force
Should network validity checks be skipped? Defaults to
FALSE
, meaning that network validity checks are executed when returning the new network. These checks guarantee a valid spatial network structure. For the nodes, this means that they all should havePOINT
geometries. In the case of spatially explicit edges, it is also checked that all edges haveLINESTRING
geometries, nodes and edges have the same CRS and boundary points of edges match their corresponding node coordinates. These checks are important, but also time consuming. If you are already sure your input data meet the requirements, the checks are unnecessary and can be turned off to improve performance.- .message
Should informational messages (those messages that are neither warnings nor errors) be printed when constructing the network? Defaults to
TRUE
.
Value
An object of class sfnetwork
.
Examples
oldpar = par(no.readonly = TRUE)
par(mar = c(1,1,1,1), mfrow = c(1,2))
net = as_sfnetwork(mozart, "delaunay", directed = FALSE)
mst = wrap_igraph(net, igraph::mst, .message = FALSE)
mst
#> # A sfnetwork: 17 nodes and 16 edges
#> #
#> # An unrooted tree with spatially explicit edges
#> #
#> # Dimension: XY
#> # Bounding box: xmin: 4548664 ymin: 2747309 xmax: 4549589 ymax: 2748537
#> # Projected CRS: ETRS89-extended / LAEA Europe
#> #
#> # Node data: 17 × 4 (active)
#> name type website geometry
#> <chr> <chr> <chr> <POINT [m]>
#> 1 Mozartkino cinema https://www.mozartki… (4549504 2747309)
#> 2 Haus für Mozart theatre NA (4549003 2747376)
#> 3 Mozartsteg/Rudolfskai bus_stop NA (4549589 2747507)
#> 4 Mozart Denkmal artwork NA (4549387 2747514)
#> 5 Mozartsteg/Rudolfskai bus_stop NA (4549491 2747551)
#> 6 Mozartsteg bridge NA (4549473 2747624)
#> # ℹ 11 more rows
#> #
#> # Edge data: 16 × 3
#> from to geometry
#> <int> <int> <LINESTRING [m]>
#> 1 1 2 (4549504 2747309, 4549003 2747376)
#> 2 1 3 (4549504 2747309, 4549589 2747507)
#> 3 1 4 (4549504 2747309, 4549387 2747514)
#> # ℹ 13 more rows
plot(net)
plot(mst)
par(oldpar)