Skip to content

Commit

Permalink
try to pass travis; #1225
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Jan 5, 2020
1 parent d16c352 commit 39e2de8
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 17 deletions.
6 changes: 4 additions & 2 deletions R/crs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions R/transform.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion man/st_crs.Rd

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

10 changes: 6 additions & 4 deletions man/st_transform.Rd

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

14 changes: 8 additions & 6 deletions src/gdal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,16 @@ Rcpp::List sfc_from_ogr(std::vector<OGRGeometry *> 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]]
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test_deprecated-db.R
Original file line number Diff line number Diff line change
Expand Up @@ -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__';"
Expand All @@ -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")
Expand Down Expand Up @@ -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__",
Expand Down Expand Up @@ -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_)
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test_postgis_RPostgres.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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))
Expand Down

0 comments on commit 39e2de8

Please sign in to comment.