Create a location ID for each longitude/latitude pair using a geohash.

createLocationID(
  longitude = NULL,
  latitude = NULL,
  precision = 10,
  algorithm = c("geohash", "digest"),
  invalidID = as.character(NA)
)

Arguments

longitude

Vector of longitudes in decimal degrees east.

latitude

Vector of latitudes in decimal degrees north.

precision

Precision used when encoding geohashes.

algorithm

Encoding algorithm to use. Only "geohash" is currently supported. "digest" is deprecated and will generate an error.

invalidID

Identifier to use for invalid locations. This can be a character string or NA.

Value

Character vector of location IDs.

Details

Each location ID is unique within a geohash grid cell. The precision argument determines the size of the grid cell. At the equator, approximate grid cell widths are:


precision   maximum grid cell width
        5   ~ 4.9 km
        6   ~ 1.2 km
        7   ~ 153 m
        8   ~ 38 m
        9   ~ 4.8 m
       10   ~ 1.2 m

Invalid locations are assigned the value specified by invalidID, typically NA.

Examples

longitude <- c(-122.5, 0, NA, -122.5, -122.5)
latitude <- c(47.5, 0, 47.5, NA, 47.5)

createLocationID(longitude, latitude)
#> [1] "c22yhrn5x1" "s000000000" NA           NA           "c22yhrn5x1"
createLocationID(longitude, latitude, precision = 7)
#> [1] "c22yhrn" "s000000" NA        NA        "c22yhrn"
createLocationID(longitude, latitude, invalidID = "bad")
#> [1] "c22yhrn5x1" "s000000000" "bad"        "bad"        "c22yhrn5x1"