QGIS only need Drawing method and why i choisen this area, don't need drawing the map.
TRP620 Open Source GIS and Spatial Data Analysis
Geoprocessing and Map Styling in QGIS
Session led by Ruth Hamilton
Introduction
Part 1
For the first part of this practical, we are going to think about how best to display point data.
This map shows the highest point in each county in the US. Your brain can tell you that there are lots of points on the map and that there are probably hotspots in certain locations but once you have hundreds of points in a small area like this, it’s very difficult to process this information mentally or to really distinguish any patterns. For example, we can see the density of points is higher in the east of the US than the west, but we can’t identify much beyond that.
We are going to look at two simple approaches, that allow us to lighten the cognitive load of points maps like the one above and make sense of the data. This makes it much easier to then interpret the underlying spatial patterns. The methods we are going to look at are:
-> Heatmaps and
-> Hex-bins
Part 2
In the second part of today’s session, we will be creating an A0 size map of Sheffield using Ordnance Survey open data – after undertaking a number of simple geoprocessing steps. In case you didn’t already know, Ordnance Survey is the national mapping agency for Great Britain and has a wide range of open data available for use.
We’re going to do the following things in this part of the workshop…
· Download a number of different layers from the OS OpenData web portal.
· Dissolve a layer based on a common attribute
· Buffer the boundary of Sheffield to 20km so we can define a reasonable area of interest.
· Clip our layers using our buffered Sheffield boundary.
After we’ve done this we will then download apply layer stylesheets to use in QGIS. A stylesheet allows you to automatically symbolise a layer and Ordnance Survey have a range of stylesheets you can use with QGIS so that you can mimic their famous map styles.
The end result of the session should be an A0 size (84.1 x 118.9 cm) map of Sheffield which looks something like the image on the next page.
Once you understand the method and how stylesheets work you can then apply the technique to other areas and produce a map of a different area of the country, if you wish.
As always, please remember to use an external hard drive or – if you’ve forgotten it – the C drive of the machine you are working on.
Some of the downloads today are quite big so don’t worry if it takes a little while to download the data.
Part 1
Task 1: Creating a heatmap from points
Sometimes when you have hundreds, thousands or even millions of points clustered together it can become hard to interpret them. One way that can help summarise patterns like this is called a ‘heatmap’; this interpolates discrete points to create a continuous surface representing the density of points.
The simplest way of creating a visual heat map of point is to use the Heatmap symbology option.
· Add the ‘AllSchools_ShefBNG’ shapefile to QGIS for this task.
· Open the symbology tab of the properties box and select the Heatmap option as shown.
· Click ‘Apply’ and look at your data. Zoom in and out.
You should see that the heatmap clustering changes and disaggregates as you zoom in. This is useful for visualisation purposes but because is calculated dynamically - depending on the zoom scale - it can sometimes be unhelpful. We can also calculate a heatmap that uses a fixed radius and so doesn’t change as the zoom level changes. This is shown on the next page.
Tip: An alternative way of rendering point layers is point clustering. This option is also accessed from the renderer drop-down menu in the Symbology tab. This results in a point cluster symbol that indicates the number of points that overlap in that area. Like the heatmap renderer this will change as you zoom in and out. You see this kind of visualisation a lot in online maps but you can also use in printed maps.
You can also create heatmap layer in QGIS using the Interpolation tool. Rather than changing the way the data is visualised, this creates a new, raster layer that is fixed irrespective of zoom level. You can find this by opening the Processing toolbox (Processing > Toolbox) and typing ‘heatmap’ into the search box
· The first thing I want you to do is follow the very basic example on the next page which shows you how to create an interpolated heatmap. This is not very revealing and is just a quick example of how to the plugin works.
· Instead of the default values, I want you to enter 2500 as the radius (this indicates a radius of 2.5km) and make sure you change the pixel size to at least 10 – you don’t need to touch any of the other settings.
· Once you’ve done this you will see a new black to white coloured raster surface called Heatmap.
· Go into the properties for the layer and change it to a different style by going to the colour options (via Style) and then changing the Render type to ‘Singleband pseudocolor’.
· Select a colour scheme and then you just need to click Load (bottom right) and then Classify – I have also ticked the ‘Invert’ box so the colour scheme runs from blue to red. The final product should look something like the image below.
· It may helpful if you add a basemap (Web>OpenLayersPlugin) and change the transparency of the Heatmap layer (for a raster layer, you do this from the transparency tab).
This gives you a raster surface image that indicates the density of schools in Sheffield. Note, how this heat map remains the same as you zoom in and out.
Making a heatmap of locations like this doesn’t always make sense from an analytical point of view. What I want you to think about is what kind of data might be more suitable for this kind of analysis. Two data examples that should come to mind immediately are crime data and fire incident data. You can find some interesting fire incident data for London at the link below. This could make for an interesting and relevant heat map! The other link is for crime data, via police.uk.
· http://data.london.gov.uk/dataset/london-fire-brigade-incident-records
The question of what radius you should specify is, of course, a very important issue and will vary from dataset to dataset, there needs to be some kind of distance decay function but precisely what this should be is up to you as the analyst.
Caution: The Heatmap plugin in QGIS can generate some lovely looking maps but there is a danger that what you produce can be misleading and/or simply wrong. What you must be careful to do when presenting the results of any heat mapping is to declare your method and say why you took such an approach. Without such information a heatmap is much more difficult to interpret.
Task 2: Mapping density with hex grids
Mapping densities using a hexagonal grid is an increasingly common method in spatial analysis – and is a useful alternative to creating heatmaps. Search online now for ‘hex binning gis’ or look at the links below. Follow up on this afterwards if you want to learn more.
· https://datavizproject.com/data-type/hexagonal-binning/
· https://odileeds.org/blog/2017-05-08-mapping-election-with-hexes
· https://blog.mapbox.com/binning-an-alternative-to-point-maps-2cfc7b01d2ed
It’s a very effective approach if you have lots of points and has some advantages over heatmaps.
We are going to have a go using the schools dataset we have just used.
· First, we are going to create a hex-bin shapefile that covers the geographical extent we are interested in, this is just a polygon shapefile which is tiled with identical polygons. These have no value to start with but we are then going to use the ‘Points in polygon’ tool to calculate the number of points from the schools layer that are within each hexagon.
In QGIS version 3.2, you do this from MMQGIS menu (you may have to install the MMQGIS plugin first). Select Create followed by Create Grid Layer. Then fill in the dialog box as shown in the picture below:
4. Select a location and name for the output file
3. Make sure this is your Schools layer
2. This should be set to Layer Extent
1. This should be set to ‘Hexagons’
2. Set this to ‘layer extent’
3. Select your layer here – in this case the schools layer
4. Select a location for your ‘grid’ layer and click OK
· After you’ve created your new hex bin layer you need to add the school data to it. Do this by using the ‘Points in polygon’ tool from the Vector > Analysis menu. This will count the number of points in each hexagon and add that as an attribute to the hex-grid layer.
This is the attribute field that will contain the ‘count’ of points
This is the layer you want to ‘count’
This is the hex-grid layer
· Symbolise the layer using the NUMPOINTS field as shown below – and the result will similar to the image on the next page. This shows the density of schools in Sheffield on a hex grid. You can use the ‘Count points in polygon (weighted)’ tool if you want to use the values in an attribute (for example, population counts) to weight your point shapefile. You can find this tool by searching in the Processing toolbox.
· Once you’ve created the heatmap and the hexbinned data, add a base map (Web > OpenLayers Plugin) and experiment with colours and transparencies until you get a map that you like.
· Compare the two approaches and think about how they could be used.
· Again, crime data and fire incident data may be more useful examples of when we could use hex binning. The example below is one I produced using London fire data from 2012 to 2014.
Part 2
An explanation of the British National Grid
The British National Grid – or Ordnance Survey National Grid reference system – divides Great Britain up into a number of different areas based on a lettering system. It is a little more complicated in reality but that’s what you need to know for now.
When you download data from OS OpenData (or Digimaps) you will often get data relating to an individual ‘tile’, which has a two letter code – as you can see below. Very often, the area you want to map will overlap two tiles.
I created the shapefile shown to the right so you can find your way around and understand what data you need if you want to map other areas. As shown below, Sheffield (just) overlaps the SE and SK tiles but we are going to ignore this for today and work with the SK tile.
I have placed the tile shapefile (OS_opndata_2letters.shp) in the Data Folder on MOLE because it can often save you time if you add it to QGIS, turn on an underlying base layer (e.g. Google Streets) and then figure out exactly which tile you need. It’s much easier this way! You don’t need to use it today, but feel free to use it if you wish.
Task 1: Get the Data
There are a few different datasets you need to download today. DO NOT follow my instructions below. I am including these for reference because I want you to know about different data sources. The files downloaded from these sites are very large and include much more than required for this workshop. Instead, use the data I have made available on the Blackboard page.
1. Go to the OS Open Data download page – link below – and download the following datasets
https://www.ordnancesurvey.co.uk/opendatadownload/products.html
2. The first step involves selecting all the data you want to download, so do the things below first.
· Scroll down and tick the box to download the OS VectorMap District vector layer for the SK National Grid Reference square. You can select an individual tile by clicking on the relevant square in the image or by selecting it from the list.
· Then tick the box to download the OS VectorMap District raster layer for the SK National Grid Reference square.
Tip:
· The OS VectorMap vector layer is useful if you want to select elements from it e.g. to only display buildings and roads.
· The OS VectorMap raster layer is a good option if you just want a basemap image.
· Then, tick the box to download the Boundary-Line layer. This is a vector layer and is about 340mb in size.
· Make sure you click the ‘Download’ box (the one to the right) rather than the DVD. If you select DVD they will send you a DVD but that’s no good for today!
· Once you’ve selected the data you need, scroll to the bottom of the screen and click ‘Continue’
· At the next step you’ll have to add some information. You’ll need to enter your e-mail address (where you want the download link to be sent to) and market sector (you can put ‘public sector’ here) and then for Company Name you can just say ‘University of Sheffield’ – all other information is optional.
· You then have to add in the little CAPTCHA code in the bottom left before you can click ‘Continue’. Once you do this you’ll see a ‘thank you’ screen and an order ID.
· Soon after this you’ll receive an e-mail with 3 download links – when you do, download the data to your external hard drive – it should only take about 5 minutes at the most.
If you’ve followed the above steps correctly, here is what you should have in your folder:
· Now you just need to unzip these files to your external hard drive. When you do, take a look inside the folders and you’ll see that there are lots of layers! Don’t add anything to QGIS just yet.
Before we go any further, I want you to download the cartographic style sheets for QGIS that we’ll use later on. These files allow us to use styling consistent with that used by the OS (we can also save or own styles). Follow the simple steps below.
· Go to the web link below https://github.com/OrdnanceSurvey/OS-VectorMap-District-stylesheets; then click the green ‘Clone or Download’ button.
· Select the ‘Download Zip’ option.
· Once you’ve downloaded the folder, unzip it and look inside it. The stylesheets you need can be found by following this file path:
…\OS-VectorMap-District-stylesheets-master\OS-VectorMap-District-stylesheets-master\ESRI Shapefile stylesheets\QGIS stylesheets (QML)
What is a QML file?
The QML file (.qml) contains: Style information
The QML (.qml) file in QGIS is a style file. It contains an export of the style information, including labels, from a layer. The .qml file however has no reference to the layer. This means I can share a .qml file with you and you can apply it to your own data without needing the data I exported it from. QML files are handy if you have one, or more, layers but have a collection of different style that you want to apply to them.
( from https://nathanw.net/2014/03/22/all-the-q-files/)
Task 2:
Now I want you to add the following shapefile layers from the OSVectorMapExtract folder to QGIS:
1.
14
· SK_Building
· SK_NamedPlace
· SK_RailwayStation
· SK_RailwayTrack
· SK_RailwayTunnel
· SK_Road
· SK_SurfaceWater_Area
· SK_SurfaceWater_Line
· SK_Woodland
These are some of the individual layers that go to make up the OSVectorMap the name should give you an indication of what they contain! As you can see form the QGIS canvas window, it is quite hard to make out what is going on. By applying different styles to the different layers we can make this look much better. First, however, we are interested in just the area around Sheffield and this is only a small part of the area in the SK data. The next few steps are going to walk you through the process of clipping the layers so that we only show our area of interest.
Task 3: Dissolve the boundary line layer
The next thing I want you to do is to create an outline boundary layer for Sheffield. We are going to use the Dissolve tool to create a boundary layer for Sheffield – like the one shown on page 3 of the workbook. We could of course just use a ready-made Sheffield layer but I want to show you how to create a boundary out of smaller shapes when you don’t have one. This is a really useful GIS skill to learn. I have done the first steps below for you, this is in the BoundarySheffieldWard.zip file.
· Navigate to the folder with the Boundary-Line data in it – that’s the one called bdline_essh_gb, this dataset contains a number of shapefiles for different administrative boundaries and can be very useful. Now add the following layer from the Data folder: district_borough_unitary_ward_region.shp .
· This covers most of Great Britain but if you open the attribute table you’ll see that there is a field called FILE_NAME which you can use to dissolve the layer to create a new shape for Sheffield.
· First of all, Filter the layer so that only Sheffield is showing ( right click layer, select Filter… and then type in the expression "FILE_NAME" = 'SHEFFIELD_DISTRICT_(B)'). You should see that although it is the outline of Sheffield, it is made up of lots of smaller areas. We are going to use this to make a layer with a single feature showing only the outline of Sheffield.
· Add the BoundarySheffieldWard.shp file. You should see Sheffield and the ward boundaries within it. We are going to ‘dissolve’ this dataset so that is only one feature – Sheffield.
· You may want to ‘turn off’ the other layers at this point (all of those starting with ‘SK_’ as re-drawing them can cause your computer to run more slowly.
· Now you need to go to Vector >> Geoprocessing Tools >> Dissolve (you can also find this by searching in the Processing Toolbox). Make sure your settings look like the image below and then click OK. It should only take a few seconds to add the new boundary to the map – then save your QGIS project.
Task 4: Create a buffer around Sheffield
Great work so far! As mentioned, the SK data covers a much larger area than we actually need. This means QGIS is drawing and re-drawing much more data than it needs to and it can slow down the mapping process. We are now create a buffer around the Sheffield boundary, we are then going to use this buffered layer to clip the other SK layers to a more manageable area.
· Using the dissolved Sheffield boundary layer from the previous step, go to Vector >> Geoprocessing Tools >> Buffer(s) and make sure your settings are the same as the image below, then click OK.
The new buffered layer can now be used to clip the layers we added earlier on.
· Although we’re just doing this to reduce our shapefile size, you can use buffers in a wide variety of contexts in GIS – e.g. to identify the extent of territorial waters along a coastline, to identify areas within a certain distance of a motorway, to identify how many people live within a distance of a particular point, and so on. Always keep in mind the other uses for geoprocessing tools.
Task 5: Clip your SK layers
Now that you’ve got an extended Sheffield boundary from the buffer procedure above, I want you to use it to clip all the SK layers you created previously. Just follow the instructions below to do this.
· Go to Vector >> Geoprocessing Tools >> Clip and make sure your settings match my example below – the input vector layer should be the layer you want to clip (i.e. SK_Building, SK_NamedPlace etc.) and the clip layer should be the new Sheffield buffered layer. Once you click OK it will take a little while to process before it is added to the map canvas.
· You should repeat the process so that you have clipped all 9 layers. To make the next steps easier, I recommend you name the new clipped files as shown in the table below:
|
Original layer name |
New ‘Clipped’ name |
|
· SK_Building |
· Building |
|
· SK_NamedPlace |
· NamedPlace |
|
· SK_RailwayStation |
· RailwayStation |
|
· SK_RailwayTrack |
· RailwayTrack |
|
· SK_RailwayTunnel |
· RailwayTunnel |
|
· SK_Road |
· Road |
|
· SK_SurfaceWater_Area |
· SurfaceWater_Area |
|
· SK_SurfaceWater_Line |
· SurfaceWater_Line |
· As you can see below, the clipped versions have much smaller file sizes and this will make things much easier for us.
Task 6: Putting it all together in a map
The task now is to put all this data together in a map, styled using Ordnance Survey’s QGIS layer stylesheets. This will make your map look beautiful and with a little extra bit of trickery you can add a nice glowing buffer around Sheffield so that it highlights the city boundary and darkens everything else. These are the files we downloaded earlier and should be in a folder called ‘OS-VectorMap-District-stylesheets-master’.
· Make sure you have the following clipped files in your QGIS window:
· Building
· NamedPlace
· RailwayStation
· RailwayTrack
· RailwayTunnel
· Road
· SurfaceWater_Area
· SurfaceWater_Line
· Woodland
· You should now make sure that the only layers you have in QGIS are the new SK clipped layers listed above (there should be 9 of these) AND plus the Sheffield boundary layer you created using the Dissolve process (NOT the buffered layer). You can remove any other layers because it may get confusing.
The next step is to style the layer using the Ordnance Survey stylesheets we’ve already downloaded. Ordnance Survey maps are very carefully created by expert cartographers and are easily recognisable to many people. We can use the stylesheets they provide to create maps that use the same symbology and styling.
To recreate their styles, we first need to make sure our layers are in the correct order in the Layers panel. They provide an image (shown left) so you know what order they should be in. This file is VMD_layer_order.png file in the Images folder
Make sure your 9 layers (indicated by the red boxes in this image) are in the order indicated.
Next, go to the properties for each layer in your map and in the Style properties, click ‘Load Style’ in the bottom left.
Then navigate to the qml stylesheet for that layer – e.g. the correct style for the Building layer is called Building.qml (as you can see below). Once you’ve done this you can click OK and you’ll see that the map style changes. Make sure you follow the path below and use the files within the ‘ESRI Shapefile stylesheets’ folder
‘…\OS-VectorMap-District-stylesheets-master\OS-VectorMap-District-stylesheets-master\ESRI Shapefile stylesheets\QGIS stylesheets (QML)\Full Color Style’
· Note that the latest OS style sheets have multiple styles for roads. These allow for details including overpasses and complicated intersections. For most maps we won’t so much detail so we can use only the Level 0 sytles. To do this first duplicate your clipped road layer (right click on the layer name and select duplicate). Then select the Level – 0 (Casings) and Level -0 (Fill) files for the two road layers in that order.
· Once you’ve styled the layers, you’ll have to make sure that they are in the right order and that some layers are not obscuring others – e.g. if you have the RailwayTrack layer over the Road layer in Sheffield then you won’t see the tram routes on the streets. The folder you downloaded containing the styles also contains a folder called ‘images’; in here is an example output and a screenshot showing the correct layer order to help you organise your layers.
· See the image below for an example of how it should look. Zoom in to different areas in the map to see how it looks. You’ll notice that the qml stylesheets sort out all sorts of things.
· Once you have your map the way you want it, start a new Print Layout (press CTRL + P), give it a name (e.g. Sheffield A0 Map), and then add the map to the layout.
· I want you to create an A0 size Landscape orientation map of Sheffield. On the next page I have shown you the settings I used, so please follow them to achieve the same look.
These are the settings I used in the Page Setup box from the Layout menu in Print Layout:
You can use the Sheffield outline layer to create a nice boundary effect (as seen on the front cover). These are the settings I used to achieve the green glow for the Sheffield boundary – black may look better, but you can experiment yourself.
· Check that the Sheffield boundary layer is on the top to make sure you get the correct effect.
· When you’re happy with it, go to Layout, Export as Image and save the file as a png. It will take a few minutes and produce a massive file. Click OK if it gives you a memory warning at this point.
|
Styling comments and tips The purpose of the second part of today’s session was to get you to understand some basic geoprocessing tools in QGIS and to help you produce a nice looking map of Sheffield with the results. However, you don’t need to merge, clip, buffer or dissolve any data to produce a nice map with Ordnance Survey data – it’s just that it can significantly improve map quality and reduce data volume if you do. The final few bullet points offer some comments and tips for you. · If your qml files have the same name as a shapefile- and are in the same folder - then the styling will be automatically applied when you add the shapefile to QGIS.
· To save time, you could omit the buffer and clip process and just skip straight to styling the layers and setting up the map in the Print Composer. But if you only want to map a small area then it can be really tiresome waiting for the map to redraw massive shapefiles. And of course the point of today was about geoprocessing techniques. · Why not create a beautiful wall map of your home town? You can really get creative here once you’ve got the method nailed down. · When you’ve got the Inverted Polygon style on and you’re using the Shapeburst fill to create a glow effect around a polygon, you can set the second colour to Transparent. This will fade the colour from your chosen colour transparent so that the surrounding areas are not dimmed. · You can also create your own ‘style’ files. Once you have symbolised a layer, select the ‘Save style’ option from the drop down ‘Style’ box at the bottom of the Symbology box. You can then re-use this symbology by simply loading as we did above. |
22