| geohash_fwd | R Documentation |
Convert geographic coordinates (longitude/latitude) to Geohash strings, or convert Geohash strings back to coordinates.
geohash_fwd(x, len = 12L)
geohash_rev(geohash)
geohash_resolution(len)
geohash_length(resolution = NULL, lat_resolution = NULL, lon_resolution = NULL)
x |
A two-column matrix or data frame of coordinates (longitude, latitude) in decimal degrees, or a list with longitude and latitude components. Can also be a length-2 numeric vector for a single point. |
len |
Integer specifying the length of the Geohash string (1-18). Default is 12, which gives approximately 19mm precision. Can be a vector to specify different lengths for each point. |
geohash |
Character vector of Geohash strings to convert back to coordinates. |
resolution |
Numeric. Desired resolution in degrees for |
lat_resolution |
Numeric. Desired latitude resolution in degrees. |
lon_resolution |
Numeric. Desired longitude resolution in degrees. |
Geohash is a geocoding system that encodes geographic coordinates into a short string of letters and digits. It has a useful property: truncating a Geohash reduces precision but the truncated code still refers to a location containing the original point.
The Geohash length determines precision:
Length 1: ~5000 km
Length 4: ~20 km
Length 6: ~610 m
Length 8: ~19 m
Length 10: ~0.6 m
Length 12: ~19 mm (default)
Length 18: ~0.0001 mm (maximum)
Both geohash_fwd() and geohash_rev() are fully vectorized.
geohash_fwd(): Character vector of Geohash strings.
geohash_rev(): Data frame with columns:
lon: Longitude in decimal degrees (center of cell)
lat: Latitude in decimal degrees (center of cell)
len: Length of the Geohash string
lat_resolution: Latitude resolution in degrees (half-height of cell)
lon_resolution: Longitude resolution in degrees (half-width of cell)
geohash_resolution(): Data frame with columns:
len: Geohash length
lat_resolution: Latitude resolution in degrees
lon_resolution: Longitude resolution in degrees
geohash_length(): Integer, minimum Geohash length to achieve the
specified resolution.
mgrs_fwd() for Military Grid Reference System encoding,
which provides a different grid-based coordinate system.
# Single point conversion
(gh <- geohash_fwd(c(147.325, -42.881)))
geohash_rev(gh)
# Multiple points with varying precision
pts <- cbind(
lon = c(147, -74, 0),
lat = c(-42, 40.7, 51.5)
)
geohash_fwd(pts, len = c(6, 8, 12))
# Truncation preserves containment
gh <- geohash_fwd(c(147.325, -42.881), len = 12)
substr(gh, 1, 6) # Lower precision, but still contains original point
# Resolution for different lengths
geohash_resolution(1:12)
# Find length needed for ~1km precision
geohash_length(1/111) # ~1 degree / 111 km
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.