Skip to content

Commit

Permalink
fix as(x, "Spatial") for points in matrix attr
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Dec 14, 2022
1 parent 7210201 commit b16648e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion R/sp.R
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,11 @@ as_Spatial = function(from, cast = TRUE, IDs = paste0("ID", seq_along(from))) {
sfc2SpatialPoints = function(from, IDs) {
if (!requireNamespace("sp", quietly = TRUE))
stop("package sp required, please install it first")
sp::SpatialPoints(do.call(rbind, from), proj4string = as(st_crs(from), "CRS"))
m = if (!is.null(pts <- attr(from, "points")))
pts
else
do.call(rbind, from)
sp::SpatialPoints(m, proj4string = as(st_crs(from), "CRS"))
}

sfc2SpatialMultiPoints = function(from) {
Expand Down

0 comments on commit b16648e

Please sign in to comment.