简体   繁体   中英

Plotting 3D Raster (DEM) in R?

I am trying to plot a 3D surface of a DEM imported as a raster in R using the raster package.

So far, my code is:

DEM <- raster("DSM_TLS_2010_25cm_v4.tif")
DEM <- setMinMax(DEM)
col <- rainbow(20)
plot(DEM, col=col, zlim=c(0,790.22), main="Digital Elevation Model (DEM)")

Which works perfect for a 2D plot of the DEM, but, when I try to make it 3D, with:

plot3d(DEM)

or

surface3d(DEM)

It says cannot coerce type 'S4' to vector of type 'double' .

I am sure that answer is very simple but I have not managed to get it working with the similar questions that I have found.

The raster() function returns RasterLayer objects, and I suspect that the plot3d() and surface3d() functions in the rgl package do not (or do not fully) support RasterLayer objects.

The plot3D() function in the RasterVis package, however, does. Give this a try:

install.packages("rasterVis")
library(rasterVis)
plot3D(DEM)   # note: 3D not 3d

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM