From 39e2de8d69128ff3d5eb98080470e8634308f8fc Mon Sep 17 00:00:00 2001 From: Edzer Pebesma Date: Sun, 5 Jan 2020 21:10:52 +0100 Subject: [PATCH] try to pass travis; #1225 --- R/crs.R | 6 ++++-- R/transform.R | 10 ++++++---- man/st_crs.Rd | 4 +++- man/st_transform.Rd | 10 ++++++---- src/gdal.cpp | 14 ++++++++------ tests/testthat/test_deprecated-db.R | 4 ++++ tests/testthat/test_postgis_RPostgres.R | 2 ++ 7 files changed, 33 insertions(+), 17 deletions(-) diff --git a/R/crs.R b/R/crs.R index 58a308c38..3d9e93c51 100644 --- a/R/crs.R +++ b/R/crs.R @@ -70,7 +70,7 @@ st_crs.character = function(x, ...) { else { crs = make_crs(x) if (is.na(crs)) - stop(paste("invalid crs:", crs)) + stop(paste("invalid crs:", x)) crs } } @@ -363,9 +363,11 @@ st_crs.Spatial = function(x, ...) { #' @export #' @examples #' pt = st_sfc(st_point(c(0, 60)), crs = 4326) +#' # st_axis_order() only has effect in GDAL >= 2.5.0: #' st_axis_order() # query default: FALSE means interpret pt as (longitude latitude) #' st_transform(pt, 3857)[[1]] -#' (old_value = st_axis_order(TRUE)) # now interpret pt as (latitude longitude), as EPSG:4326 prescribes +#' (old_value = st_axis_order(TRUE)) +#' # now interpret pt as (latitude longitude), as EPSG:4326 prescribes: #' st_axis_order() # query current value #' st_transform(pt, 3857)[[1]] #' st_axis_order(old_value) # set back to old value diff --git a/R/transform.R b/R/transform.R index f9e61b999..089e700a2 100644 --- a/R/transform.R +++ b/R/transform.R @@ -66,10 +66,12 @@ st_transform = function(x, crs, ...) UseMethod("st_transform") #' @examples #' st_transform(st_sf(a=2:1, geom=sfc), "+init=epsg:3857") #' try(st_transform(sfc, 3857, aoi = c(-280,-90,180,90))) -#' st_transform(sfc, pipeline = -#' "+proj=pipeline +step +proj=axisswap +order=2,1") # reverse axes -#' st_transform(sfc, pipeline = -#' "+proj=pipeline +step +proj=axisswap +order=2,1", reverse = TRUE) # also reverse axes +#' if (sf_extSoftVersion()["GDAL"] >= "3.0.0") { +#' st_transform(sfc, pipeline = +#' "+proj=pipeline +step +proj=axisswap +order=2,1") # reverse axes +#' st_transform(sfc, pipeline = +#' "+proj=pipeline +step +proj=axisswap +order=2,1", reverse = TRUE) # also reverse axes +#' } st_transform.sfc = function(x, crs = st_crs(x), ..., aoi = numeric(0), pipeline = character(0), reverse = FALSE, partial = TRUE, check = FALSE) { diff --git a/man/st_crs.Rd b/man/st_crs.Rd index 0ee2e93ab..faba3fac4 100644 --- a/man/st_crs.Rd +++ b/man/st_crs.Rd @@ -123,9 +123,11 @@ st_crs("+init=epsg:3857")$proj4string st_crs("+init=epsg:3857 +units=m")$b # numeric st_crs("+init=epsg:3857 +units=m")$units # character pt = st_sfc(st_point(c(0, 60)), crs = 4326) +# st_axis_order() only has effect in GDAL >= 2.5.0: st_axis_order() # query default: FALSE means interpret pt as (longitude latitude) st_transform(pt, 3857)[[1]] -(old_value = st_axis_order(TRUE)) # now interpret pt as (latitude longitude), as EPSG:4326 prescribes +(old_value = st_axis_order(TRUE)) +# now interpret pt as (latitude longitude), as EPSG:4326 prescribes: st_axis_order() # query current value st_transform(pt, 3857)[[1]] st_axis_order(old_value) # set back to old value diff --git a/man/st_transform.Rd b/man/st_transform.Rd index e6d9fa0a4..6fcd05527 100644 --- a/man/st_transform.Rd +++ b/man/st_transform.Rd @@ -87,10 +87,12 @@ sfc st_transform(sfc, 3857) st_transform(st_sf(a=2:1, geom=sfc), "+init=epsg:3857") try(st_transform(sfc, 3857, aoi = c(-280,-90,180,90))) -st_transform(sfc, pipeline = - "+proj=pipeline +step +proj=axisswap +order=2,1") # reverse axes -st_transform(sfc, pipeline = - "+proj=pipeline +step +proj=axisswap +order=2,1", reverse = TRUE) # also reverse axes +if (sf_extSoftVersion()["GDAL"] >= "3.0.0") { + st_transform(sfc, pipeline = + "+proj=pipeline +step +proj=axisswap +order=2,1") # reverse axes + st_transform(sfc, pipeline = + "+proj=pipeline +step +proj=axisswap +order=2,1", reverse = TRUE) # also reverse axes +} nc = st_read(system.file("shape/nc.shp", package="sf")) st_area(nc[1,]) # area from long/lat st_area(st_transform(nc[1,], 32119)) # NC state plane, m diff --git a/src/gdal.cpp b/src/gdal.cpp index fc712f9d1..5a4f03555 100644 --- a/src/gdal.cpp +++ b/src/gdal.cpp @@ -375,14 +375,16 @@ Rcpp::List sfc_from_ogr(std::vector g, bool destroy = false) { // [[Rcpp::export]] Rcpp::List CPL_crs_from_input(Rcpp::CharacterVector input) { - OGRSpatialReference ref; - handle_axis_order(&ref); - if (ref.SetFromUserInput(input[0]) == OGRERR_NONE) { - Rcpp::List crs = create_crs(&ref, false); + OGRSpatialReference *ref = new OGRSpatialReference; + handle_axis_order(ref); + Rcpp::List crs; + if (ref->SetFromUserInput(input[0]) == OGRERR_NONE) { + crs = create_crs(ref, false); crs(0) = input; - return crs; } else - return create_crs(NULL); + crs = create_crs(NULL); + delete ref; + return crs; } // [[Rcpp::export]] diff --git a/tests/testthat/test_deprecated-db.R b/tests/testthat/test_deprecated-db.R index 3cb998db8..7814261c3 100644 --- a/tests/testthat/test_deprecated-db.R +++ b/tests/testthat/test_deprecated-db.R @@ -54,6 +54,7 @@ test_that("sf can write units to database (#264)", { }) test_that("can write to other schema", { + skip_on_travis() # wkt2 skip_if_not(can_con(pg), "could not connect to postgis database") try(DBI::dbSendQuery(pg, "CREATE SCHEMA sf_test__;"), silent = TRUE) q <- "SELECT schema_name FROM information_schema.schemata WHERE schema_name = 'sf_test__';" @@ -74,6 +75,7 @@ test_that("can write to other schema", { }) test_that("can read from db", { + skip_on_travis() # wkt2 skip_if_not(can_con(pg), "could not connect to postgis database") q <- "select * from sf_meuse__" #expect_warning(x <- deprecated_st_read_db(pg, query = q), "crs") @@ -195,6 +197,7 @@ test_that("round trips", { }) test_that("can read using driver", { + skip_on_travis() # wkt2 skip_if_not(can_con(pg), "could not connect to postgis database") layers <- st_layers("PG:host=localhost dbname=postgis") lyr_expect <- sort(c("sf_meuse__", "sf_meuse2__", "sf_meuse3__", @@ -234,6 +237,7 @@ test_that("multi geom columns work", { }) test_that("new SRIDs are handled correctly", { + skip_on_travis() # wkt2 skip_if_not(can_con(pg), "could not connect to postgis database") data(meuse, package = "sp") meuse_sf = st_as_sf(meuse, coords = c("x", "y"), crs = NA_crs_) diff --git a/tests/testthat/test_postgis_RPostgres.R b/tests/testthat/test_postgis_RPostgres.R index 004742ea4..6a2a316ba 100644 --- a/tests/testthat/test_postgis_RPostgres.R +++ b/tests/testthat/test_postgis_RPostgres.R @@ -29,6 +29,7 @@ try(pg <- DBI::dbConnect(RPostgres::Postgres(), host = "localhost", dbname = "po # tests ------------------------------------------------------------------------ test_that("can write to db", { + skip_on_travis() # wkt2 skip_if_not(can_con(pg), "could not connect to postgis database") expect_silent(suppressMessages(st_write(pts, pg, "sf_meuse__"))) expect_error(st_write(pts, pg, "sf_meuse__"), "exists") @@ -42,6 +43,7 @@ test_that("can write to db", { }) test_that("can handle multiple geom columns", { + skip_on_travis() # wkt2 skip_if_not(can_con(pg), "could not connect to postgis database") multi <- cbind(pts[["geometry"]], st_transform(pts, 4326)) expect_silent(st_write(multi, pg, "meuse_multi", overwrite = TRUE))