Skip to content

Instantly share code, notes, and snippets.

@jhollist
Last active November 29, 2018 15:36
Show Gist options
  • Save jhollist/6bf0ffcc1b2178bd812836da98ef06e4 to your computer and use it in GitHub Desktop.
Save jhollist/6bf0ffcc1b2178bd812836da98ef06e4 to your computer and use it in GitHub Desktop.
library(USAboundaries)
library(sf)
library(dplyr)
library(elevatr)
library(raster)
# Get map of lower 48 states
usa_l48 <- us_boundaries() %>%
filter(state_abbr != "HI" &
state_abbr != "AK" &
state_abbr != "PR")
# Get DEM. Zoom level 4 returns dem of ~ 3.8km resolution for whole of lower 48
usa_l48_dem <- get_elev_raster(as(usa_l48, "Spatial"), src="aws", z = 4, clip = "location")
# Project to albers/meters
usgs_albers <- "+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs"
usa_l48_alb <- usa_l48 %>%
st_transform(crs = usgs_albers)
usa_l48_dem_alb <- projectRaster(usa_l48_dem, crs = usgs_albers)
# Plot it
plot(usa_l48_dem_alb)
plot(st_geometry(usa_l48_alb), fill = F, add = T)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment