From 4824e2f5851a8fe2dd52c66cd77b4c70370368d9 Mon Sep 17 00:00:00 2001 From: edzer Date: Sun, 12 May 2024 00:24:48 +0200 Subject: [PATCH] update docs --- R/geohash.R | 15 +++++++++++---- man/st_geohash.Rd | 13 +++++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/R/geohash.R b/R/geohash.R index aa8c7c8..5c98652 100644 --- a/R/geohash.R +++ b/R/geohash.R @@ -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) @@ -16,6 +18,7 @@ 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) @@ -23,11 +26,15 @@ st_geohash = function(x, precision = 0) { #' 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) + } } diff --git a/man/st_geohash.Rd b/man/st_geohash.Rd index 8953789..959642c 100644 --- a/man/st_geohash.Rd +++ b/man/st_geohash.Rd @@ -7,7 +7,12 @@ \usage{ st_geohash(x, precision = 0) -st_geom_from_geohash(hash, precision = -1, crs = st_crs("OGC:CRS84")) +st_geom_from_geohash( + hash, + precision = -1, + crs = st_crs("OGC:CRS84"), + raw = FALSE +) } \arguments{ \item{x}{object of class \code{sf}, \code{sfc} or \code{sfg}} @@ -17,9 +22,13 @@ st_geom_from_geohash(hash, precision = -1, crs = st_crs("OGC:CRS84")) \item{hash}{character vector with geohashes} \item{crs}{object of class `crs`} + +\item{raw}{logical; if `TRUE`, return a matrix with bounding box coordinates on each row} } \value{ -character vector with geohashes +`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. } \description{ compute geohash from (average) coordinates