Learn R Programming

MazamaCoreUtils (version 0.6.2)

createLocationID: Create one or more unique location IDs

Description

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

Usage

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

Value

Character vector of location IDs.

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.

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.

References

https://michaelchirico.github.io/geohashTools/index.html

Examples

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

createLocationID(longitude, latitude)
createLocationID(longitude, latitude, precision = 7)
createLocationID(longitude, latitude, invalidID = "bad")

Run the code above in your browser using DataLab