Skip to content

Instantly share code, notes, and snippets.

@ClemRz
Last active August 28, 2023 14:15
Show Gist options
  • Save ClemRz/5a538fc878edba80b08829e3115e8ff1 to your computer and use it in GitHub Desktop.
Save ClemRz/5a538fc878edba80b08829e3115e8ff1 to your computer and use it in GitHub Desktop.
Trail maps production with QGIS

Trail maps production with QGIS

Table of Content

I. Setup

  1. Install git on your computer: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
  2. Download the source repository: run the command line git clone --recurse-submodules -j8 https://github.com/ClemRz/Topographic-Maps.git
  3. Download and install the latest QGIS LTS version: https://qgis.org/en/site/forusers/download.html
  4. Create a free account under https://earthexplorer.usgs.gov/

II. Create a map from an existing map

Here is a general overview of the steps to follow:

  1. Open an existing map, the more recent the better
  2. Save it as new in a different folder under the same root directory
  3. Fetch the layers for your map (see III. Add layers below)
  4. Style the layers (see IV. Style layers below)
  5. Configure the atlas layer (see V. Configure an atlas below)
  6. Edit the print composer (see VI. Compose below)
  7. Print the map (see VII. Print below)

III. Add layers

Depending on your map's location you will fetch the layer from different services.

  • For USA I use to download them from OSM, here is a how to.
  • For Mexico I use to download them from INEGI. The steps are (see this screencast):
    1. Visualize the file named claves_INEGI.kmz located in Topographic-Maps with Google Earth for instance, or from my map.
    2. Click on the cell(s) corresponding to your area of interest. A key will be shown, for instance A11B22
    3. Go to http://www.beta.inegi.org.mx/app/mapas/ search using the previous key and download the latest SHP package
    4. Unzip the downloaded file, move the folder to your map's folder, then drag and drop the SHP files to your QGIS map
  • Download the DEM files. DEM is for Data Elevation Model, this is the source file that we will use to generate the contour lines (elevation curves) and the hill-shades (see III.a. DEM below)
  • Download any trail related file that could enrich your map, it can be a KML/KMZ file from a GPS device, or even a file downloaded from WikiLoc or AllTrails
  • Download any layer that provides usefull information to your map:

III.a. DEM

A topographic map is a map showing the third dimention, elevation, graphically. In order to do that we display what we call contour lines, AKA elevation curves. Here is how to do that:

  1. Go to https://earthexplorer.usgs.gov/ and log in with your account
  2. Delimit your zone of interest on the map
  3. Click Data Sets >>, unfold Digital Elevation and check ASTER GLOBAL DEM
  4. Click Results >> and download the rasters
  5. Drag and drop the rasters in your QGIS project
  6. Merge the rasters if you use more than one: Raster > Miscellaneous > Merge...
  7. Clipp the merged raster according to the area of interest: Raster > Extraction > Clipper
  8. Get rid of all the rasters except the clipped one
  9. Extract the contour lines (see III.a.1. Contour Lines below)
  10. Extract the hill-shades (see III.a.2. Hill Shades below)
  11. Extract the slope-shades (see III.a.3 Slope Shades below)

III.a.1. Contour Lines

  1. Make sure the project's CRS is EPSG:4326
  2. Open the Contour dialogue: Raster > Extraction > Contour
  3. Select the input file (the clipped raster)
  4. Specify the location of the output file (contour lines)
  5. Check the box Attribute name and change the name from ELEV with elevation
  6. Click ok

III.a.2. Hill Shades

  1. Open the DEM (Terrain models) dialogue: Raster > Analysis > DEM (Terrain Models)
  2. Select the input file (the clipped raster)
  3. Specify the ouput file (the hill shade raster)
  4. Leave the mode to Hillshade
  5. Go to http://blogs.esri.com/esri/arcgis/2007/06/12/setting-the-z-factor-parameter-correctly/ and take note of the Z factor (in meters) that matches the mean latitude of your map
  6. Click on the "pen" button at the bottom right corner of the dialogue and change the value -z 1.0 to -z followed by the Z factor you took note previously
  7. Click OK
  8. Change the transparency (80%), brightness and contrast so the result is nice looking.

III.a.3. Slope Shades

  1. Open the DEM (Terrain models) dialogue: Raster > Analysis > DEM (Terrain Models)
  2. Select the input file (the clipped raster)
  3. Specify the ouput file (the slope shade raster)
  4. Change the mode to Slope
  5. Go to http://blogs.esri.com/esri/arcgis/2007/06/12/setting-the-z-factor-parameter-correctly/ and take note of the Z factor (in meters) that matches the mean latitude of your map.
  6. Compute the inverse s of that value: 1/Z. For instance if your Z factor is 0.00001036 the the inverse s is: 1/0.00001036 which is about 96525
  7. Click on the "pen" button at the bottom right corner of the dialogue and change the value -s 1.0 to -s followed by the s factor you computed previously
  8. Click OK
  9. Change the transparency (80%), brightness and contrast so the result is nice looking.

IV. Style layers

It is important to reorganize your layers into groups to preserve the following order:

  • at the top level the "points" layers, we'll name the group P
  • next, the "lines" layers, we'll name the group L
  • next, the "area" layers, we'll name the group A
  • at the bottom the rasters and other aerial images

