Skip to content

Instantly share code, notes, and snippets.

@dakvid
Created November 16, 2021 09:39
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 dakvid/a10005a13cfcab690f14d44064f00c65 to your computer and use it in GitHub Desktop.
Save dakvid/a10005a13cfcab690f14d44064f00c65 to your computer and use it in GitHub Desktop.
#30DayMapChallenge 2021 - Day 10 - Raster - 3D Kāpiti Island with rayshader
# Make a black and white elevation map of Kāpiti Island, New Zealand
# adapting https://github.com/AmitLevinson/30daymapchallenge/blob/main/2021/09_monochrome/monochrome.R
# for #30DayMapChallenge 2021 - Day 10 - Raster
# -- David Friggens, November 2021
library(elevatr)
library(rayshader)
library(sf)
library(dplyr)
# Luckily the island is its own Statistical Area 2, & I have those from
# datafinder.stats.govt.nz
ki_outline <-
read_sf("statsnz/statistical-area-2-2021-clipped-generalised.gpkg") %>%
filter(SA22021_V1_00_NAME_ASCII == "Kapiti Island")
ki_outline <-
ki_outline %>%
st_transform(crs = 4326L) %>%
select(geom) %>%
st_cast("POLYGON") %>%
slice(4) # Just take the main island and ignore the pesky tiny ones
# Get elevation data
ki_raster <-
get_elev_raster(
locations = ki_outline,
z = 12,
clip = "locations")
# Convert to matrix for rayshader plotting
ki_matrix = raster_to_matrix(ki_raster)
# The biggest issue I had getting this working was figuring out that my island
# way up in the air was due to the zscale being too low
ki_matrix %>%
sphere_shade(texture = "bw") %>%
plot_3d(ki_matrix, zscale = 10, fov = 0, theta = 0, zoom = 0.9, phi = 45, windowsize = c(1000, 800))
render_snapshot("Day_10/Day_10_raster_kapiti",
title_text = "K\u0101piti Island",
title_offset = c(220,300),
title_color = "black",
title_size = 40,
title_font = "Poppins",
vignette = 0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment