Skip to content

Instantly share code, notes, and snippets.

@mikemahoney218
Last active February 23, 2021 04:25
Show Gist options
  • Save mikemahoney218/c3294e3d70c393bc1a955c39ec9fbf58 to your computer and use it in GitHub Desktop.
Save mikemahoney218/c3294e3d70c393bc1a955c39ec9fbf58 to your computer and use it in GitHub Desktop.
library(terrainr) # remotes::install.github("ropensci/terrainr")
library(sf)
library(ggplot2)
library(progressr)
handlers("progress")
simulated_data <- data.frame(id = seq(1, 100, 1),
lat = runif(100, 44.04905, 44.17609),
lng = runif(100, -74.01188, -73.83493))
simulated_data <- st_as_sf(simulated_data, coords = c("lng", "lat"))
simulated_data <- st_set_crs(simulated_data, 4326)
with_progress(
output_tiles <- get_tiles(simulated_data,
services = c("elevation", "ortho"),
resolution = 90
)
)
ele_df <- raster::as.data.frame(raster::raster(output_tiles[["elevation"]]), xy = TRUE)
names(ele_df) <- c("x", "y", "val")
ggplot() +
geom_spatial_rgb(data = output_tiles[["ortho"]],
aes(x = x, y = y, r = red, g = green, b = blue), alpha = 0.1) +
ggnewscale::new_scale_fill() +
geom_raster(data = ele_df, aes(x = x, y = y, fill = val)) +
geom_sf(data = simulated_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment