Skip to content

3. Heightmap

Ross edited this page May 22, 2019 · 36 revisions

This tutorial covers single raster heightmap as per the kind you will find on opentopo here, I will detail steps for heightmaps spread across muliptle rasters in a further update to this tutorial. as they will require additional steps likely including Merge / Build Virtual Raster commands. This section does not cover any re scaling of heightmap, which I would recommend against anyway. Remember Grid size x Cell size should = the same size (meters) as your source heightmap selection.

Drag and drop your heightmap '.asc' into QGIS

If you do use opentopo for source of Heightmap, make sure extract both the .asc and .prj files before proceeding with below. They should both be in the zip file from opentopo.

Set QGIS to appropriate CRS for location of your HM

Clicking on the CRS section bottom right within QGIS -- will bring up the Project Properties for CRS

Ross-QGIS-Tutorial-11b.png

Select the CRS to match your real world data, in this example its ‘WGS 84 UTM zone 20N’ because the terrain is from the Montserrat in the Caribbean. See also UTM projection.

This will ensure your QGIS project space works appropriately with any other data you want to add - eg road shapefiles etc. Terrain Builder will only use UTM 31N but we'll get to that later.

Ross-QGIS-Tutorial-13b.png

Create shapefile & generate square feature using Advanced Digitizing panel

Top menu -- Layer > Create Layer > New Shapefile Layer

Save to project folder location

Change Geometry type to ‘Polygon’

Match CRS so it is the same as that just configured in above step

Ross-QGIS-Tutorial-14b.png

Right click on your shapefile in layers window & select ‘Toggle Editing

Ross-QGIS-Tutorial-15b.png

From menu -- ViewToolbarsAdvanced Digitizing Toolbar

Ross-QGIS-Tutorial-16.png

Select ‘Add Polygon Feature

Ross-QGIS-Tutorial-17.png

Select Enable advanced digitizing tools

Ross-QGIS-Tutorial-18.png

To create a perfect square, left mouse click for your top left starting point, move your mouse to the right a little, then press ‘d’ on keyboard, type in the exact width (distance) required (in this example ‘20480’) then immediately press Enter -- be careful not to move the mouse before pressing Enter or it will mess up the number. Press left mouse click and you will have drawn your first horizontal line which turns red. By default this tool snaps to 90 degree angles, making it easy to draw your lines. Now to draw the vertical line start moving mouse your down, press ‘d’ again and type in same figure as above, press Enter and another left mouse click, repeat the process for the last 2 lines of the square.

Ross-QGIS-Tutorial-19b.png

See a short video example using the Advanced Digitizing tool:

AdvancedDigitizing.gif

After the last left mouse click from the step above, the tool is still waiting to plot more points, so to finalise the square do a right mouse click

Ross-QGIS-Tutorial-20b.png

This will then bring up an attributes dialogue -- just type any number and Enter

Ross-QGIS-Tutorial-21.png

Save the above edits to the shapefile by clicking on the layer & selecting ‘Toggle Editing

Obtain extents from square feature

Activate the toolbox if it is not already available

Ross-QGIS-Tutorial-new-12.png

Start typing 'vector' in Processing Toolbox search bar, and you will see 'Vector information'

Double click it and make sure your square input layer is selected - then just click Run

Ross-QGIS-Tutorial-new-01.png

You will only need to copy the Extent figures, which we will use within the GDAL commands in the next step

Ross-QGIS-Tutorial-new-02.png

Run the first GDAL command which will - set CRS, cell size and then clip to shapefile square extents

From menu - Plugins > Python Console

Click 'Show Editor'

Ross-QGIS-Tutorial-new-03.png

The blank window on the right is where you will paste GDAL commands

Now you are ready to edit the command below to match your data - sections in bold are the parts to edit:

import os
os.system(r'''gdalwarp -t_srs EPSG:32620 -wo SOURCE_EXTRA=1000 -tr 5.0 5.0 -srcnodata ”-9999” -r cubic -ot Float32 -of GTiff -te 576787.687480 1841104.815839 597267.687480 1861584.815839 D:/Arma/Heightmaps/Opentopo/output_srtm.asc D:/Arma/QGIS/Montserrat/converted.tif''')

Some explanation of the key parameters:

-t_srs EPSG:32620

CRS to match where the heightmap is from in the world.

-tr 5.0 5.0

The desired resolution of your heightmap, match with Cell size set within your Mapframe properties in Terrain Builder:

Ross-QGIS-Tutorial-new-04.png

-te 576787.687480 1841104.815839 597267.687480 1861584.815839

The 4 long figures represent the extents of your square, and should be replaced with your own figures obtained in previous step.

Update the paths to match where you are storing your source heightmap, and where you want the output tif saved to.

Input:

D:/Arma/Heightmaps/Opentopo/output_srtm.asc use double quotes around your input path if it contains any blanks

Output:

D:/Arma/QGIS/Montserrat/converted.tif

Run second GDAL command - converting tif from above step to a Terrain Builder friendly .asc

Remember to change the paths in below command to match where your files are located

import os
os.system(r'''gdal_translate -of AAIGrid D:/Arma/QGIS/Montserrat/converted.tif D:/Arma/QGIS/Montserrat/final.asc''')