diff --git a/DESCRIPTION b/DESCRIPTION index 99beebe29..a34bb3de1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -61,6 +61,7 @@ Imports: units (>= 0.6-0), utils Suggests: + blob, covr, dplyr (>= 0.7-0), ggplot2, diff --git a/R/sfc.R b/R/sfc.R index 86f0c4b01..482eee389 100644 --- a/R/sfc.R +++ b/R/sfc.R @@ -491,15 +491,15 @@ st_as_sfc.list = function(x, ..., crs = NA_crs_) { return(st_sfc(crs = crs)) if (is.raw(x[[1]])) - st_as_sfc(structure(x, class = "WKB"), ...) + st_as_sfc.WKB(as_wkb(x), ..., crs = crs) else if (inherits(x[[1]], "sfg")) st_sfc(x, crs = crs) else if (is.character(x[[1]])) { # hex wkb or wkt: ch12 = substr(x[[1]], 1, 2) if (ch12 == "0x" || ch12 == "00" || ch12 == "01") # hex wkb - st_as_sfc(structure(x, class = "WKB"), ...) + st_as_sfc.WKB(as_wkb(x), ..., crs = crs) else - st_as_sfc(unlist(x), ...) # wkt + st_as_sfc(unlist(x), ..., crs = crs) # wkt } else stop(paste("st_as_sfc.list: don't know what to do with list with elements of class", class(x[[1]]))) } diff --git a/tests/testthat/test_wkb.R b/tests/testthat/test_wkb.R index 27d1171d0..c3b5d76df 100644 --- a/tests/testthat/test_wkb.R +++ b/tests/testthat/test_wkb.R @@ -50,3 +50,14 @@ test_that("Reading of truncated buffers results in a proper error", { expect_error(st_as_sfc(wkb, EWKB = TRUE), "WKB buffer too small. Input file corrupt?") }) +test_that("st_as_sfc() honors crs argument", { + raw = st_as_binary(st_point(c(26e5, 12e5))) + + list = list(raw) + blob = blob::blob(raw) + wkb = as_wkb(list) + + expect_identical(st_as_sfc(raw, crs = 2056), st_as_sfc(wkb, crs = 2056)) + expect_identical(st_as_sfc(list, crs = 2056), st_as_sfc(wkb, crs = 2056)) + expect_identical(st_as_sfc(blob, crs = 2056), st_as_sfc(wkb, crs = 2056)) +})