From e547e3121e03e6e736e3e9a28f76764f49ae0c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 11 Dec 2018 16:03:29 +0100 Subject: [PATCH 1/2] Pass on CRS for st_as_sfc.list() --- R/sfc.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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]]))) } From 6db66c7e976914b34e5fb89d7bb88c9609357055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 11 Dec 2018 16:18:16 +0100 Subject: [PATCH 2/2] Add test --- DESCRIPTION | 1 + tests/testthat/test_wkb.R | 11 +++++++++++ 2 files changed, 12 insertions(+) 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/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)) +})