Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More details for geodesic objects #125

Merged
merged 12 commits into from
Dec 29, 2021
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ S3method(wk_handle,wk_wkt)
S3method(wk_handle,wk_xy)
S3method(wk_handle_slice,data.frame)
S3method(wk_handle_slice,default)
S3method(wk_is_geodesic,data.frame)
S3method(wk_is_geodesic,default)
S3method(wk_is_geodesic,wk_rct)
S3method(wk_is_geodesic,wk_wkb)
S3method(wk_is_geodesic,wk_wkt)
S3method(wk_meta,default)
Expand All @@ -239,8 +239,8 @@ S3method(wk_set_crs,sf)
S3method(wk_set_crs,sfc)
S3method(wk_set_crs,wk_rcrd)
S3method(wk_set_crs,wk_vctr)
S3method(wk_set_geodesic,data.frame)
S3method(wk_set_geodesic,default)
S3method(wk_set_geodesic,wk_rct)
S3method(wk_set_geodesic,wk_wkb)
S3method(wk_set_geodesic,wk_wkt)
S3method(wk_trans_inverse,wk_trans_affine)
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Added `wk_crs_longlat()` helper to help promote authority-compliant
CRS choices (#112).
* Added `wk_is_geodesic()`, `wk_set_geodesic()`, and argument `geodesic`
in `wkt()`, `wkb()`, and `rct()` as a flag for objects whose edges must
in `wkt()` and `wkb()` as a flag for objects whose edges must
be interpolated along a spherical/ellipsoidal trajectory (#112).
* Added `sf::st_geometry()` and `sf::st_sfc()` methods for wk geometry
vectors for better integration with sf (#113, #114).
Expand All @@ -24,6 +24,8 @@
* Added `wk_envelope()` and `wk_envelope_handler()` to compute feature-wise
bounding boxes (#120, #122).
* Fixed headers and tests to pass on big endian systems (#105, #122).
* Incorporated the geodesic attribute into vctrs methods, data frame
columns, and bbox/envelope calculation (#124, #125).

# wk 0.5.0

Expand Down
4 changes: 0 additions & 4 deletions R/bbox.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ wk_envelope.default <- function(handleable, ...) {
#' @rdname wk_bbox
#' @export
wk_envelope.wk_rct <- function(handleable, ...) {
if (wk_is_geodesic(handleable)) {
stop("Can't compute envelope for geodesic object", call. = FALSE)
}

handleable
}

Expand Down
16 changes: 16 additions & 0 deletions R/class-data-frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#' @inheritParams wk_translate
#' @inheritParams wk_crs
#' @inheritParams wk_identity
#' @inheritParams wk_is_geodesic
#'
#' @export
#'
Expand Down Expand Up @@ -40,6 +41,21 @@ wk_set_crs.data.frame <- function(x, crs) {
x
}

#' @rdname wk_handle.data.frame
#' @export
wk_is_geodesic.data.frame <- function(x) {
col <- handleable_column_name(x)
wk_is_geodesic(x[[col]])
}

#' @rdname wk_handle.data.frame
#' @export
wk_set_geodesic.data.frame <- function(x, geodesic) {
col <- handleable_column_name(x)
x[[col]] <- wk_set_geodesic(x[[col]], geodesic)
x
}

#' @rdname wk_handle.data.frame
#' @export
wk_restore.data.frame <- function(handleable, result, ...) {
Expand Down
18 changes: 14 additions & 4 deletions R/make.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#' values indicate a new ring. Rings are automatically
#' closed. This is recycled silently as needed.
#' @param geometry_type The collection type to create.
#' @param geodesic Use `TRUE` or `FALSE` to explicitly force
#' the geodesic-ness of the output.
#'
#' @return An object of the same class as `handleable` with
#' whose coordinates have been assembled into the given
Expand All @@ -20,15 +22,19 @@
#' wk_polygon(xy(c(0, 1, 0), c(0, 0, 1)))
#' wk_collection(xy(c(1, 1), c(2, 3)))
#'
wk_linestring <- function(handleable, feature_id = 1L, ...) {
wk_linestring <- function(handleable, feature_id = 1L, ..., geodesic = NULL) {
writer <- wk_writer(handleable, generic = TRUE)
result <- wk_handle(handleable, wk_linestring_filter(writer, as.integer(feature_id)), ...)
wk_set_crs(result, wk_crs(handleable))

wk_crs(result) <- wk_crs(handleable)
wk_is_geodesic(result) <- geodesic %||% wk_is_geodesic(handleable)

result
}

#' @rdname wk_linestring
#' @export
wk_polygon <- function(handleable, feature_id = 1L, ring_id = 1L, ...) {
wk_polygon <- function(handleable, feature_id = 1L, ring_id = 1L, ..., geodesic = NULL) {
writer <- wk_writer(handleable, generic = TRUE)
result <- wk_handle(
handleable,
Expand All @@ -39,7 +45,11 @@ wk_polygon <- function(handleable, feature_id = 1L, ring_id = 1L, ...) {
),
...
)
wk_set_crs(result, wk_crs(handleable))

wk_crs(result) <- wk_crs(handleable)
wk_is_geodesic(result) <- geodesic %||% wk_is_geodesic(handleable)

result
}

#' @rdname wk_linestring
Expand Down