match_pts_to_graph | R Documentation |
Match spatial points to the edges of a spatial graph, through finding the
edge with the closest perpendicular intersection. NOTE: Intersections are
calculated geometrically, and presume planar geometry. It is up to users of
projected geometrical data, such as those within a dodgr_streetnet
object,
to ensure that either: (i) Data span an sufficiently small area that errors
from presuming planar geometry may be ignored; or (ii) Data are re-projected
to an equivalent planar geometry prior to calling this routine.
match_pts_to_graph(graph, xy, connected = FALSE, distances = FALSE)
graph |
A |
xy |
coordinates of points to be matched to the vertices, either as
matrix or sf-formatted |
connected |
Should points be matched to the same (largest) connected
component of graph? If |
distances |
If |
For distances = FALSE
(default), a vector index matching the xy
coordinates to nearest edges. For bi-directional edges, only one match is
returned, and it is up to the user to identify and suitably process matching
edge pairs. For 'distances = TRUE', a 'data.frame' of four columns:
"index" The index of closest edges in "graph", as described above.
"d_signed" The perpendicular distance from ech point to the nearest edge, with negative distances denoting points to the left of edges, and positive distances denoting points to the right. Distances of zero denote points lying precisely on the line of an edge (potentially including cases where nearest point of bisection lies beyond the actual edge).
"x" The x-coordinate of the point of intersection.
"y" The y-coordinate of the point of intersection.
Other match:
add_nodes_to_graph()
,
match_points_to_graph()
,
match_points_to_verts()
,
match_pts_to_verts()
graph <- weight_streetnet (hampi, wt_profile = "foot")
# Then generate some random points to match to graph
verts <- dodgr_vertices (graph)
npts <- 10
xy <- data.frame (
x = min (verts$x) + runif (npts) * diff (range (verts$x)),
y = min (verts$y) + runif (npts) * diff (range (verts$y))
)
edges <- match_pts_to_graph (graph, xy)
graph [edges, ] # The edges of the graph closest to `xy`
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.