Skip to content

Instantly share code, notes, and snippets.

@rCarto
Last active November 27, 2020 12:22
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 rCarto/7dfca328e0cd2a3455ba6cf9601c0147 to your computer and use it in GitHub Desktop.
Save rCarto/7dfca328e0cd2a3455ba6cf9601c0147 to your computer and use it in GitHub Desktop.
library(sf)
library(elevatr)
library(raster)
library(tanaka)
# a polygon of bangalore
bangalore <- st_read("export.geojson")
elevation <- get_elev_raster(bangalore, z = 10)
bangalore_elevation <- trim(mask(elevation, bangalore))
# inspect min and max values
summary(bangalore_elevation)
# get contours
bangalore_contour <- tanaka_contour(bangalore_elevation,
breaks = seq(750, 1000, 25))
# define margins and facets
par(mfrow = c(1,2), mar = c(0,0,0,0))
# plot raster and contour
plot(bangalore_elevation, axes = F, box = FALSE, legend = FALSE)
plot(st_geometry(bangalore_contour), add = TRUE,
col = NA, border = "grey20", lwd = .5)
# plot tanaka
tanaka(bangalore_contour,
col = hcl.colors(n = nrow(bangalore_contour),
palette = "Cividis"),
legend.pos = "topright")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment