Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed May 11, 2024
1 parent 017f58b commit 4824e2f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
15 changes: 11 additions & 4 deletions R/geohash.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#' @param precision integer; precision (length) of geohash returned. From the liblwgeom source: ``where the precision is non-positive, a precision based on the bounds of the feature. Big features have loose precision. Small features have tight precision.''
#' @export
#' @details see \url{http://geohash.org/} or \url{https://en.wikipedia.org/wiki/Geohash}.
#' @return character vector with geohashes
#' @return `st_geohash` returns a character vector with geohashes
#'
#' `st_geom_from_geohash` returns a (bounding box) polygon for each geohash if `raw` is `FALSE`, if `raw` is `TRUE` a matrix is returned with bounding box coordinates on each row.
#' @examples
#' library(sf)
#' lwgeom::st_geohash(st_sfc(st_point(c(1.5,3.5)), st_point(c(0,90))), 2)
Expand All @@ -16,18 +18,23 @@ st_geohash = function(x, precision = 0) {
#' @export
#' @name st_geohash
#' @param hash character vector with geohashes
#' @param raw logical; if `TRUE`, return a matrix with bounding box coordinates on each row
#' @param crs object of class `crs`
#' @examples
#' o = options(digits = 20)
#' st_geom_from_geohash(c('9qqj7nmxncgyy4d0dbxqz0', 'u1hzz631zyd63zwsd7zt'))
#' st_geom_from_geohash('9qqj7nmxncgyy4d0dbxqz0', 4)
#' st_geom_from_geohash('9qqj7nmxncgyy4d0dbxqz0', 10)
#' options(o)
st_geom_from_geohash = function(hash, precision = -1, crs = st_crs('OGC:CRS84')) {
st_geom_from_geohash = function(hash, precision = -1, crs = st_crs('OGC:CRS84'), raw = FALSE) {
stopifnot(is.character(hash), is.numeric(precision), length(precision) == 1)
m = CPL_bbox_from_geohash(hash, as.integer(precision))
bb = matrix(m, nrow = 4)
rownames(bb) = c("xmin", "ymin", "xmax", "ymax")
bb = apply(bb, 2, sf::st_bbox, simplify = FALSE)
sf::st_set_crs(do.call(c, lapply(bb, sf::st_as_sfc)), crs)
if (raw)
t(bb)
else {
bb = apply(bb, 2, sf::st_bbox, simplify = FALSE)
sf::st_set_crs(do.call(c, lapply(bb, sf::st_as_sfc)), crs)
}
}
13 changes: 11 additions & 2 deletions man/st_geohash.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4824e2f

Please sign in to comment.