Skip to contents

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.

Usage

map_nearest(source, target, k = 1, max_dist_km = NULL)

Arguments

source

An sf object of points, or a data.frame with lon and lat columns (assumed CRS 4326 / WGS 84).

target

An sf object of candidate point or polygon geometries.

k

Integer. Number of nearest targets to map per source. Defaults to 1; Inf may be used with max_dist_km for a radius search.

max_dist_km

Numeric or NULL. If set, omit targets farther than this distance in kilometres.

Value

A leaflet htmlwidget.

Examples

stations <- retrieve_monitoring_stations_simple()[1:5, ]
map_nearest(stations, retrieve_hive()[1:50, ], k = 3)