0

In R The Volcano dataset has elevation values, but is not a DEM file. How can I convert my DEM files (from earthexplorer.usgs.gov) so that the I can access all the elevation values in a matrix (what is returned by volcano)? I am trying to use r2stl() with the data.

1

You can use the raster package:

library(raster)
dem = raster.open("a_dem')
# plot with R
library(rasterVis)
plot3(dem)

enter image description here

# convert the raster to a matrix (as Volcano)
demmat = as.matrix(dem)

Now, you can apply the same procedure as in r2stl/demo/Maungawhau.R

z = demmat
x = 1:dim(demmat)[1]
y = 1:dim(demmat)[2]
library(r2stl)
r2stl(x, y, z, filename="dem.stl", show.persp=TRUE)

Result with MeshLab:

enter image description here

  • Thanks @gene .as.matrix() creates z values, but I'm still getting strange results. Most of my dems are spiky and if it is smooth r2stl seems to create a 1x1 x something less than 1, even if my x and y values are not equal-distorting the model. Is there a way to get a solid stl file with r2stl that is closer to the results from writeSTL (which just creates a surface) dem <-raster("dems_10m.dem") demmat <-as.matrix(dem) dem[is.na(dem)] <- 0 z <- demmat x <- (1:nrow(z)) y <- (1:ncol(z)) r2stl(x,y,z, filename="crater.stl") – larum Apr 6 '15 at 16:15

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.