Skip to content

Commit d1ac929

Browse files
authored
Merge pull request #62 from r-spatial/sync-wk
Don't use wk functions that will be removed, minor doc updates
2 parents 9b4d4de + 0cd6d02 commit d1ac929

File tree

6 files changed

+24
-40
lines changed

6 files changed

+24
-40
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ License: Apache License (== 2.0)
2525
Encoding: UTF-8
2626
LazyData: true
2727
Roxygen: list(markdown = TRUE)
28-
RoxygenNote: 7.1.0.9000
28+
RoxygenNote: 7.1.1
2929
LinkingTo:
3030
Rcpp,
3131
wk

NEWS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# s2 (development version)
22

3+
* `s2_*_matrix()` predicates now efficiently use indexing to compute the
4+
results of many predicate comparisons (#61).
35

46
# s2 1.0.0
57

6-
This version is a complete rewrite of the former s2 CRAN package, entirely backwards incompatible with previous versions.
8+
This version is a complete rewrite of the former s2 CRAN package, entirely
9+
backwards incompatible with previous versions.

R/s2-latlng.R

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,12 @@ as_s2_latlng.character <- function(x, ...) {
5858

5959
#' @export
6060
as_s2_latlng.wk_wkt <- function(x, ...) {
61-
meta <- wk::wkt_meta(x)
62-
if (any(meta$type_id != 1)) {
63-
stop("Can't import non-points as s2_latlng")
64-
}
65-
66-
# need matching because empty points do not have a row in
67-
# wk::wk*_coords()
68-
coords <- wk::wkt_coords(x)
69-
coords_match <- match(seq_along(x), coords$feature_id)
70-
new_s2_xptr(s2_latlng_from_numeric(coords$y[coords_match], coords$x[coords_match]), "s2_latlng")
61+
as_s2_latlng(as_s2_geography(x), ...)
7162
}
7263

7364
#' @export
7465
as_s2_latlng.wk_wkb <- function(x, ...) {
75-
meta <- wk::wkb_meta(x)
76-
if (any(meta$type_id != 1)) {
77-
stop("Can't import non-points as s2_latlng")
78-
}
79-
80-
# need matching because empty points do not have a row in
81-
# wk::wk*_coords()
82-
coords <- wk::wkb_coords(x)
83-
coords_match <- match(seq_along(x), coords$feature_id)
84-
new_s2_xptr(s2_latlng_from_numeric(coords$y[coords_match], coords$x[coords_match]), "s2_latlng")
66+
as_s2_latlng(as_s2_geography(x), ...)
8567
}
8668

8769
#' @rdname s2_latlng
@@ -99,15 +81,13 @@ as.matrix.s2_latlng <- function(x, ...) {
9981
#' @importFrom wk as_wkb
10082
#' @export
10183
as_wkb.s2_latlng <- function(x, ..., endian = wk::wk_platform_endian()) {
102-
df <- data_frame_from_s2_latlng(x)
103-
wk::new_wk_wkb(wk::coords_point_translate_wkb(df$lng, df$lat, endian = endian))
84+
as_wkb(as_s2_geography(x), ..., endian = endian)
10485
}
10586

10687
#' @importFrom wk as_wkt
10788
#' @export
10889
as_wkt.s2_latlng <- function(x, ..., precision = 16, trim = TRUE) {
109-
df <- data_frame_from_s2_latlng(x)
110-
wk::new_wk_wkt(wk::coords_point_translate_wkt(df$lng, df$lat, precision = precision, trim = trim))
90+
as_wkt(as_s2_geography(x), ..., precision = precision, trim = trim)
11191
}
11292

11393
#' @export

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@
99
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
1010
![R-CMD-check](https://github.com/r-spatial/s2/workflows/R-CMD-check/badge.svg)
1111
[![codecov](https://codecov.io/gh/r-spatial/s2/branch/master/graph/badge.svg)](https://codecov.io/gh/r-spatial/s2)
12+
[![CRAN](http://www.r-pkg.org/badges/version/s2)](https://cran.r-project.org/package=s2)
1213
<!-- badges: end -->
1314

1415
The goal of s2 is to provide R bindings to Google’s
1516
[S2Geometry](https://s2geometry.io) library. The package exposes an API
1617
similar to Google’s [BigQuery Geography
1718
API](https://cloud.google.com/bigquery/docs/reference/standard-sql/geography_functions),
18-
whose functions also operate on spherical geometries.
19+
whose functions also operate on spherical geometries. This package is a
20+
complete rewrite of an earlier CRAN package s2 with versions up to
21+
0.4-2, for which the sources are found
22+
[here](https://github.com/spatstat/s2/).
1923

2024
## Installation
2125

tests/testthat/test-s2-latlng.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,27 @@ test_that("s2_latlng objects can be created from and converted back to R objects
4040

4141
test_that("s2_latlng can be imported/exported to/from wkb and wkt", {
4242
wkb_point <- wk::as_wkb("POINT (-64 45)")
43-
expect_identical(wk::as_wkb(s2_latlng(45, -64), endian = 1), wkb_point)
44-
expect_identical(wk::as_wkt(s2_latlng(45, -64)), wk::wkt("POINT (-64 45)"))
43+
expect_wkt_equal(wk::as_wkb(s2_latlng(45, -64), endian = 1), wkb_point)
44+
expect_wkt_equal(wk::as_wkt(s2_latlng(45, -64)), wk::wkt("POINT (-64 45)"))
4545
expect_identical(wk::as_wkt(s2_latlng(NA, NA)), wk::wkt("POINT EMPTY"))
4646

4747
expect_equal(
4848
as.data.frame(as_s2_latlng(wk::as_wkb(c("POINT EMPTY", "POINT (-64 45)")))),
4949
data.frame(lat = c(NA, 45), lng = c(NA, -64))
5050
)
5151

52-
expect_identical(
52+
expect_equal(
5353
as.data.frame(as_s2_latlng(c("POINT EMPTY", "POINT (-64 45)"))),
5454
data.frame(lat = c(NA, 45), lng = c(NA, -64))
5555
)
5656

57-
expect_identical(
57+
expect_equal(
5858
as.data.frame(as_s2_latlng(wk::wkt(c("POINT EMPTY", "POINT (-64 45)")))),
5959
data.frame(lat = c(NA, 45), lng = c(NA, -64))
6060
)
6161

62-
expect_error(as_s2_latlng(wk::wkt("LINESTRING EMPTY")), "Can't import non-points")
63-
expect_error(as_s2_latlng(wk::as_wkb("LINESTRING EMPTY")), "Can't import non-points")
62+
expect_error(as_s2_latlng(wk::wkt("LINESTRING EMPTY")), "non-point")
63+
expect_error(as_s2_latlng(wk::as_wkb("LINESTRING EMPTY")), "non-point")
6464
})
6565

6666
test_that("s2_latlng vectors can't have other types of objects concatenated or asssigned", {
@@ -81,7 +81,7 @@ test_that("s2_latlng can be imported from s2_geography", {
8181
test_that("s2_latlng can be imported from wkb", {
8282
wkb_point <- wk::as_wkb("POINT (-64 45)")
8383

84-
expect_identical(
84+
expect_equal(
8585
as.data.frame(as_s2_latlng(wkb_point)),
8686
data.frame(lat = 45, lng = -64)
8787
)

tests/testthat/test-s2-transformers.R

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,9 @@ test_that("s2_snap_to_grid() works", {
311311
})
312312

313313
test_that("s2_buffer() works", {
314-
ply <- s2_buffer_cells("POINT (0 0)", distance = 1, radius = 180 / pi)
315-
box <- wk::wkb_ranges(wk::as_wkb(ply))
316-
expect_near(box$xmin, -1, epsilon = 0.002)
317-
expect_near(box$ymin, -1, epsilon = 0.002)
318-
expect_near(box$xmax, 1, epsilon = 0.002)
319-
expect_near(box$ymax, 1, epsilon = 0.002)
314+
# create a hemisphere!
315+
ply <- s2_buffer_cells("POINT (0 0)", distance = pi / 2, radius = 1)
316+
expect_near(s2_area(ply, radius = 1), 4 * pi / 2, epsilon = 0.1)
320317
})
321318

322319
test_that("real data survives the S2BooleanOperation", {

0 commit comments

Comments
 (0)