Created
September 4, 2018 12:49
-
-
Save joeroe/43bb6efa233cb5c8994b6a6d41a4911a to your computer and use it in GitHub Desktop.
Convert a deldir::deldir object to an sf::sf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' @importFrom sf st_as_sf | |
st_as_sf.deldir <- function(dd, extract = c("tiles", "triangles")) { | |
extract <- match.arg(extract) | |
if (extract == "tiles") { | |
ddlist <- deldir::tile.list(dd) | |
} | |
else if (extract == "triangles") { | |
ddlist <- deldir::triang.list(dd) | |
} | |
ddlist %>% | |
purrr::map(~{cbind(x = .$x, y = .$y)} %>% | |
rbind(.[1,]) %>% | |
list() %>% | |
sf::st_polygon()) %>% | |
sf::st_sfc() %>% | |
sf::st_sf() %>% | |
dplyr::mutate(id = dplyr::row_number()) %>% | |
return() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment