Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

st_network_join

Join two spatial networks based on equality of node geometries


Description

A spatial network specific join function which makes a spatial full join on the geometries of the nodes data, based on the st_equals spatial predicate. Edge data are combined using a bind_rows semantic, meaning that data are matched by column name and values are filled with NA if missing in either of the networks. The from and to columns in the edge data are updated such that they match the new node indices of the resulting network.

Usage

st_network_join(x, y, ...)

Arguments

x

An object of class sfnetwork.

y

An object of class sfnetwork, or directly convertible to it using as_sfnetwork.

...

Arguments passed on to graph_join.

Value

The joined networks as an object of class sfnetwork.

Examples

library(sf, quietly = TRUE)

node1 = st_point(c(0, 0))
node2 = st_point(c(1, 0))
node3 = st_point(c(1,1))
node4 = st_point(c(0,1))
edge1 = st_sfc(st_linestring(c(node1, node2)))
edge2 = st_sfc(st_linestring(c(node2, node3)))
edge3 = st_sfc(st_linestring(c(node3, node4)))

net1 = as_sfnetwork(c(edge1, edge2))
net2 = as_sfnetwork(c(edge2, edge3))

joined = st_network_join(net1, net2)
joined

## Plot results.
oldpar = par(no.readonly = TRUE)
par(mar = c(1,1,1,1), mfrow = c(1,2))
plot(net1, pch = 15, cex = 2, lwd = 4)
plot(net2, col = "red", pch = 18, cex = 2, lty = 3, lwd = 4, add = TRUE)
plot(joined, cex = 2, lwd = 4)
par(oldpar)

sfnetworks

Tidy Geospatial Networks

v0.5.1
Apache License (>= 2)
Authors
Lucas van der Meer [aut, cre] (<https://orcid.org/0000-0001-6336-8628>), Lorena Abad [aut] (<https://orcid.org/0000-0003-0554-734X>), Andrea Gilardi [aut] (<https://orcid.org/0000-0002-9424-7439>), Robin Lovelace [aut] (<https://orcid.org/0000-0001-5679-6536>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.