Skip to content

Commit

Permalink
closes #93
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Oct 15, 2024
1 parent 304022f commit a96f95b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ Collate:
geod.R
wkt.R
wrap_x.R
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
9 changes: 7 additions & 2 deletions R/geohash.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
#' @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 `st_geohash` returns a character vector with geohashes
#' @return `st_geohash` returns a character vector with geohashes; empty or full geometries result in `NA`
#'
#' `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)
#' lwgeom::st_geohash(st_sfc(st_point(c(1.5,3.5)), st_point(c(0,90))), 10)
st_geohash = function(x, precision = 0) {
CPL_geohash(st_geometry(x), precision)
x = st_geometry(x)
ret = vector("character", length(x))
is_na = st_is_empty(x) | st_is_full(x)
ret[is_na] = NA_character_
ret[!is_na] = CPL_geohash(x[!is_na], precision)
ret
}

#' @export
Expand Down
2 changes: 1 addition & 1 deletion 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 a96f95b

Please sign in to comment.