3D terrains from height maps
- 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, " 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
The online tool allows you to select the desired areas to export differently from the website swissALTI3D. From 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 the "New rectangle" button and dragging it on the map. The map can be zoomed in by scrolling in and out and clicking the right mouse to pan around.
Regarding the available options, I suggest using "Cloud Optimized GeoTIFF," with a resolution of 2 meters. The 0.5-meter format is very dense and too heavy for more significant areas to handle later. It's an excellent choice for smaller areas to keep all the details.
The last step is to click "Search" to generate the list of the selected map tiles. Download them on your computer. You can click on "Export all links" to download a CSV file with all the download links you can download simultaneously (see bath download).
Batch download from the CSV file
To download all the files automatically, you can download this free and open-source program available for Mac, Windows, and Linux: Free Download Manager
Change the ".csv" extension of the CSV file with a ".txt". From the menu of the Free Download Manager, select "Paste Urls from file" and select the .txt file.
Choose a folder where to save the files and begin with 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.
From the QGIS menu bar click on Plugins > Manage and install Plugins ... and search for DEMto3D and install it From the QGIS menu bar click on Plugins > Manage and install Plugins ... and search for DEMto3D and install it
QGIS maps preparation
The downloaded TIFF images must 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 into the "Layers" box to load 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 each has a different greyscale gradient that doesn't match the others. As a reminder, the grey values indicate the vertical elevation of the terrain.
The next step is to merge them to create a uniform greyscale gradient among all the maps, ensuring that they all use the same greyscale to match correctly.
Select "Raster > Miscellaneous > Merge..." from the main menu bar. A new window appears. At the moment, no input layers have been selected. To select them, click on the button with the three dots next to the "Input layers". From there, click "Select All" to add all the layers.
Click on the back arrow next to "Input layers" to return. Now press the "Run" button at the bottom of the window, and a new "Merged" layer will appear in the list. Close the Merge window.
Drag the TIFF maps into the Layer box to load them into QGIS. The map will appear. Select Raster > Miscellaneous > Merge... to process them and uniform the greyscale height scale. In the Merge tool select all the layers and click on Run to generate a new merged layer The new merged layer has an uniformed grayscale that can be used to correctly generate the 3D terrain
DEMto3D model generation
Select "Raster > DEMto3D > STL DEM 3D printing" from the main menu to load the plugin.
Layer to print
The first step is to select the layer you are interested in using; 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. 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 which elevation upward you want to generate the model from. You can see the "Lowest point" of the current map on the left side. 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 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 out all the parameters, click on the "Export to STL" button to generate the 3D STL model. The plugin will notify you with a popup window once the model is generated.
The DEMto3D plugin is quite flexible and it allows to easily generate a 3D model. Fill all the fields properly. This the final result! You can now do some renderings, 3D print it or cut it with the CNC. An example of a modification and render in Blender