Skip to content

Commit

Permalink
Merge pull request #42 from anthonynorth/main
Browse files Browse the repository at this point in the history
Proj >=  6 hard dependency
  • Loading branch information
mdsumner authored Dec 4, 2023
2 parents 941b0b9 + 6f30c54 commit fdd8321
Show file tree
Hide file tree
Showing 25 changed files with 57 additions and 174 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/R-CMD-check-autotools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ jobs:
- {os: ubuntu-latest, r: 'release', PROJ_VERSION: '8.2.1'}
- {os: ubuntu-latest, r: 'release', PROJ_VERSION: '7.2.1'}
- {os: ubuntu-latest, r: 'release', PROJ_VERSION: '6.3.1'}
- {os: ubuntu-latest, r: 'release', PROJ_VERSION: '5.2.0'}
- {os: ubuntu-latest, r: 'release', PROJ_VERSION: '4.9.3'}


env:
Expand Down
51 changes: 0 additions & 51 deletions .github/workflows/R-CMD-check-none.yaml

This file was deleted.

26 changes: 14 additions & 12 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
Package: PROJ
Title: Generic Coordinate System Transformations Using 'PROJ'
Version: 0.4.5
Authors@R:
Authors@R:
c(person(given = "Michael D.",
family = "Sumner",
role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0002-2471-7511")),
person("Jeroen", "Ooms", role = c("ctb"),
comment = "provided PROJ library support on Windows, and assistance with Windows configuration"),
person("Simon", "Urbanek", role = c("cph", "ctb"),
comment = "wrote original code versions for PROJ version 6"),
person("Dewey", "Dunnington", role = c("ctb"),
comment = c(ORCID = "0000-0002-2471-7511")),
person("Jeroen", "Ooms", role = c("ctb"),
comment = "provided PROJ library support on Windows, and assistance with Windows configuration"),
person("Simon", "Urbanek", role = c("cph", "ctb"),
comment = "wrote original code versions for PROJ version 6"),
person("Dewey", "Dunnington", role = c("ctb"),
comment = "key code contributions"))
Description: A wrapper around the generic coordinate transformation software 'PROJ'
that transforms coordinates from one coordinate reference system ('CRS')
to another. This includes cartographic projections as well as geodetic transformations. The intention is for this
package to be used by user-packages such as 'reproj', and that the older 'PROJ.4' and version 5
pathways be provided by the 'proj4' package.
that transforms coordinates from one coordinate reference system ('CRS')
to another. This includes cartographic projections as well as geodetic transformations. The intention is for this
package to be used by user-packages such as 'reproj', and that the older 'PROJ.4' and version 5
pathways be provided by the 'proj4' package.
Depends: R (>= 3.0.2)
License: GPL-3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
Suggests:
Imports:
lifecycle
Suggests:
testthat (>= 2.1.0),
spelling,
knitr,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export(ok_proj6)
export(proj_crs_text)
export(proj_trans)
export(proj_version)
importFrom(lifecycle,deprecated)
useDynLib(PROJ, .registration = TRUE)
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# PROJ (development version)

* PROJ >= 6 is now a hard dependency (#42)
* Deprecate ok_proj6() (#42)

# PROJ 0.4.5

* New function `proj_version()`.
Expand Down
1 change: 1 addition & 0 deletions R/PROJ-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# The following block is used by usethis to automatically manage
# roxygen namespace tags. Modify with care!
## usethis namespace: start
#' @importFrom lifecycle deprecated
#' @useDynLib PROJ, .registration = TRUE
## usethis namespace: end
NULL
Expand Down
23 changes: 7 additions & 16 deletions R/ok_proj6.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#' Is 'PROJ library >= 6' available
#'
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' Test for availability of 'PROJ' system library version 6 or higher.
#'
#'
#' @details
#' On unix-alikes, this function is run in `.onLoad()` to check that version 6 functionality is
#' available. On Windows, the load process sets the data file location with the version 6 API, and that
#' is used as a test instead.
Expand All @@ -17,19 +21,6 @@
#' @examples
#' ok_proj6()
ok_proj6 <- function() {

mock_no_proj6 <- getOption("reproj.mock.noproj6")

if (!is.null(mock_no_proj6) && isTRUE(mock_no_proj6)) {
message("PROJ6 *is* available, but operating in mock-no-proj6 mode '?PROJ::ok_proj6'")
out <- FALSE
} else {
#test <- try(proj_trans(list(x = 0, y = 0),
## source = "+proj=longlat +datum=WGS84",
# target = "+proj=laea"), silent = TRUE)
#out <- !inherits(test, "try-error")
out <- !is.na(proj_version())
}

out
lifecycle::deprecate_warn("0.5", "ok_proj6")
TRUE
}
6 changes: 0 additions & 6 deletions R/proj_crs_text.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,11 @@
#' @return character string in requested format
#'
#' @examples
#' if (ok_proj6()) {
#' cat(proj_crs_text("OGC:CRS84", format = 0L))
#' proj_crs_text("OGC:CRS84", format = 1L)
#' south55 <- "+proj=utm +zone=55 +south +ellps=GRS80 +units=m +no_defs +type=crs"
#' proj_crs_text(proj_crs_text(south55), 1L)
#' }
proj_crs_text <- function(source, format = 0L) {
if (!ok_proj6()) {
message("no PROJ lib available")
return(NA_character_)
}
stopifnot(length(format) == 1L)
stopifnot(format %in% c(0L, 1L, 2L))
stopifnot(is.character(source))
Expand Down
10 changes: 3 additions & 7 deletions R/proj_trans.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,12 @@
#' @references see the [PROJ library documentation](https://proj.org/development/reference/functions.html#coordinate-transformation)
#' for details on the underlying functionality
#' @examples
#' if (ok_proj6()) {
#' proj_trans(cbind(147, -42), "+proj=laea", source = "OGC:CRS84")
#' proj_trans(cbind(147, -42), z_ = -2, "+proj=laea", source = "OGC:CRS84")
#' proj_trans(cbind(147, -42), z_ = -2, t_ = 1, "+proj=laea", source = "OGC:CRS84")
#' }
#' proj_trans(cbind(147, -42), "+proj=laea", source = "OGC:CRS84")
#' proj_trans(cbind(147, -42), z_ = -2, "+proj=laea", source = "OGC:CRS84")
#' proj_trans(cbind(147, -42), z_ = -2, t_ = 1, "+proj=laea", source = "OGC:CRS84")
#' @name proj_trans
#' @export
proj_trans <- function(x, target, ..., source = NULL, z_ = NULL, t_ = NULL) {

if (!ok_proj6()) stop("no PROJ lib available")
if (missing(target) || !is.character(target)) stop("target must be a string")
if (is.null(source) || !is.character(source)) stop("source must be provided as a string")
if (is.list(x) || is.data.frame(x)) x <- cbind(x[[1L]], x[[2L]])
Expand Down
1 change: 0 additions & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ PROJ_load_proj <- function() {
## - windows because tools/winlibs.R
## - macos because CRAN mac binary libs, and configure --with-data-copy=yes --with-proj-data=/usr/local/share/proj

if (!ok_proj6()) packageStartupMessage("no PROJ lib available, {PROJ} requires PROJ lib 6.3.1 or later")
##PROJ data, only if the files are in package (will fix in gdalheaders)
if (file.exists(system.file("proj/nad.lst", package = "PROJ"))) {
prj = system.file("proj", package = "PROJ")[1L]
Expand Down
3 changes: 0 additions & 3 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -3129,9 +3129,6 @@ if test x$use6 = xyes -a x${proj6api} = xno; then
$as_echo "$as_me: Cannot find working proj.h headers and library.
*** You may need to install libproj-dev or similar! ***
" >&6;}
else
CPPFLAGS="-DUSE_PROJ6_API=1 ${CPPFLAGS}"
fi
Expand Down
4 changes: 0 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,9 @@ if test x$use6 = xyes -a x${proj6api} = xno; then
AC_MSG_NOTICE([Cannot find working proj.h headers and library.
*** You may need to install libproj-dev or similar! ***
])
else
CPPFLAGS="-DUSE_PROJ6_API=1 ${CPPFLAGS}"

fi



AC_ARG_VAR([PKG_CPPFLAGS],[custom C preprocessor flags for packages compilation])
AC_ARG_VAR([PKG_LIBS],[custom libraries for package compilation])

Expand Down
21 changes: 21 additions & 0 deletions man/figures/lifecycle-deprecated.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions man/ok_proj6.Rd

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

2 changes: 0 additions & 2 deletions man/proj_crs_text.Rd

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

8 changes: 3 additions & 5 deletions man/proj_trans.Rd

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

15 changes: 0 additions & 15 deletions src/C_proj_crs_text.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include <R.h>
#include <Rinternals.h>

#ifdef USE_PROJ6_API

#include <proj.h>

SEXP C_proj_crs_text(SEXP crs_, SEXP format)
Expand Down Expand Up @@ -67,16 +65,3 @@ SEXP C_proj_crs_text(SEXP crs_, SEXP format)

return(out);
}


#else

SEXP C_proj_crs_text(SEXP crs_, SEXP format)
{
SEXP out = PROTECT(allocVector(STRSXP, 1));
SET_STRING_ELT(out, 0, NA_STRING);
UNPROTECT(1);
return out;
}

#endif
20 changes: 0 additions & 20 deletions src/C_proj_trans.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@

#include <Rinternals.h>


#ifdef USE_PROJ6_API

#include "proj.h"

// this returns a list of 2 or 4, takes in a list of 2 or 4
Expand Down Expand Up @@ -154,20 +151,3 @@ SEXP C_proj_trans_xy(SEXP x_, SEXP y_, SEXP src_, SEXP tgt_)
UNPROTECT(5);
return vec;
}

#else

SEXP C_proj_trans_list(SEXP x, SEXP src_, SEXP tgt_)
{
SEXP vec = PROTECT(allocVector(VECSXP, 0));
UNPROTECT(1);
return vec;
}
SEXP C_proj_trans_xy(SEXP x_, SEXP y_, SEXP src_, SEXP tgt_)
{
SEXP vec = PROTECT(allocVector(VECSXP, 0));
UNPROTECT(1);

return vec;
}
#endif
14 changes: 0 additions & 14 deletions src/C_proj_version.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include <R.h>
#include <Rinternals.h>

#ifdef USE_PROJ6_API

#include <proj.h>

#define STR_HELPER(x) #x
Expand All @@ -14,15 +12,3 @@ SEXP C_proj_version(void)
{
return Rf_mkString(PROJ_PROJ_VERSION);
}

#else

SEXP C_proj_version(void)
{
SEXP out = PROTECT(allocVector(STRSXP, 1));
SET_STRING_ELT(out, 0, NA_STRING);
UNPROTECT(1);
return out;
}

#endif
2 changes: 0 additions & 2 deletions src/Makevars.ucrt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
LIBSHARPYUV = $(or $(and $(wildcard $(R_TOOLS_SOFT)/lib/libsharpyuv.a),-lsharpyuv),)
PKG_LIBS = -lproj -lsqlite3 -lcurl -lbcrypt -ltiff -ljpeg -lrtmp -lssl -lssh2 -lgcrypt -lcrypto -lgdi32 -lz -lzstd -lwebp $(LIBSHARPYUV) -llzma -lgdi32 -lcrypt32 -lidn2 -lunistring -liconv -lgpg-error -lws2_32 -lwldap32 -lwinmm -lstdc++

PKG_CPPFLAGS = -DUSE_PROJ6_API=1

all: clean winlibs

winlibs:
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-PROJ.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ lat <- na.omit(w[,2])
dst <- "+proj=laea +datum=WGS84 +lon_0=147 +lat_0=-42"

test_that("PROJ works", {
skip_if(!ok_proj6())
src <- "+proj=longlat +datum=WGS84"
expect_silent(xyz <- proj_trans(cbind(X = lon, Y = lat), z_ = rep(0, length(lon)), dst, source = src))
expect_silent(lonlat <- proj_trans(cbind(X = xyz["x_"], Y = xyz["y_"]), z_ = rep(0, length(lon)),
Expand Down
Loading

0 comments on commit fdd8321

Please sign in to comment.