Skip to content

Commit

Permalink
Merge pull request #48 from anthonynorth/main
Browse files Browse the repository at this point in the history
Rename proj_create() to proj_trans_create()
  • Loading branch information
anthonynorth authored Jan 14, 2024
2 parents aec58af + 92eba3e commit e5cc06f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
S3method(print,proj_trans)
S3method(wk_trans_inverse,proj_trans)
export(ok_proj6)
export(proj_create)
export(proj_crs_text)
export(proj_trans)
export(proj_trans_create)
export(proj_version)
importFrom(lifecycle,deprecated)
importFrom(wk,wk_trans_inverse)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

* PROJ >= 6 is now a hard dependency (#42)
* Deprecate ok_proj6() (#42)
* Add {wk} transformer api (#44, #46)
* Add {wk} transformer api (#44, #46, #48)

# PROJ 0.4.5

Expand Down
8 changes: 4 additions & 4 deletions R/wk-trans.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
#' Creates a transformation object that transforms coordinates in a {wk}
#' pipeline.
#'
#' @name proj_create
#' @name proj_trans_create
#' @inheritParams wk::wk_trans_set
#' @param source_crs,target_crs Source/Target CRS definition, coerced with [wk::wk_crs_proj_definition()]
#' @return A PROJ transformation object
#'
#' @examples
#' (trans <- proj_create("OGC:CRS84", "EPSG:3857"))
#' (trans <- proj_trans_create("OGC:CRS84", "EPSG:3857"))
#' wk::wk_transform(wk::xy(1:5, 1:5), trans)
#'
#' library(wk)
Expand All @@ -20,7 +20,7 @@
#' wk::wk_transform(wk::xy(c(-h * 180, 0, h * 180), c(-h * 180,0, h * 180)), invtrans)
#'
#' @export
proj_create <- function(source_crs, target_crs, use_z = NA, use_m = NA) {
proj_trans_create <- function(source_crs, target_crs, use_z = NA, use_m = NA) {
source_crs <- wk::wk_crs_proj_definition(source_crs)
target_crs <- wk::wk_crs_proj_definition(target_crs)

Expand All @@ -30,7 +30,7 @@ proj_create <- function(source_crs, target_crs, use_z = NA, use_m = NA) {
stopifnot(is.logical(use_z) && is.logical(use_m))

trans <- .Call(
C_proj_trans_new,
C_proj_trans_create,
source_crs,
target_crs,
use_z[1],
Expand Down
8 changes: 4 additions & 4 deletions man/proj_create.Rd → man/proj_trans_create.Rd

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

4 changes: 2 additions & 2 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
/* Section generated by pkgbuild, do not edit */
/* .Call calls */
extern SEXP C_proj_crs_text(void *, void *);
extern SEXP C_proj_trans_create(void *, void *, void *, void *);
extern SEXP C_proj_trans_fmt(void *);
extern SEXP C_proj_trans_inverse(void *);
extern SEXP C_proj_trans_list(void *, void *, void *);
extern SEXP C_proj_trans_new(void *, void *, void *, void *);
extern SEXP C_proj_trans_xy(void *, void *, void *, void *);
extern SEXP C_proj_version(void);

static const R_CallMethodDef CallEntries[] = {
{"C_proj_crs_text", (DL_FUNC) &C_proj_crs_text, 2},
{"C_proj_trans_create", (DL_FUNC) &C_proj_trans_create, 4},
{"C_proj_trans_fmt", (DL_FUNC) &C_proj_trans_fmt, 1},
{"C_proj_trans_inverse", (DL_FUNC) &C_proj_trans_inverse, 1},
{"C_proj_trans_list", (DL_FUNC) &C_proj_trans_list, 3},
{"C_proj_trans_new", (DL_FUNC) &C_proj_trans_new, 4},
{"C_proj_trans_xy", (DL_FUNC) &C_proj_trans_xy, 4},
{"C_proj_version", (DL_FUNC) &C_proj_version, 0},
{NULL, NULL, 0}
Expand Down
2 changes: 1 addition & 1 deletion src/wk-trans.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static wk_trans_t* wk_trans_from_xptr(SEXP trans_xptr) {
return trans;
}

SEXP C_proj_trans_new(SEXP source_crs, SEXP target_crs, SEXP use_z, SEXP use_m) {
SEXP C_proj_trans_create(SEXP source_crs, SEXP target_crs, SEXP use_z, SEXP use_m) {
wk_trans_t* trans = wk_trans_create();

trans->trans = &transform;
Expand Down
44 changes: 22 additions & 22 deletions tests/testthat/test-wk-trans.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
test_that("proj_create() works", {
expect_type(proj_create("OGC:CRS84", "EPSG:3857"), "externalptr")
expect_s3_class(proj_create("OGC:CRS84", "EPSG:3857"), "proj_trans")
test_that("proj_trans_create() works", {
expect_type(proj_trans_create("OGC:CRS84", "EPSG:3857"), "externalptr")
expect_s3_class(proj_trans_create("OGC:CRS84", "EPSG:3857"), "proj_trans")
})

test_that("proj_trans print method works", {
crs_to_crs <- proj_create("OGC:CRS84", "EPSG:3857")
crs_to_crs <- proj_trans_create("OGC:CRS84", "EPSG:3857")
str <- capture_output(print(crs_to_crs))

expect_match(str, "<proj_trans at .*>")
Expand All @@ -21,33 +21,33 @@ test_that("proj_trans print doesn't crash on invalid input", {
expect_error(.Call(C_proj_trans_fmt, null_trans))
})

test_that("proj_create() doesn't crash on invalid input", {
expect_error(proj_create(1, 2))
expect_error(proj_create("OGC:CRS84", 2))
test_that("proj_trans_create() doesn't crash on invalid input", {
expect_error(proj_trans_create(1, 2))
expect_error(proj_trans_create("OGC:CRS84", 2))

expect_error(proj_create(4326, "", logical(), logical(2)))
expect_error(proj_create("", 4326, TRUE, logical(2)))
expect_error(proj_create(4326, 4326, "", TRUE))
expect_error(proj_create(4326, 4326, NA, 1))
expect_error(proj_trans_create(4326, "", logical(), logical(2)))
expect_error(proj_trans_create("", 4326, TRUE, logical(2)))
expect_error(proj_trans_create(4326, 4326, "", TRUE))
expect_error(proj_trans_create(4326, 4326, NA, 1))
})

test_that("wk_transform() works", {
fwd <- wk::wk_transform(wk::xy(-5:5, -5:5), proj_create("OGC:CRS84", "EPSG:3857"))
inv <- wk::wk_transform(fwd, proj_create("EPSG:3857", "OGC:CRS84"))
fwd <- wk::wk_transform(wk::xy(-5:5, -5:5), proj_trans_create("OGC:CRS84", "EPSG:3857"))
inv <- wk::wk_transform(fwd, proj_trans_create("EPSG:3857", "OGC:CRS84"))

expect_equal(inv, wk::xy(-5:5, -5:5))

expect_equal(
wk::wk_transform(wk::xy(1, 1), proj_create("OGC:CRS84", "EPSG:3857")),
wk::wk_transform(wk::xy(1, 1), proj_trans_create("OGC:CRS84", "EPSG:3857")),
wk::xy(111319.4908, 111325.1429)
)
})

test_that("proj_create() is normalised", {
test_that("proj_trans_create() is normalised", {
pts <- wk::xy(-10:10, 10:-10)
expect_equal(
# no coord flip
wk::wk_transform(pts, proj_create("EPSG:4326", "OGC:CRS84")),
wk::wk_transform(pts, proj_trans_create("EPSG:4326", "OGC:CRS84")),
pts
)
})
Expand All @@ -57,7 +57,7 @@ test_that("transform() handles NA & NaN", {
expect_equal(
wk::wk_transform(
wk::xy(1:3, 1:3),
proj_create("OGC:CRS84", "OGC:CRS84")
proj_trans_create("OGC:CRS84", "OGC:CRS84")
),
wk::xy(1:3, 1:3)
)
Expand All @@ -66,7 +66,7 @@ test_that("transform() handles NA & NaN", {
expect_equal(
wk::wk_transform(
wk::xyzm(1, 1, NA, NaN),
proj_create("OGC:CRS84", "OGC:CRS84")
proj_trans_create("OGC:CRS84", "OGC:CRS84")
),
wk::xyzm(1, 1, NA, NaN)
)
Expand All @@ -75,15 +75,15 @@ test_that("transform() handles NA & NaN", {
expect_equal(
wk::wk_transform(
wk::xyzm(c(NaN, NaN, NA, NA), c(NaN, NA, NaN, NA), 0, 0),
proj_create("OGC:CRS84", "OGC:CRS84")
proj_trans_create("OGC:CRS84", "OGC:CRS84")
),
rep.int(wk::xyzm(NaN, NaN, NaN, NaN), 4)
)
})

test_that("wk_trans_inverse() works", {
inv <- wk::wk_trans_inverse(proj_create("EPSG:3857", "OGC:CRS84"))
rev <- proj_create("OGC:CRS84", "EPSG:3857")
inv <- wk::wk_trans_inverse(proj_trans_create("EPSG:3857", "OGC:CRS84"))
rev <- proj_trans_create("OGC:CRS84", "EPSG:3857")

expect_equal(
wk::wk_transform(
Expand All @@ -103,7 +103,7 @@ test_that("wk_trans_inverse() works", {
})

test_that("inverse(proj_trans) print method works", {
crs_to_crs <- wk::wk_trans_inverse(proj_create("OGC:CRS84", "EPSG:3857"))
crs_to_crs <- wk::wk_trans_inverse(proj_trans_create("OGC:CRS84", "EPSG:3857"))
str <- capture_output(print(crs_to_crs))

expect_match(str, "<proj_trans at .*>")
Expand Down

0 comments on commit e5cc06f

Please sign in to comment.