0

Here is some elevation data of some islands.

Land Only

I wish to add depth info to the water. With the generous help of @Spacedman at Overlaying elevation data and bathymetry data in R I get:

Water and Land I

To resolve the blockyness of the lower resolution water data I tried, resample(to_harbour, to_island, method = "bilinear") yielding:

enter image description here

I'm not sure if that is correct. Note that I have lost some of the water around the islands. I'm not sure why this is nor am I sure how I should identify the water in to_island. Currently I am just looking at the data and guessing that values less than 75.109m are water and should be looked up from the bathymetric raster layer.

Dropbox:

to_island

to_harbour

Code

library(sp)
library(raster)

library(tidyverse)
library(rayshader)

to_island <- readRDS(file = "to_island.RDS") # https://www.dropbox.com/s/hc86gzdt6nm4j4w/to_island.RDS?dl=0
to_harbour <- readRDS(file = "to_harbour.RDS") # https://www.dropbox.com/s/awl4clyb3254n14/to_harbour.RDS?dl=0

# Create matrix for 3D plotting
to_island_matrix = matrix(raster::extract(to_island, raster::extent(to_island), buffer = 10000), 
                          nrow = ncol(to_island), ncol = nrow(to_island))

# 3D plot land without water depth info ####################################################
to_island_matrix %>%
  sphere_shade(zscale = 0.1, texture = "imhof1") %>%  # Lower zscale maps points to wider range of colours
  plot_3d(to_island_matrix, zscale = 1, fov = 0, theta = 170, phi = 30, windowsize = c(1000, 800), zoom = 0.35,
          water = TRUE, waterdepth = 75.2, wateralpha = 0.5, watercolor = "#88DDFF",
          waterlinecolor = "white", waterlinealpha = 0.5)

render_snapshot()
rgl::clear3d()

###########################################################################################
# Add water depth values to land raster layer ##############################################

# Resample to_harbour to match higher resolution of to_island
to_harbour_res <- resample(to_harbour, to_island, method = "bilinear")


# Identify points on to_island that are water
w <- which(to_island[] < 75.109)
length(w)

# Get coordinates of those points (water)
xy <- SpatialPoints(to_island)[w]

# Add CRS
proj4string(xy) = projection(to_island)

# These locations aren't in the coordinate system of the water raster so we need to transform them (WGS84 v NAD83)
xyt = spTransform(xy, projection(to_harbour))

# Get the water raster values at those points:
ex = raster::extract(to_harbour_res, xyt)

# Replace the locations in the land raster with the values sampled from from the water raster:
to_island[w] = ex

# Create matrix for 3D plotting
to_island_matrix = matrix(raster::extract(to_island, raster::extent(to_island), buffer = 10000), 
                          nrow = ncol(to_island), ncol = nrow(to_island))

# # 3D plot land WITH water depth info
to_island_matrix %>%
  sphere_shade(zscale = 0.1, texture = "imhof1") %>%  # Lower zscale maps points to wider range of colours
  plot_3d(to_island_matrix, zscale = 1, fov = 0, theta = 170, phi = 30, windowsize = c(1000, 800), zoom = 0.35,
          water = TRUE, waterdepth = 75.2, wateralpha = 0.5, watercolor = "#88DDFF",
          waterlinecolor = "white", waterlinealpha = 0.5)

render_snapshot()
rgl::clear3d()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.