Marco Lurati

3D terrains from height maps

- file://UTbOswaYAX9njqKt

  • 3D printing
  • 3D terrain
  • maps

Height maps

The geodata images on the swiss topography office are free to download; the ones necessary to generate a 3D terrain are the ones called swissALTI3D.

The data necessary to generate the 3D model are called "height maps" and are usually greyscale images. Every pixel in the picture carries three pieces of information; latitudinal and longitudinal coordinates (related to its x and y position in the image) and the elevation of the terrain in that specific point defined by the greyscale value of the pixel itself.

The 3D model is generated using the information from the height map image.

The main program required is QGIS with the DEMto3D extension, both open source and free to use. Later on, I will show you how to install them.

Get the maps form swissALTI3D

From the website swissALTI3D, the online tool allows you to select the desired areas to export differently. With the "Selection mode" drop-down menu, choose the one that best works for you.

The "Selection by rectangle" allows you to select a more extensive area by clicking on the "New rectangle" button and dragging it on the map. The map can be zoomed in by scrolling in and out and the right click of the mouse to pan around.

About the available options, the format I would suggest using is "Cloud Optimized GeoTIFF," with a resolution of 2 meters. The 0.5 meter is very dense and way too heavy for more significant areas to handle later. For smaller areas, it's an excellent choice to keep all the details.

The last step is to click on "Search" to generate the list of the selected map tiles. Download them on your computer.

Batch download from the CSV file

To download all the files automatically, starting from the CSV file, you can download this free and open-source program available for Mac, Windows, and Linux: Persepolis.

Create a new queue from "Queue > Create New Queue", then select "File > Import links from a text file". In the "Add to queue" option, choose the queue you created as a destination and click OK.

From the "Category", right-click on the queue and select "Start this queue" to begin the download.

QGIS setup

Installation

Download and install QGIS. Once installed, from the menu bar, click on "Plugins > Manage and install Plugins ..." and all the available plugin lists will appear. Search for "DEMto3D" and install it. You are all set up now.

QGIS maps preparation

The TIFF images that have been downloaded have to be loaded as Layers in QGIS. From the QGIS interface, you can browse your folders from the "Browser" box, select all the map tiles, and drag them in the "Layers" box to load them and show them. You can also drag them from your computer to the Layer box, which is even easier.

The height maps are shown as single tiles, and everyone has a different greyscale gradient that doesn't match the other one. As a reminder, the grey values indicate the vertical elevation of the terrain.

To make them all use the same greyscale to match correctly, the next step is to merge them to have a uniform greyscale gradient among all the maps.

Select "Raster > Miscellaneous > Merge..." from the main menu bar. A new window appears. At the moment, there are no Input layers selected. To select them, click on the button with the three dots next to the "Input layers". From there, click on "Select All" to add all the layers.

Click on the back arrow next to "Input layers" to go back. Now press the "Run" button at the bottom of the window, and you will see a new "Merged" layer appear in the list. Close the Merge window.

DEMto3D model generation

Select "Raster > DEMto3D > STL DEM 3D printing" from the main menu to load the plugin.

Layer to print
The first thing to do is select the interested layer to use; in this case, select the Merged layer from the list.

Print extent
The print extent defines the portion of the map to include; by clicking on the magnifying loop button with the green arrows, you will select the whole map of the layer. With the other magnifying loop buttons, you can choose just a portion.
By activating the "Show width/length," you will see the terrain width and length selected in meters.

Spacing
This will define the dimension of triangles of the generated mesh of the STL file (let's say it does control the resolution of the mesh). The smaller it is, the more resolution you will have, but it will be way more complex to generate and difficult to work with. The weight of the file will also increase (quickly reaching some GBytes in size!). If your PC freezes, you may need to increase this value to be able to generate the 3D model.

Width, Length, and Scale
those are linked together; change one to update the others. They define the final dimension of the model; if you are going to 3D print it, check that the maximum size will fit on your printer bed. You could also specify a scale if you want to reproduce it truthfully.

Vertical exaggeration
If you want to emphasize the depth of the 3D model, you can increase this value, be aware that it won't be on a real scale, and the Z vertical axis will be stretched. With x 1,000, the scale is correct.

Terrain inversion
you can generate the negative of the terrain with this option.

Divide model
If you need a specific scale and size of the final terrain, but it won't fit into your 3D printer or CNC, you can divide it into tiles (separate files), print/cut them separately, and assemble them afterward.

Height (m)
You can define from which elevation upward you want to generate the model. On the left side, you can see the "Lowest point" of the current map. If you include all of that, you can choose a lower value.

For example, if the lowest point is 1635m, you can choose 1500m as the height from which to include a vertical margin corresponding to 135m and have all the maps in the 3D model.

On the other hand, if you are only interested in a higher portion of the map, you can start from a higher height, for example, 2000m, and be sure to be still lower than the "Highest point." Else there won't be any terrain to generate. In this example, with a height of 2000m, you will have 658m of vertical terrain in your model (the Highest point is indicated as 2658m).

!!! Small caviar of the plugin !!!
Once you insert the "Height (m)" value, you have to press the Enter key for the plugin to calculate the "Model height." If you don't do that, the model height will stay at 0mm, and your model will be flat (useless). Press Enter and check to have a defined Model height other than 0mm.

Once you have filled up all the parameters, click on the "Export to STL" button to generate the 3D STL model. Once the model is generated, the plugin will notify you with a popup window.