Skip to contents

A spatial network specific bounding box creator, returning the combined bounding box of the nodes and edges in the network.

Usage

st_network_bbox(x, ...)

Arguments

x

An object of class sfnetwork.

...

Arguments passed on to st_bbox.

Value

The bounding box of the network as an object of class bbox.

Details

See st_bbox for details.

Examples

library(sf, quietly = TRUE)

oldpar = par(no.readonly = TRUE)
par(mar = c(1,1,1,1), mfrow = c(1,2))

# Create a network.
n1 = st_point(c(8, 51))
n2 = st_point(c(7, 51.5))
n3 = st_point(c(8, 52))
n4 = st_point(c(9, 51))
e1 = st_sfc(st_linestring(c(n1, n2, n3)))

nodes = st_as_sf(c(st_sfc(n1), st_sfc(n3), st_sfc(n4)))

edges = st_as_sf(e1)
edges$from = 1
edges$to = 2

net = sfnetwork(nodes, edges)
#> → Checking node geometry types ...
#>  All nodes have geometry type POINT
#> → Checking edge geometry types ...
#>  All edges have geometry type LINESTRING
#> → Checking coordinate reference system equality ...
#>  Nodes and edges have the same crs
#> → Checking coordinate precision equality ...
#>  Nodes and edges have the same precision
#> → Checking if geometries match ...
#>  Node locations match edge boundaries
#>  Spatial network structure is valid

# Create bounding boxes for nodes, edges and the whole network.
node_bbox = st_bbox(activate(net, "nodes"))
node_bbox
#> xmin ymin xmax ymax 
#>    8   51    9   52 
edge_bbox = st_bbox(activate(net, "edges"))
edge_bbox
#> xmin ymin xmax ymax 
#>    7   51    8   52 
net_bbox = st_network_bbox(net)
net_bbox
#> xmin ymin xmax ymax 
#>    7   51    9   52 

# Plot.
plot(net, lwd = 2, cex = 4, main = "Element bounding boxes")
plot(st_as_sfc(node_bbox), border = "orange", lty = 2, lwd = 4, add = TRUE)
plot(st_as_sfc(edge_bbox), border = "skyblue", lty = 2, lwd = 4, add = TRUE)

plot(net, lwd = 2, cex = 4, main = "Network bounding box")
plot(st_as_sfc(net_bbox), border = "orange", lty = 2, lwd = 4, add = TRUE)


par(oldpar)