Skip to content

Instantly share code, notes, and snippets.

@cbrown5
Created May 18, 2020 12:18
Show Gist options
  • Save cbrown5/65ac150cb71de8cc6c7923313a2b72f5 to your computer and use it in GitHub Desktop.
Save cbrown5/65ac150cb71de8cc6c7923313a2b72f5 to your computer and use it in GitHub Desktop.
Convert stars raster to raster::raster
#Takes as an input a stars raster layer
#CJ Brown 2020-05-18
st_as_raster <- function(rstars){
rext <- st_bbox(rstars)
raster(t(rstars[[1]]), xmn = rext[1], xmx = rext[3],
ymn = rext[2], ymx=rext[4],
crs = st_crs(rstars)$proj4string)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment