3D_Morlaix_mini

Outputs of a species distribution model draped over 3D landscape

Outputs of a species distribution model draped over 3D landscape of the studied area
Prédictions d’un modèle d’habitat drapées sur un modèle numérique de terrain en 3D

This image is a 3D snapshot of the predictions of probability of presence of Laminaria in the Bay of Morlaix. The outputs are draped on the bathymetric digitial elevation model of the area using library(rgl) in the R-software.
Cette image montre les prédictions d’un modèle de distribution de laminaires projetées sur la représentation 3D des fonds marins de la zone d’étude. Elle a été réalisée à l’aide de la librairie ‘rgl’ dans le logiciel R.

# 3D representation of the outputs of a species distribution model
# website: http://statnmap.com

# Libraries
library(raster)
library(rgl)

# Read digital elevation model for bathymetry
dem.r <- raster("dem.r.tif")

# Read raster of predictions with same characteristics than dem.r
mean_map <- raster("mean_prediction.tif")

# Color palette
myPal <- colorRampPalette(c("forestgreen", "lightgreen", "yellow2", "bisque1"))

# Vector of colors corresponding to predictions
color <- myPal(30)[31-c((values(mean_map)-0)/(max(values(mean_map),na.rm=T)-0))*30]
# Areas without predictions are colored in blue
color[which(is.na(values(mean_map))] <- "lightsteelblue1"

# Figure
open3d()
rgl.bg(col="black")
# Transform raster as a matrix for z-value in the 3D plot
datamat <- matrix(values(dem.r),nrow=dim(dem.r)[2],ncol=dim(dem.r)[1])[,c(dim(dem.r)[1]:1)]
# Transform color vector as a matrix to be draped over the 3D plot
colormat <- matrix(color,nrow=dim(dem.r)[2],ncol=dim(dem.r)[1])[,c(dim(dem.r)[1]:1)]

persp3d(datamat,
  x = seq(xmin(dem.r), xmax(dem.r)-1, xres(dem.r)),
  y = seq(ymin(dem.r), ymax(dem.r)-1, yres(dem.r)),
  col = colormat)

aspect3d(1,1,0.01)

# Save 3d rgl snapshot
rgl.snapshot("3D_Morlaix_mini.png", fmt = "png", top = TRUE)