table_getNearestDistance: Return distances to nearest known locations

View source: R/table_getNearestDistance.R

table_getNearestDistanceR Documentation

Return distances to nearest known locations

Description

Returns distances between known locations in locationTbl, and a vector of target locations specified by longitude and latitude. Only a single distance to the closest known location is returned for each incoming target location. If no known location is found within distanceThreshold meters for a particular incoming location, that distance in the vector will be NA.

Usage

table_getNearestDistance(
  locationTbl = NULL,
  longitude = NULL,
  latitude = NULL,
  distanceThreshold = NULL,
  measure = c("geodesic", "haversine", "vincenty", "cheap")
)

Arguments

locationTbl

Tibble of known locations.

longitude

Vector of longitudes in decimal degrees E.

latitude

Vector of latitudes in decimal degrees N.

distanceThreshold

Distance in meters.

measure

One of "haversine" "vincenty", "geodesic", or "cheap" specifying desired method of geodesic distance calculation.

See geodist::geodist for details.

Value

Vector of distances from known locations.

Note

The measure "cheap" may be used to speed things up depending on the spatial scale being considered. Distances calculated with measure = "cheap" will vary by a few meters compared with those calculated using measure = "geodesic".

Examples

library(MazamaLocationUtils)

locationTbl <- get(data("wa_monitors_500"))

# Wenatchee
lon <- -120.325278
lat <- 47.423333

# Too small a distanceThreshold will not find a match
table_getNearestDistance(locationTbl, lon, lat, distanceThreshold = 50)

# Expanding the distanceThreshold will find one
table_getNearestDistance(locationTbl, lon, lat, distanceThreshold = 5000)


MazamaLocationUtils documentation built on March 18, 2022, 7:24 p.m.