Converting DEM rasters into OBJ meshes for use in Blender

This is the technique I use to get Digital Elevation Models (DEMs) into Blender from QGIS. Here's an example using this technique:-

Indian Ocean. Sea was added as an additional, transparent mesh at sea level (elevation 0)


For this, you’ll need

- Blender (I use 2.79)
- QGIS
- Python
- dem2obj (here on Github)
- git

First of all, fork the project in Github. That'll give you a fresh copy to play with (and enhancements/fixes are welcome)

cd /path/to/project
git clone https://www.github.com/your_user_name/dem2obj
pyvenv venv
source ./venv/bin/activate

You should now see the command line prompt change to (venv).

(venv) pip install -r requirements.txt

That might take a while (a few minutes, potentially)

Running dem2obj

When that's done, you should be able to run this. If you're not seeing the (venv) prompt, you'll need to reactivate the virtual environment, as follows:-

cd /path/to/project
source ./venv/bin/activate

You can now run the tool. You need to run AT LEAST --input FILENAME and --output FILENAME.

If your DEM is in degrees (e.g. WGS84) and elevation in meters, pass in the -w (or --wgs84) flags

(venv) python rastertomesh.py --input /path/to/input.tiff --output /tmp/foo.obj

Importing into Blender

Blender supports OBJ file import as a standard, no need for plugins.

In Blender, File > Import > Wavefront (.obj)

You need to make sure your settings look like this. I'm using Y forward, Z up. You can save these settings and recall them later using the [+] button. You'll need to reselect this each time you import a new mesh!

Screen Shot 2017-11-18 at 20.53.54.png

Styling Relief Maps in Blender

There are lots of ways of styling in Blender. I find the traditional way (lighting from the top-left, and viewing straight down with an Orthogonal camera) works really well.

This is the Nodes recipe I use (with Cycles renderer). This applies a relief-map colour ramp to the z-axis to give cartographic-looking results...

an example configuration

Troubleshooting

Out-of-memory (Blender crashes). I find a 4Gb machine can handle 1000x1000 fine; 8Gb RAM is good for 2000x2000. If your raster is too large Blender will crash during loading. You can use QGIS or gdalwarp to resize your raster to something your machine can cope with.

If the tool runs, and Blender imports it but you can't see anything, it may be that the scale means the mesh is too large (clipping means that very large models can disappear). You can pass this in using the --scale VALUE option. The default is 1.0, which means 1 unit of size in the DEM equals 1 Blender unit. You can scale it up/down in Blender, or run it again with this option.

If the model imports but is rotated on its side, check you imported using the suggested settings. Remember, y forward, z up.