Skip to content

Instantly share code, notes, and snippets.

@btupper
Created May 10, 2020 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save btupper/8e8eb8c0ebf4402a3f87b5638eca954a to your computer and use it in GitHub Desktop.
Save btupper/8e8eb8c0ebf4402a3f87b5638eca954a to your computer and use it in GitHub Desktop.
#' Retrieve a stars layer of Auckland’s Maunga Whau volcano topography. Adapted from
#' USGS-R inlmisc package.
#'
#' @seealso \url{https://waterdata.usgs.gov/blog/inlmiscmaps/}
#' @seealso \url{https://CRAN.R-project.org/package=inlmisc}
#' @export
#' @param indexed logical, if TRUE then assign 1,2,3,... as cell values
#' @return Stars
volcano_stars <- function(indexed = FALSE){
require(magrittr)
require(stars)
m <- datasets::volcano
s <- 10
x0 <- 6478705
y0 <- 2668010
d <- dim(m)
m <- m[,rev(seq_len(d[2]))]
x <- seq(from = x0, length.out = d[2], by = s)
y <- seq(from = y0 , length.out = d[1], by = -s)
r <- stars::st_as_stars(m) %>%
stars::st_set_dimensions(names = c("x", "y")) %>%
stars::st_set_dimensions("x", offset = x0, delta = s) %>%
stars::st_set_dimensions("y", offset = y0, delta = -s) %>%
sf::st_set_crs("epsg:27200")
if (indexed){
r[[1]] <- matrix(seq_len(prod(d)), nrow = d[1], ncol = d[2], byrow = TRUE)
}
r
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment