These functions smooth the gateway between working with geohashes and geospatial information built for the major geospatial package in R, sf::sf.
gh_to_sf(...)
# Default S3 method
gh_to_sf(geohashes, ...)
# S3 method for class 'data.frame'
gh_to_sf(gh_df, gh_col = "gh", ...)
gh_covering(x, precision = 6L, minimal = FALSE)Arguments for subsequent methods.
character vector of geohashes to be converted to polygons.
data.frame which 1) contains a column of geohashes to be converted to polygons and 2) will
serve as the attribute table of the resultant sf::sf object.
character column name saying where the geohashes are stored in gh_df.
An sf, sfc, or sfg object (from the sf package).
integer specifying the precision of geohashes to use, same as gh_encode()
logical; if FALSE, the output will have all geohashes in the bounding box of x; if
TRUE, any geohashes not intersecting x will be removed.
For gh_to_sf, a sf::sf object.
gh_to_sf relies on the gh_decode() function. Note in particular that this function accepts any length
of geohash (geohash-6, geohash-4, etc.) and is agnostic to potential overlap, though duplicates will be caught
and excluded.
# get the neighborhood of this geohash in downtown Apia as an sf object
downtown = '2jtc5x'
apia_nbhd = unlist(gh_neighbors(downtown))
apia_sf = gh_to_sf(apia_nbhd)
# all geohashes covering a random sampling within Apia:
apia_covering = gh_covering(sf::st_sample(apia_sf, 10L, type = 'random'))
#> Warning: coordinate ranges not computed along great circles; install package lwgeom to get rid of this warning