st_network_blend | R Documentation |
Blending a point into a network is the combined process of first projecting the point onto its nearest point on its nearest edge in the network, then subdividing that edge at the location of the projected point, and finally adding the projected point as node to the network. If the location of the projected point is equal an existing node in the network, the attributes of the point will be joined to that node, instead of adding a new node.
st_network_blend(x, y, tolerance = Inf, ignore_duplicates = TRUE)
x |
An object of class |
y |
The spatial features to be blended, either as object of class
|
tolerance |
The tolerance distance to be used. Only features that are
at least as close to the network as the tolerance distance will be blended.
Should be a non-negative number preferably given as an object of class
|
ignore_duplicates |
If there are multiple points in |
When the projected location of a given point intersects with more
than one edge, it is only blended into the first of these edges. Edges are
not connected at blending locations. Use the spatial morpher
to_spatial_subdivision
for that.
To determine if a projected point is equal to an existing node, and to
determine if multiple projected points are equal to each other, sfnetworks
by default rounds coordinates to 12 decimal places. You can influence this
behavior by explicitly setting the precision of the network using
st_set_precision
.
The blended network as an object of class sfnetwork
.
Due to internal rounding of rational numbers, it may occur that the intersection point between a line and a point is not evaluated as actually intersecting that line by the designated algorithm. Instead, the intersection point lies a tiny-bit away from the edge. Therefore, it is recommended to set the tolerance to a very small number (for example 1e-5) even if you only want to blend points that intersect an edge.
library(sf, quietly = TRUE)
oldpar = par(no.readonly = TRUE)
par(mar = c(1,1,1,1), mfrow = c(1,2))
# Create a spatial network.
n1 = st_point(c(0, 0))
n2 = st_point(c(1, 0))
n3 = st_point(c(2, 0))
e1 = st_sfc(st_linestring(c(n1, n2)), crs = 3857)
e2 = st_sfc(st_linestring(c(n2, n3)), crs = 3857)
net = as_sfnetwork(c(e1, e2))
# Create spatial points to blend in.
p1 = st_sfc(st_point(c(0.5, 0.1)))
p2 = st_sfc(st_point(c(0.5, -0.2)))
p3 = st_sfc(st_point(c(1, 0.2)))
p4 = st_sfc(st_point(c(1.75, 0.2)))
p5 = st_sfc(st_point(c(1.25, 0.1)))
pts = st_sf(foo = letters[1:5], geometry = c(p1, p2, p3, p4, p5), crs = 3857)
# Blend all points into the network.
b1 = st_network_blend(net, pts)
b1
plot(net)
plot(st_geometry(pts), pch = 20, col = "orange", add = TRUE)
plot(b1)
plot(st_geometry(pts), pch = 20, col = "orange", add = TRUE)
# Blend points within a tolerance distance.
tol = units::set_units(0.1, "m")
b2 = st_network_blend(net, pts, tolerance = tol)
b2
plot(net)
plot(st_geometry(pts), pch = 20, col = "orange", add = TRUE)
plot(b2)
plot(st_geometry(pts), pch = 20, col = "orange", add = TRUE)
# Add points with duplicated projected location as isolated nodes.
b3 = st_network_blend(net, pts, ignore_duplicates = FALSE)
b3
par(oldpar)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.