Skip to content

Commit

Permalink
Merge pull request #916 from krlmlr/b-crs-wkb
Browse files Browse the repository at this point in the history
Honor crs argument for st_as_sfc.list()
  • Loading branch information
edzer committed Dec 11, 2018
2 parents bb53f02 + 6db66c7 commit 5a48393
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Imports:
units (>= 0.6-0),
utils
Suggests:
blob,
covr,
dplyr (>= 0.7-0),
ggplot2,
Expand Down
6 changes: 3 additions & 3 deletions R/sfc.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]])))
}
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test_wkb.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})

0 comments on commit 5a48393

Please sign in to comment.