This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Last revision Both sides next revision | ||
arma3:terrain:qgis-real-world-data-tutorial [2019-01-20 10:01] snakeman fixed typos. |
arma3:terrain:qgis-real-world-data-tutorial [2019-05-04 03:37] snakeman |
||
---|---|---|---|
Line 7: | Line 7: | ||
The goal was to achieve an export satellite image and heightmap with the same or better quality than would be possible with Global Mapper. | The goal was to achieve an export satellite image and heightmap with the same or better quality than would be possible with Global Mapper. | ||
- | The is my second revision of this process as I recently discovered that due to an update to GDAL (**2.4.0**) one of the key steps in the original tutorial using '**Clip Raster by Mask Layer**' no longer works perfectly! | + | I've used GDAL command lines where possible, which simplifies the process a little, and reduced additional processing on the data. |
- | So I reworked the process by getting a bit more under the hood, and using GDAL command line where possible, this also simplifies the process a little and reduced even further processing on the data. | + | The following software versions were used for this tutorial: |
- | + | ||
- | This tutorial used the following software: | + | |
**[[https://qgis.org/en/site/forusers/download.html|QGIS v3.4.3]]** | **[[https://qgis.org/en/site/forusers/download.html|QGIS v3.4.3]]** | ||
Line 36: | Line 34: | ||
**For single tile export** | **For single tile export** | ||
- | * Load in just the '.map' files generated in Terra Incognita into QGIS | + | * Load in just the '.map' files generated from Terra Incognita into QGIS |
* Merge rasters | * Merge rasters | ||
* Obtain extents from square feature | * Obtain extents from square feature | ||
Line 43: | Line 41: | ||
**For 4 tile export (large projects 40960 and above)** | **For 4 tile export (large projects 40960 and above)** | ||
- | * Load in just the '.map' files generated in Terra Incognita into QGIS | + | * Load in just the '.map' files generated from Terra Incognita into QGIS |
* Merge Rasters | * Merge Rasters | ||
* Create grid -- 2 x 2 Feature | * Create grid -- 2 x 2 Feature | ||
Line 54: | Line 52: | ||
===== Heightmap: ===== | ===== Heightmap: ===== | ||
+ | |||
+ | This tutorial covers single raster heightmap as per the kind you will find on opentopo [[http://opentopo.sdsc.edu/raster?opentopoID=OTSRTM.082015.4326.1|here]], I will detail steps for heightmaps spread across muliptle 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** | **Drag and drop your heightmap '.asc' into QGIS** | ||
- | This tutorial covers single raster heightmap as per the kind you will find on opentopo [[http://opentopo.sdsc.edu/raster?opentopoID=OTSRTM.082015.4326.1|here]], I will detail steps for heightmaps spread across muliptle rasters in another update. as they will require additional steps likely including Merge / Build Virtual Raster commands. | + | 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** | **Set QGIS to appropriate CRS for location of your HM** | ||
Line 66: | Line 66: | ||
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]].\\ | 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. | + | 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}} | {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-13b.png}} | ||
Line 113: | Line 113: | ||
{{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-21.png}} | {{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** | **Obtain extents from square feature** | ||
Line 143: | Line 145: | ||
import os\\ | import os\\ | ||
- | os.system(r%%'''%%gdalwarp **-t_srs EPSG:32620** -wo SOURCE_EXTRA=1000 **-tr 5.0 5.0** -srcnodata "-9999" -r cubic -of GTiff **-te 576787.687480 1841104.815839 597267.687480 1861584.815839 D:/Arma/Heightmaps/Opentopo/output_srtm.asc** **D:/Arma/QGIS/Montserrat/converted.tif**%%'''%%) | + | 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: | Some explanation of the key parameters: | ||
Line 289: | Line 291: | ||
And list them out for safe keeping - | And list them out for safe keeping - | ||
- | TL - Extent: (576787.687480, 1851344.815839) - (587027.687480, 1861584.815839)\\ | + | **TL - Extent**: (576787.687480, 1851344.815839) - (587027.687480, 1861584.815839)\\ |
- | TR - Extent: (587027.687480, 1851344.815839) - (597267.687480, 1861584.815839)\\ | + | **TR - Extent**: (587027.687480, 1851344.815839) - (597267.687480, 1861584.815839)\\ |
- | BL - Extent: (576787.687480, 1841104.815839) - (587027.687480, 1851344.815839)\\ | + | **BL - Extent**: (576787.687480, 1841104.815839) - (587027.687480, 1851344.815839)\\ |
- | BR - Extent: (587027.687480, 1841104.815839) - (597267.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** | **Run GDAL command for each quarter to set cell size and CRS and clip to shapefile square extents** | ||
Line 302: | Line 304: | ||
===== Loading your assets into Terrain Builder ===== | ===== 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** | **Heightmap (.asc) edits** | ||
- | Open your asc and change the following: | + | 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}} | {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-14.png}} | ||
- | Before loading the asc file into Terrain Builder, delete the .prj file. Otherwise it will not import into TB. | + | 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}} | {{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-09.png}} | ||
Line 331: | Line 336: | ||
{{https://pmc.editing.wiki/images/Ross-QGIS-Tutorial-11.png}} | {{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** | ||
**Coming Soon:** | **Coming Soon:** | ||
- | * Road shapefile creation | ||
* Assisted image classification - for creation of mask | * Assisted image classification - for creation of mask | ||
- | * 3d preview using Qgis2threejs |