Open source mapping
If you like Google Maps you’re going to love QGIS. Mike Bedford shows you how to get started and introduces some of its functionality.
If you like Google Maps you’re going to love QGIS. Mike Bedford shows you how to get started and introduces some of its base mapping functionality.
Back in 1962, archaeologists in the Czech Republic discovered a mammoth’s tusk that has been engraved with a geometrical design. The pattern was subsequently identified as representing the hills, rivers, valleys and routes of the surrounding area. It was dated around 250,000 BC, making it probably the earliest map ever discovered.
In the library of Hereford Cathedral is the Mappa Mundi. Created around 1300, it’s the largest surviving medieval map of the world. The UK’s Ordnance Survey was set up in 1791 to help address the perceived risk arising from the Jacobite rising, and of invasion by France, and it went on to become one of the world’s foremost national mapping agencies. And 1999 saw California-based ESRI release its ArcGIS graphical information system, which would become the world’s most used GIS (geographic information system).
These few notable dates in the history of cartography illustrate 27,000 years of change and it’s clear that the rate of change has accelerated significantly in recent years. This isn’t surprising since digital technology has had the same effect on so many other areas, but it’s been suggested that a GIS is so different to its predecessors that it’s a totally new entity. Professionals point to support of multiple layers and an ability to carry out analyses of geographically based data as just some of the things you can do with a GIS but not with an ordinary map. And if you’re wondering where Google Maps fits in, while we’re not going to get embroiled in the debate over whether or not it’s a GIS, we would agree with the sentiment that a fully blown GIS is like Google Maps on steroids.
ESRI’s well-respected ArcGIS isn’t cheap at £1,192 per year, including VAT, for professional use. This reduces to £139 for non-commercial use, but that’s still a lot unless you have a fairly serious application. Our subject here, therefore, is the free open source QGIS which is widely used professionally and is considered to be on par with many professional GIS offerings.
We’re going to provide a hands-on introduction to using QGIS but we’re certainly not going to be looking at all its features, in fact we won’t come close. After all, if you can think of something you believe you ought to be able to do with mapping data, it’s a fair bet that QGIS can do it, either natively or via one of its many plug-ins. However, we trust that our tentative first steps will be enough to excite you about the possibilities of QGIS and start you off on your own voyage of discovery.
Orientate yourself
If your main experience with digital mapping has involved Google Maps, the first thing you’ll notice when you start up QGIS for the first time is that you don’t see a map at all. Instead, unless you open a project that someone else has produced, you’ll need to create a new project but, even having done that, you’ll be faced with a blank canvas to which you’ll need to add data as layers.
Usually you’ll want to start a project by adding a base map so, let’s see how to do that, but first create a new project at Project>New. Now, in the Browser panel at the top-left, find and expand the XYZ Tiles entry and
double-click OpenStreetMap. This will add the open source OpenStreetMap as a new layer. The map will appear in the main window and you’ll also be able to see it listed in the Layers panel at the bottom-left.
Although OpenStreetMap is the only base map shown by default, there are lots of others you can use, and you might like to familiarise yourself with what’s on offer. You’ll have to search out the URLs yourself, but as an example, right-click XYZ Tiles in the Browser panel and select New connection… In the Connection Details dialog, enter https://tile.opentopomap. org/%7Bz%7D/%7Bx%7D/%7By%7D.png as the URL, give it a name such as OpenTopoMap and click OK.
OpenTopoMap will appear below OpenStreetMap under XYZ Tiles and, if you double-click it, OpenTopoMap will appear as a second layer. In fact, it’ll appear to have replaced OpenStreetMap in the main window, but that’s only because it’s the top-most layer: it appears above OpenStreetMap in the list, and it’s fully opaque. We’ll look at opacity later but, for now, note that you can swap to seeing the OpenStreetMap again by clicking the tick box next to OpenTopoMap so it’s not displayed, or by dragging OpenStreetMap to the top of the list.
This method of adding base maps isn’t limited to maps in the normal sense of the word. You can also add satellite or aerial imagery using the same method. To add Google imagery, for example, use https://mt1. google.com/vt/lyrs=s&x=%7Bx%7D&y=%7By%7D&z=%7Bz %7D as the URL.
Elevation data
So far, we’ve seen how to add various layers to a QGIS project, although all of those layers were essentially images of one type or another. But since a GIS is concerned with far more than just images, or maps if you prefer, let’s take a look at how other types of data can be added.
To start we’re going to add some elevation data, but first a few words on types and sources. The types you’ll mostly find are DSMs (digital surface models) and DTMs (digital terrain models). DSMs include objects such as trees, buildings and cars, as well as the actual ground, while in a DTM the former types of object are filtered out so it represents only the topography. In the UK, elevation data has been produced by the Environment Agency at a resolution of 1m or 2m, and is distributed freely online by DEFRA. Over the Pond, the USGS makes elevation data available for the US at resolutions ranging from 10m to 30m, but with the aim of migrating to 1m. They also provide Space Shuttlederived data for most of the world at 30m resolution. Commonly elevation data is provided as a GeoTIFF file, which is a geo-referenced variant of the familiar TIFF image format, although there are other formats, and QGIS supports most of them.
Once you’ve downloaded the elevation data it’s time to import it into a QGIS project, ideally one into which you’ve already added a base map. Select Add Layer from the Layers menu and then choose Add Raster Layer… In the dialog, select the elevation data file by clicking the three dots against Raster Dataset(s) and clicking Add.
Because the elevation data might cover a smaller area than the base map, it’s possible that you won’t see the new layer on the map, even though it appears in the Layers panel. If that happens, just right-click the name of the layer containing the elevation data and select Zoom to Layer. Your elevation data will often appear as a rectangle, because you’ll have downloaded a so-called
tile, although it’s possible it might be less than a complete rectangle because coverage isn’t always 100 per cent.
Initially the elevation data might not look too impressive. It’s just in shades of grey with white representing the highest elevation in the tile, and black representing the lowest. In passing, this means that if you have two elevation layers, they’ll be scaled differently, but this can be solved by merging them using Raster>Miscellaneous>Build Virtual Raster…
The uninspiring greyscale image is just a start and QGIS has plenty of tricks up its sleeve. For a start let’s just change the colours: right-click the layer and select Properties. Now, in the Layer Properties dialog, ensure that Symbology is selected on the left, under Render type choose Singleband pseudocolor instead of Singleband gray, and select one of the options for Color ramp. You might not find that any of the Color ramps are to your liking, and none correspond to the common colouring of altitudes on topographic maps, but you’ll notice that you can edit each of the colours.
Moving away from just changing colours, Hillshade is another interesting option for Render type. It’ll revert the colours to greyscales in the process, but there’s a solution to that. As before, use the Layer properties to select your preferred colour scheme. Next, with the elevation layer selected, select Analysis>Hillshade… from the Raster menu, before accepting all the defaults in the dialog and clicking Run. Unlike last time, the latter won’t be converted to a hill-shaded version, but a new hill-shaded layer will be created.
As always, the new layer will be at the top of the list, so drag the coloured elevation layer to the top in the Layers panel and, of course, it will obscure the hillshaded layer. However, adjusting the transparency of the pseudo colour layer will give the best of both worlds. This option is available in Layer Properties.
And as a final way of processing elevation data, a few words on contours. Depending on your choice of base map, you might already be able to see contours. However, if you’re using a base map without contours, you can generate these from elevation data at Raster>Extraction>Contours….
Beyond conventional maps
So we’ve seen how QGIS handles data that’s basically an image, or in other words a map, and we’ve seen that it can process elevation data in so many ways. But this is far from the limit of its data-handling capabilities. QGIS can work with any type off data so long as it’s georeferenced. So, for example, this could enable you to see the variation in rainfall or hours of sunshine across a region, or it could provide a means of visualising the correspondence between the geological classification of rocks and surface features.
A recent project involved showing how QGIS can operate with other types of data, and via a brief return to elevation data, how it can carry out calculations on that data. The exercise involved using rainfall and elevation data to simulate areas at risk from flooding. The simulation software could input raw elevation data, so no need for QGIS there, except for the fact that elevation data for the area of interest was incomplete. In particular, there were holes in the preferred 1m resolution data, but 2m data was available for the area.
QGIS was used, therefore, to compile a file of elevation data using 1m resolution where present, and filling the gaps with 2m data where it wasn’t. This was achieved by loading both sets of elevation data as separate layers and then using QGIS’ raster calculator (Raster>Raster Calculator) to combine them. This was done using the statement (“1m_dtm@1” = 0) * “2m_ dtm@1” + (“1m_dtm@1” != 0) * “2m_dtm@1” having first ensured that the no data value in the 1m elevation data file is 0. It generates a new raster layer with values defined by the expression, and it’s fairly clear how it achieves the desired effect.
This is only presented as an aside, but the ability to carry out any arithmetic operation on raster data is a powerful tool. QGIS then came into play again when the simulation software had crunched the input data and created a geo-referenced output file of water depths. By importing this to QGIS, and viewing it, partially transparent, over a base map, at-risk areas could be clearly identified.
Lines, points, photos
Informative pushpin labels are a familiar sight on online maps, and QGIS doesn’t disappoint here. This sort of information can be created elsewhere and imported as a new layer, or it can be created within QGIS, as we’re about to see. As always, you need at least a base map in your project before proceeding.
In the Layer menu, select Create Layer>New Shapefile Layer…. In the dialog, give the layer a name and choose a type, which must be Point, Multipoint, Line or Polygon. Now start adding fields, and there can be as many as you want. In our example, we’re creating a layer
that shows places at which particular minerals were found. Our first field, therefore, is the type of mineral, so we give it the name “type”, and specify that the field is defined as text. Having filled in the first field, click Add to Fields List and you’ll see it appear in the list below. We also added a second field, namely the date on which the mineral was found, in just the same way. When you’ve defined all the necessary fields, just click OK and you’ll see that the layer appears in the Layers panel, although nothing will appear on the map, because there are no points defined yet.
To add points, make sure the new layer is selected and click the Toggle Editing icon (yellow pencil) in the Data Source Manager toolbar. Once you’re in editing mode, click the Add Point Feature icon (three green dots and a crosshair), and the cursor will change to a crosshair. Click it on the map at the place of interest and the Feature Attribute dialog will appear. You might not want to bother with the “id”, but fill in the various other fields and click OK. A coloured dot will appear on the map. Now click the Toggle Editing toolbar again to turn off editing and see how a user can interrogate that point. Click the Identify Features icon (the “i” on a blue circle with an arrow cursor) in the Project toolbar. Click a coloured dot and a window will appear providing data on all the fields defined for the layer.
You might find it surprising that some of that data doesn’t appear alongside the point without interrogating it, but since there’s no limit to how many fields you can assign, it’s fairly obvious why that doesn’t happen by default. However, you can choose to add labels for all points on a layer, which you’ll do by clicking the Layer Labelling Options icon (“abc” on a yellow arrow) on the Data Source Manager toolbar. In the Layer Styling dialog, ensure the Labels tab is selected (the “abc” on a yellow arrow again), choose Single labels in the top box and choose the field you want the point to be labelled with against Value. You’ll see the point labelled on the map. You might want to fine-tune the options under “Placement”. Also, if the size, shape and colour of the point aren’t to your liking, this is something else you can adjust in the Layer Styling dialog, this time on the Symbology tab (the paintbrush).
QGIS also enables you to show photos at the location they were taken, but only if they’re geolocated. So, if they were taken on a phone you’ll be okay, although if you took them on a camera they might not be. Bizarrely, given that QGIS doesn’t seem to be short on features, we could find no way to import non-geotagged photos. That’s not a show-stopper, though – it just means you’ve got to add the geotags separately. There are plenty of standalone applications and web-based utilities to do that (for example, www.tool.geoimgr.com), although many limit how many photos you can process a day without paying a fee.
So, with a folder full of geotagged photos at the ready, here’s how to import them into a QGIS project. In the Processing menu, select Toolbox>Vector creation>Import geotagged photos. Against Input folder select the folder containing the photos you want to add and click Run. A new layer will appear in the Layers panel and you’ll notice some small markers appear on the map, at their correct locations, just like the ones we added previously.
However much you zoom in, though, they won’t appear as photos unless you make some changes. Bring up the Layer Styling dialog and ensure the Symbology tab is selected. Single Symbol will be shown and below that the marker type will be shown (expand it if not already expanded to show Simple Marker). Click Simple marker and then, against Symbol Layer Type, choose Raster Image Marker instead of Simple Marker. Lower down there’s an unnamed box where you can define a particular raster image, but instead we want it to pick up the image at that point. So, click the icon at the right, which looks like a filing cabinet and a couple of arrows, to allow the Data Defined Override option to be selected, and against “Field type: string”, choose “Photo (string)”. Photos will replace the blobs, but they will be very small so specify a new size against Width.
QGIS is a very powerful tool and what we’ve presented here is only a taster to what it can achieve. Experimentation is one of the best ways of learning, so what are you waiting for?