====== ArmA 3 QGIS Real World Data Tutorial ====== [[https://www.pmctactical.org/forum/viewforum.php?f=68|ArmA 3 Forum]], [[:arma3|ArmA 3]], [[arma3:config|ArmA 3 Config]], [[arma3:missions|ArmA 3 Missions]], [[arma3:modeling|ArmA 3 3D Modeling]], [[arma3:scripting|ArmA 3 Scripting]], [[arma3:terrain|ArmA 3 Terrain]], [[arma3:texturing|ArmA 3 Texturing]], [[arma3:tools|ArmA 3 Tools]] **ArmA 3 QGIS Real World Data Tutorial** by Ross This process has often been described using Global Mapper, but I wanted to detail the equivalent steps within the open source (free) GIS app - QGIS. The goal was to achieve an export satellite image and heightmap with the same or better quality than would be possible with Global Mapper. I've used GDAL command lines where possible, which simplifies the process a little, and reduced additional processing on the data. The following software versions were used for this tutorial: **[[https://qgis.org/en/site/forusers/download.html|QGIS v3.4.3]]** **[[https://sourceforge.net/projects/terraincognita2/files/|Terra Incognita v2.45]]** I have referenced Terra Incognita because i felt it was the easiest way to obtain satellite data in the oziexplorer map format - see this **[[https://pmc.editing.wiki/doku.php?id=arma3:terrain:satellite-texture-terra-incognita|tutorial]]** for help using Terra Incognita. **First an overview of the steps required:** ==== For Heightmap: ==== * Load heightmap into QGIS (drag and drop) * Set QGIS to appropriate CRS for location of your HM * Create shapefile & generate perfect square using Advanced Digitizing panel * Obtain extents from square feature * Run 2 GDAL commands * First to set cell size, CRS and then clip to shapefile square extents * Second to convert to .asc file ==== For Satellite image ==== **For single tile export** * Load in just the '.map' files generated from Terra Incognita into QGIS * Merge rasters * Obtain extents from square feature * gdalwarp command will set cell size, CRS and then clip to shapefile square extents **For 4 tile export (large projects 40960 and above)** * Load in just the '.map' files generated from Terra Incognita into QGIS * Merge Rasters * Create grid -- 2 x 2 Feature * Move each quarter to its own shapefile layer * Obtain extents from each quarter feature * Run gdalwarp command for each quarter to set cell size and CRS and clip to shapefile square extents **And now detailed steps for:** ===== Heightmap: ===== This tutorial covers single raster heightmap as per the kind you will find on [[https://portal.opentopography.org/raster?opentopoID=OTSRTM.082015.4326.1|opentopo]], I will detail steps for heightmaps spread across multiple rasters in another update. 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 [[https://pmc.editing.wiki/doku.php?id=arma:terrain:grid_cell_size|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 {{https://pmc.editing.wiki/images/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 [[https://pmc.editing.wiki/doku.php?id=arma3:terrain:utm-projection|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. {{https://pmc.editing.wiki/images/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 {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-14b.png}} Right click on your shapefile in layers window & select ‘**Toggle Editing**’ {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-15b.png}} From menu -- **View** → **Toolbars** → **Advanced Digitizing Toolbar** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-16.png}} Select ‘**Add Polygon Feature**’ {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-17.png}} Select Enable advanced digitizing tools {{https://pmc.editing.wiki/images/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. {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-19b.png}} See a short video example using the **Advanced Digitizing** tool: {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-AdvancedDigitizing.gif}} After the last **left mouse click** from the step above, the tool is still waiting to plot more points, so to finalize the square do a **right mouse click** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-20b.png}} This will then bring up an attributes dialogue -- just type any number and Enter {{https://pmc.editing.wiki/images/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 {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-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** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-01.png}} You will only need to copy the **Extent** figures, which we will use within the GDAL commands in the next step {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-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**' {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-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: {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-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**%%'''%%) ===== Satellite image ===== ==== For single tile export ==== **Load in just the '.map' files generated from Terra Incognita into QGIS** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-1b.png}} **Merge Rasters** Top Menu -** Raster **→ **Miscellaneous **→ **Merge** Select all your .map files as input layers {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-3b.png}} change **Output data type** to ‘Byte’ as the default is ‘Float32’. Select ‘**Save to File**’ under Merged -- as the default is to a temporary file. {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-2b.png}} **Obtain extents from square feature** You should already have this from working on heightmap above **576787.687480 1841104.815839 597267.687480 1861584.815839** **Run GDAL command** import os\\ os.system(r%%'''%%gdalwarp **-t_srs EPSG:32620** -r cubic -wo SOURCE_EXTRA=1000 **-tr 1.0 1.0** -r cubic -of BMP **-te 576787.687480 1841104.815839 597267.687480 1861584.815839** D:/Arma/QGIS/Montserrat/merged.tif D:/Arma/QGIS/Montserrat/mont.bmp%%'''%%) Some explanation of the key parameters: **-t_srs EPSG:32620**\\ Sets the CRS **-tr 1.0 1.0**\\ Sets the resolution of your satellite image to 1mtr per pixel - which is recommended. Make sure it matches your settings within Terrain Builder. {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-05.png}} **-te 576787.687480 1841104.815839 597267.687480 1861584.815839**\\ Clips to shapefile square extents ==== For 4 tile export ==== Detailing additional steps required for a 4 tile export -- which would suit those terrains that are 40960px x 40960px and higher. **Load in just the .map files into QGIS** **Merge rasters - same as above (single tile export)** **Create grid -- 2 x 2 Feature** You will need to have created the **square shapefile** first -- see above steps Top Menu -- **View** → **Panels** → **Processing Toolbox** Processing Toolbox Menu -- **Vector Creation** > **Create Grid** Set **Grid type** to ‘**Rectangle (polygon)**’ & the **Horizontal & Vertical** to half the distance of your main square Set it to save new grid feature to .shp file {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-26b.png}} After clicking '**Use Layer Extent**' Select the shapefile layer for your square {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-13.png}} After clicking **Run**, your original square will then be Covered with a new grid of 4 tiles -- perfect quarters of your original square {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-30b.png}} **Move each quarter to its own shapefile layer** Because you will need to export each quarter separately for use in Terrain Builder, we will move each quarter onto its own shapefile layer. Click **Select Features** - {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-31.png}} And select the first quarter: {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-32b.png}} Top Menu -- **Edit** > **Copy Features** Then… **Edit** → **Paste Features As **→ **New Vector Layer** Save shapefile layer to something obvious I’ve used ‘**TL**’ for top left. {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-33b.png}} Repeat for the remaining quarters and you’ll have something like below, ‘Grid’ can be deleted. {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-34b.png}} You will then have 4 tiles which we can use to gather each quarters extents {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-35b.png}} **Obtain extents from each quarter feature** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-06.png}} Copy extents to clipboard {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-07.png}} And list them out for safe keeping - **TL - Extent**: (576787.687480, 1851344.815839) - (587027.687480, 1861584.815839)\\ **TR - Extent**: (587027.687480, 1851344.815839) - (597267.687480, 1861584.815839)\\ **BL - Extent**: (576787.687480, 1841104.815839) - (587027.687480, 1851344.815839)\\ **BR - Extent**: (587027.687480, 1841104.815839) - (597267.687480, 1851344.815839)\\ **Run GDAL command for each quarter to set cell size and CRS and clip to shapefile square extents** import os\\ os.system(r%%'''%%gdalwarp -t_srs EPSG:32620 -r cubic -wo SOURCE_EXTRA=1000 -tr 1.0 1.0 -r cubic -of BMP -te 576787.687480 1841104.815839 597267.687480 1861584.815839 D:/Arma/QGIS/Montserrat/merged.tif D:/Arma/QGIS/Montserrat/**TR.bmp**%%'''%%) ===== Loading your assets into Terrain Builder ===== I would recommend saving copies of any files to be used in **Terrain Builder** into a separate terrain project folder. This will prevent your source project files being adversely affected, and potentially no longer working within **QGIS** - particularly relevant to those changes mentioned below. **Heightmap (.asc) edits** Open your **asc** in notepad and change the following to ensure it loads in **Terrain builder**: {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-14.png}} Save to a new asc, whilst maintaining the original for use in your QGIS project space Before loading the asc file into **Terrain Builder**, delete the .prj file. Otherwise it will not import into TB. {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-09.png}} **Satellite image** Before loading the satellite image into Terrain Builder delete the .bmp.aux file {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-08.png}} ===== Managing the project assets within QGIS ===== Save your QGIS project so that you can return to export further data at a later date. Layers can be tidied up to hold the essentials ready for the next time you want to re-run GDAL commands, or export anything else like road shapefiles or mask layers etc. {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-11.png}} ===== Preparing Road Shapefile ===== **Load into QGIS (drag and drop) road shapefile** In this example I got a good dataset from - [[https://data.humdata.org/|https://data.humdata.org/]] {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-37.png}} **Clip vector to square shape** Top Menu - **Vector** > **Geoprocessing Tools** > **Clip** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-38.png}} Save features from clip to new shapefile - selecting appropriate CRS, in this example **CRS UTM-20**\\ Top Menu - **Layer** > **Save As** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-39.png}} **Set road shapefile to CRS - 31N** RMB on road shapefile > **Set CRS** > **Set Layer CRS** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-40.png}} {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-41.png}} **Set QGIS project CRS to UTM- 31N (bottom right corner):** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-42.png}} **Collect extents from your square shapefile:** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-43.png}} Extent: (**576787.687480**, **1841104.815839**) - (597267.687480, 1861584.815839) The first two values will be used in the v.transform step below. **v.transform on road shapefile using calculated extents from square shapefile** Your heightmap asc must adhere to Terrain Builders required values of **easting 200000** and **northing 0** Your road shapefile also needs to line up to the same values - we will use **v.transform** to achieve this So taking the extent values we grabbed in previous step -\\ We will do the following calculations to bring these values to (**200000** and **0**):\\ **Easting: 576787.687480 - 376787.68748 = 200000**\\ **Northing: 1841104.815839 - 1841104.815839 = 0**\\ **-376787.68748**\\ **-1841104.815839** Having figured out the correct figures plug them into the **v.transform** process {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-44.png}} Drag and Drop into QGIS your heightmap asc - the one you are able to load into Terrain builder - already adjusted to (**200000**, **0**) Set CRS on above asc to **UTM - 31N** Right click on asc in **Layers** > **Zoom to Layer** In **Layers** panel drag the asc below your **transformed road shapefile** - so you can see the roads layered above the asc {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-45.png}} Your roads should now be perfectly aligned above your heightmap {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-46.png}} ==== Setting ID and ORDER fields ==== RMB on transformed shapefile layer > Toggle **Editing** RMB on transformed shapefile layer > Open **Attribute Table** Click **Delete field** - select all fields and press **OK** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-47.png}} New Field - Name '**ID**' - length **0** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-48.png}} New Field - Name '**ORDER**' - length 0 {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-49.png}} Toggle - **Multi Edit mode** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-50.png}} ID - Enter **0** - click **Update All** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-51.png}} Select ORDER from drop down - Enter **1** - click **Update all** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-52.png}} Click - **Switch to table view** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-53.png}} Click **Save** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-54.png}} RMB on transformed road shapefile - **Toggle Editing** to save the changes **Switching to Terrain Builder -** **Load your road shapefile** Top menu - **File** > **Import** > **Shapes** Click **OK** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-55.png}} Perfectly overlaid within **Terrain builder:** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-56.png}} ===== 3D Preview using Qgis2threejs ===== If you want to see an instant 3d preview of your terrain within QGIS you can with the amazing plugin **Qgis2threejs** First install it: Top menu > **Plugins** > **Manage and Install Plugins** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-57.png}} RMB on the Merged layer and select **Zoom to Layer** Then select both the **Merged** raster, and the original source heightmap - deselect all other layers {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-58.png}} Start the Qgis2threejs plugin - Top Menu > **Web** > **Qgis2threejs** > **Qgis2threejs Exporter** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-59.png}} Select source heightmap and nothing else RMB on heightmap > **Properties** Set the **Resampling** level to **6** Set **Resolution** to **400%** {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-60.png}} Enjoy browsing around your terrain in 3D: {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-61.png}} You can also export your terrain to a browser interface if you want - **File** > **Export to web**