Combines nearest() with map_layers() to show source points, the targets
matched to them, and a connector line for every match. Only matched targets
are drawn. If no target is within max_dist_km, the returned map contains
the source points without target or connector layers.
Arguments
- source
An
sfobject of points, or adata.framewithlonandlatcolumns (assumed CRS 4326 / WGS 84).- target
An
sfobject of candidate point or polygon geometries.- k
Integer. Number of nearest targets to map per source. Defaults to
1;Infmay be used withmax_dist_kmfor a radius search.- max_dist_km
Numeric or
NULL. If set, omit targets farther than this distance in kilometres.
Examples
stations <- retrieve_monitoring_stations_simple()[1:5, ]
map_nearest(stations, retrieve_hive()[1:50, ], k = 3)