Match spatial points to the vertices of a spatial graph.
Source:R/match-points.R
match_pts_to_verts.Rd
The match_pts_to_graph function matches points to the nearest edge based on geometric intersections; this function only matches to the nearest vertex based on point-to-point distances.
Arguments
- verts
A
data.frame
of vertices obtained fromdodgr_vertices(graph)
.- xy
coordinates of points to be matched to the vertices, either as matrix or sf-formatted
data.frame
.- connected
Should points be matched to the same (largest) connected component of graph? If
FALSE
and these points are to be used for adodgr
routing routine (dodgr_dists, dodgr_paths, or dodgr_flows_aggregate), then results may not be returned if points are not part of the same connected component. On the other hand, forcing them to be part of the same connected component may decrease the spatial accuracy of matching.
See also
Other match:
add_nodes_to_graph()
,
match_points_to_graph()
,
match_points_to_verts()
,
match_pts_to_graph()
Examples
net <- weight_streetnet (hampi, wt_profile = "foot")
verts <- dodgr_vertices (net)
# Then generate some random points to match to 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))
)
pts <- match_pts_to_verts (verts, xy)
pts # an index into verts
#> [1] 3079 1704 1704 3077 2923 1704 3078 2921 3082 2343
pts <- verts$id [pts]
pts # names of those vertices
#> [1] "1388482473" "2588119056" "2588119056" "6597298435" "2398957539"
#> [6] "2588119056" "6597300510" "313796433" "3921525779" "2398957612"