Is there any command line tool to create a 3D terrain from a DEM SRTM HGT file like this?

I mean, given a camera position, a HGT file and a satelite image.

enter image description here


First try to adapt mdsumner's answer: This is the full code:

First, install all I need (Docker image from R-Base):

apt-get update & apt-get install -y libproj-dev xorg libx11-dev libglu1-mesa-dev libfreetype6-dev libgdal-dev --fix-missing

Install required packages:

install.packages(c("remotes", "quadmesh", "rgl"))

Load the SRTM DEM HGT file:

dem <- raster("/home/docker/S14W042.hgt")

Load a texture image and execute. My image is just a PNG file (must be a sub product of the HGT file - anything that I can extract using GDAL - or an ordinary image):

im <- brick("/home/docker/S14W042.map.png" )
qm <- quadmesh::quadmesh(dem, texture = im)


Error in quadmesh.BasicRaster(dem, texture = im) :
  texture must be a 3-layer raster with RGB values (in 0-255)

Please help here. NOTE: I can't auto-download anything. All files MUST be here when creating the image.


I realized that I can use any X,Y,Z map server instead MapBox to get the imagery, including my own server.

First I try with ArcGIS online:

Give any API-KEY. Don't care.

u <- "https://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{zoom}/{y}/{x}"

im <- cc_location(cbind(147, -42), base_url = u)

  • This 3D terrain was created with photoshop plugin 3d terrain. – nagib Jun 1 '19 at 6:56
  • Ok but I don't want to say exactly THIS image. I mean an image LIKE this. Photoshop IS NOT a command line tool. – Magno C Jun 1 '19 at 17:17
  • I expect it's a one layer palette image but you need a 3-layer raster with RGB values (in 0-255) so try im_rgb <- setValues(brick(im[[1]], im[[1]], im[[1]]), t(col2rgb(im@legend@colortable))) - but I'm guessing, does your im@legend@colortable have a set of hex code colours? – mdsumner Jun 4 '19 at 13:39
  • I don't know. I'm completely blind because I don't now anything about R and raster files. I'm just a Java developer. But I will follow anything you tell me to do. Basicaly I have just a HGT file. I can use GDAL tools to extract slope as TIF, an image as PNG, some kind of colored image using ramp color and so on. I don't have any way to download anything at execution time because production environment limitations. I can use my Geoserver to get any map image I need in a given BBOX but it is limited to the layers I have. I think the texture may not be exactly a satelite image. – Magno C Jun 4 '19 at 13:51
  • 1
    btw, this is a very unsuitable venue for discussions, feel free to take it to the dev repo Issues: github.com/hypertidy/quadmesh/issues – mdsumner Jun 6 '19 at 7:21

This can be done with R, visualized with the rgl package, and converting the DEM and image to mesh3d form with the quadmesh package.

Here I use another package ceramic from github to obtain the DEM and image, but you can replace those by reading the DEM with raster::raster() and the image with raster::brick().

## install.packages(c("remotes", "quadmesh", "rgl))
## remotes::install_github("hypertidy/ceramic")
dem <- cc_elevation(cbind(120.9647, -8.8033), buffer = 15000)
im <- cc_location(dem, type = "mapbox.satellite")

rgl::shade3d(qm, lit = FALSE); 

Use the rgl function view3d() to control the view, or interact with the scene to put it where you need.

enter image description here

  • Please see my EDIT 1 – Magno C Jun 4 '19 at 13:00

Your Answer

