Calculate distances between all locations within a known locations table and return a tibble containing all records that have an adjacent location separated by less than distanceThreshold meters. The return tibble is ordered by separation distance.

It is useful when working with new metadata tables to identify adjacent locations early on so that decisions can be made about the appropriateness of the specified distanceThreshold.

table_findAdjacentLocations(
  locationTbl = NULL,
  distanceThreshold = NULL,
  measure = c("geodesic", "haversine", "vincenty", "cheap")
)

Arguments

locationTbl

Tibble of known locations.

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

Tibble of known locations separated by less than distanceThreshold meters.

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)

meta <- wa_airfire_meta

# Any locations closer than 2 km?
meta %>%
  table_findAdjacentLocations(distanceThreshold = 2000) %>%
  dplyr::select(AQSID, timezone)
#> # A tibble: 0 × 2
#> # ℹ 2 variables: AQSID <chr>, timezone <chr>

# How about 4 km?
meta %>%
  table_findAdjacentLocations(distanceThreshold = 4000) %>%
  dplyr::select(AQSID, timezone)
#> # A tibble: 6 × 2
#>   AQSID     timezone           
#>   <chr>     <chr>              
#> 1 530330080 America/Los_Angeles
#> 2 530330057 America/Los_Angeles
#> 3 530330030 America/Los_Angeles
#> 4 530050003 America/Los_Angeles
#> 5 530050002 America/Los_Angeles
#> 6 530331011 America/Los_Angeles