Using the style copy/paste feature of QGIS it is easy to style the added layers with the existing ones:

  1. Right-click on an existing layer, Styles > Copy Style
  2. Right-click on the new equivalent layer, Styles > Paste Style

If there is no existing equivalent for a new layer, you will be able to find a library of stylings under the QGIS-Properties folder:

  1. Double-click on the new layer to open the properties dialogue
  2. At the bottom click on Style > Load Style and locate the matching style file
  3. Click Open and OK

V. Configure an atlas

An atlas is what will allow you decide and visualize in advance what will be printed in the end. It is basically a polygon layer that represents the sheets of paper. But that's not all, it also contains some information behind each sheets (polygons): the orientation (landscape or portrait), the scale and the id (for page numbering and ordering).

As you copied a recent project to start with, you should already have a layer named atlas.

  1. Edit this layer (pencil icon, or right-click then toggle editting)
  2. Copy-paste and move the pages over the areas of interest
  3. Open the attribute table (table icon, or right-click then Open Attribute Table)
  4. Renumber the column id according to your needs, change the scale if necessary
  5. Save the edits (floppy disk icon with a red pencil) then toggle the editing back

It is better for a trail map to have the sheets overlapping a bit.

You will be abble to modifiy this layer whenever you want during the composing process. Don't worry if this is not perfect yet.

VI. Compose

The action of composing corresponds to put together the map (styled layers) with anything that could help reading it:

  • a legend
  • a scale
  • a CRS grid
  • a title
  • etc.

A composer is the tool that will help to arrange all this together on the page.

VI.a. Map & Atlas

  1. Click on Project > Print Composers > dynamic
  2. On the right hand side, click on Atlas generation and make sure of the following: - Coverage layer is set to atlas - Hidden coverage layer is checked - Page name is set to id - Sort by is checked and set to id - Single file export when possible is checked
  3. Click on the map, the area at the center of the page where it probably says "Map will be printed here"
  4. On the right hand side, click on Item properties
  5. Under the section Main properties change from Rectangle to Cache
  6. Make sure the section named Controlled by atlas is checked
  7. Make sure that, under this section, fixed scale is selected
  8. Click on the menu Atlas > Preview Atlas

At this point you should be abble to navigate through the pages, with the icons or the same Atlas menu.

VI.b. Legend

The legend is what helps decript the symbology of the map.

  1. Click on the existing legend
  2. On the right hand side, click on the Update all button under the section Legend items. Make sure Auto update is not selected.
  3. You will see the same hirearchy as you grouped the layers. We don't need that hierarchy so we need to do some renaming an cleanup. Sarting by dragging and dropping all the items outside of the groups so we can delete them.
  4. Some layer have a conditional styling, like the roads and the streams. They are easily identifiable by the arrow that appears left to the layer name. Edit that layer name (click on the pencil icon), clear the name and press OK.
  5. Remove (red - icon) the DEM entries such as the slope-shade, hill-shade and any layer that has no sense to be present in the legend.
  6. Rename the remaining entries so they make sense

VI.c. Additional information box

This is the text box located at the bottom right of the page. I indicates the name of the map, the number of the current page and the number of pages in total, the author, the scale, the magnetic declination etc.

  1. Click on the name of the map and modify it according to your needs. You will see that there are 2 placeholders for the page number and the total number of pages.
  2. Click on the text where appears the author and modify it accoding to your needs.
  3. Obtain the magnetic declination value for your map: go to http://twcc.fr and locate the pin where your map is. At the bottom left of the screen you will be able to read the value of the magnetic declination.
  4. Back in QGIS, click on the magnetic declination picture and change the Image source to point to NorthArrow_08_x.xx.svg where x.xx is the value of the magnetic declination.
  5. If the image looks rotten (a red cross) then you will have to generate it. Don't be affraid, this is a simple process, see section VI.c.1. SVG magnetic declination below.

VI.c.1. SVG magnetic declination

The magnetic declination image is a SVG file and can be easily modified with a simple text editor.

  1. Open the folder QGIS-Properties/images and duplicate any image NorthArrow_08_y.yy.svg where y.yy is as close as possible to x.xx.
  2. Rename the duplicated image to NorthArrow_08_x.xx.svg
  3. Open the image with a text editor and look for the text y.yy. Replace it with x.xx and save the file
  4. Go back to QGIS, the image should appear with the correct magnetic declination

VII. Print

When you feel your map is complete and your composer is ready then the last step is to export and print your map. This might be the most satisfying step in the process.

Remember that if your map is not showing exactly the desired region you can still go back and edit your atlas layer to your convinience.

  1. Exporte the entire atlas (set of sheets composing the map) clicking on the menu Atlas > Export as PDF ...
  2. Select the location of the exported file and name it as you wish
  3. Click on Save. It might take some minutes to render, depending on the number of pages and the speed of your computer.
  4. Open the generated PDF file and print it on your preffered printer. Make sure the printing scale is set to 100% in order to keep the map scale consistent.

VII. Go out and explore

This is the most important step in the whole process!

Don't forget to bring your map with you ;)

Enjoy!

Truly yours, Clément Ronzon.

@ClemRz
Copy link
Author

ClemRz commented May 31, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment