individuals â also lies at the heart of the 'big data' revolution and it will be worth ... GPS data is usually stored
Jon Reades; CC BY-NC 4.0
Page 1 of 13
Working with GPS Tracks & Points Introduction Modern smartphones are nearly all GPS-enabled, meaning that you can take a continuous and accurate record of a walk, run, or bike, and combine it with geo-tagged photos and other location-enabled activities to build a class-sized data set from a collection of individual tracks. This approach – combining detailed data from many individuals – also lies at the heart of the ‘big data’ revolution and it will be worth looking out for opportunities to discuss issues of privacy, accuracy, and meaning along the way!
Learning Outcomes By the end of this practical, you will hopefully have:
Loaded trail and waypoint data from a GPX file;
Performed simple – but computational – analysis of one or more trails;
Explored ways that data from several users can be combined and analysed;
Considered some of the implications that this has for individuals and groups in a ‘big data’ age.
An Important Note about School Clusters Many schools and universities use a ‘proxy server’ to filter inappropriate content, improve security, and reduce overall network usage. This can create problems for QGIS’ plugin manager because it can't connect to the server that lists available plugins. If you are unable to search for and install plugins, then you will need to:
Click on the ‘Settings’ menu item;
Select ‘Options’;
Select the ‘Network’ tab at the bottom of the options window;
And make sure that the ‘use proxy’ checkbox is ticked (no other changes should be needed).
Section 1. Importing & Viewing GPS Data Introduction GPS data is usually stored in GPX files (e.g. file.gpx); these cannot be read directly by many applications, but QGIS is rather clever in this respect and can show them on a map in a pretty straightforward way. In Section 1 we’re just aiming to get the data shown against a background map as quickly as possible so that the rather abstract process of collecting GPS data comes to life. Backup Plan If things have gone well with the FieldTripGB experiment then we will be working with the tracks that you have created. But just in case things have gone horribly wrong (as they often do in demos) I’ve also posted online a couple of tracks from hikes I did in the Peak District.
Download the data from: http://www.reades.com/downloads/GPS.zip
Extract the Zip file to a memorable location (e.g. ‘My Documents’).
Loading Data into QGIS Let’s start by loading just one GPS trace into QGIS – after the first GPX is loaded it should be fairly easy to follow the same steps to load any/all of the remaining data. Remember to make a note of where you’ve stored your GPX files as you’ll need to tell QGIS where to find them. Now, in QGIS:
Create a new, blank map document by clicking the ‘New’ button (
).
Click on ‘Add Vector Layer’ button (
You will then be shown a list of up to six different layers within the GPX file that you can load; most of these layers will contain no data as we’re not using a specialised GPS device.
) and pick one GPX file.
Jon Reades; CC BY-NC 4.0
Page 2 of 13
You need to select track_points and tracks. [Hint: you can select more than one layer at a time by Control-clicking (holding down ‘Ctrl’ while clicking on the layers with the mouse; on a Mac it’s Command-clicking using the ‘Cmd’ key.]
Click ‘OK’ and then you should see a large number of points (and a much fainter line) appear on the map.
Do this for two or more additional sets of tracks and points from a GPX file. Making Sense of the Data Now that you have added more than one track, it may seem like you have a lot of work to do navigating between the different tracks on the map. To jump quickly between different tracks in different regions rightclick on the desired layer and then select ‘Zoom to layer’ from the popup menu – this will re-centre the map to the layer that you selected. Adding a Backdrop Of course, just looking at trails on a blank map isn’t very helpful and this is where QGIS’ plugins are rather useful. First, we need to install the QuickMapServices plugin:
Click on the ‘Plugins’ menu item at the top of the screen.
Select ‘Manage and Install Plugins’.
In the Search area type: “QuickMapServices”.
Select the plugin.
If the plugin is not already installed, click ‘Install plugin’.
When the plugin is finished installing, click ‘Close’ to return to the map.
Now let’s get an OpenStreetMap layer loaded so that we can see where we are:
Click on the ‘Web’ menu item at the top of the screen.
Pick ‘QuickMapServices’ and then ‘OSM’ to access ‘OSM TF Outdoor’.
After selecting the landscape layer you should see a Google Maps-style layer appear in your map… but on top of your data! [Hint: I sometimes find that I need to zoom in or out one level in order to make QGIS start drawing the background OpenStreetMap layer properly – it’s an annoying bug, but once you know it’s there it’s not a big deal.]
In the left-hand ‘Layers Panel’ drag the OCM Landscape layer so that it is below the GPS data you’ve loaded.
You should now see your data sitting on top of the map (something like Figure 2 below) – the points will be easy to see and, in fact, may hide a lot of the map behind them, but the tracks will be nearly invisible now. Let’s fix that! Styling the Points Data As a last step, let’s tweak the styling of the track points:
Double-click one of the points layers so that the ‘Layer Properties’ window opens (see Figure 1).
Select the ‘Style’ button (
Select the ‘Simple marker’ label on the left-hand side of the window (see Figure 1).
Notice that we can now change many aspects of the points marker – everything from a different shape to different fill and outline (i.e. edge) colours.
Change the ‘Outline style’ to ‘No Pen’ to turn off the outline completely.
Click on the ‘Fill’ colour and change it to an intense orange colour.
Click on the ‘+’ icon on the left-hand side of the window and notice that we now have two Simple makers – the new marker sits on top of the old one.
Change the order of the markers so that new simple marker is below the one we’ve just changed to
) so that you can change the appearance of the layer.
orange: click the down arrow icon (
) that looks like an upside-down triangle.
Make the second marker a simple red square with no outline. Page 2 of 13
Jon Reades; CC BY-NC 4.0
Page 3 of 13
Click ‘OK’ and have a look at the results (you may need to zoom in using the
icon).
Figure 1. Setting Layer Properties
To apply the same style to another layer quickly and easily:
Right-click on the ‘source’ layer from which you want to copy a style.
Select ‘Styles’ and then ‘Copy Style’.
Right-click on the ‘target’ layer to which you want to paste a style.
Select ‘Styles’ and then ‘Paste Style’.
Done! You should have something like the below in Figure 2. Figure 2. Styled Track Points
Over to you! Now see if you can figure out how to style the tracks (lines) so that they are easier to see on the map. Briefly discuss with your neighbour:
How accurate does GPS data seem to be?
Are there any obvious issues with the GPS traces?
If you are way ahead of the rest of the group, you might like to play around with some of the other layer options at this point: there are options for transparency, more complex effects, and scaling according to a number (e.g. you could scale a tree icon according to its measured girth).
Page 3 of 13
Jon Reades; CC BY-NC 4.0
Page 4 of 13
Notice too that we were able to create more complex markers by layering several markers; one on top of the other. I’ve used this do things like create a 2.5D map by creating a simple shadow effect using two markers, one offset and blurred from the other. There is a lot that can be done here beyond just choropleth mapping.
Section 2. Time Manager One of the things that’s so interesting about GPX tracks is that they aren’t just points, they’re points in time. So we have a kind of spatial history of how someone (or some-thing) moved around over a period of minutes, hours, or days. You may have seen the BBC show The Secret Life of Cats or seen other research done recently with migratory birds or whales – all of these are based on the collection and analysis of GPS data over time. Historically, showing time as part of a map was pretty tough, but recently QGIS has gained a handy plugin called ‘Time Manager’ that allows us to animate movement on a map and save the results as a video! Installing the TimeManager plugin (a tutorial video can be found at: youtube.com/watch?v=GkfoFFy-bao) will hopefully allow us to animate each person’s walk – I can’t promise that this will work for everyone, but if it does… movie time! By this point the process of using the Plugin Manager should be becoming familiar to you, but if not then the instructions for installing QuickMapServices (Making Sense of the Data on page 2) will help you. [Hint: I’m not 100% sure that this next step – removing spaces from layer names – is necessary, but my testing suggested that it may; for each of the layers that we want to animate:
Right-click on the layer and select ‘Rename’ from the popup menu
Remove any spaces in the layer name by replacing them with underscores (“_”).]
Now, on with the show! In the TimeManager window at the bottom of QGIS:
Click ‘Settings’.
In the popup window click ‘Add layer’.
For the Layer option select ‘track_point’.
For the ‘Start time’ select the name of the field that has the time data (e.g. ‘time’ in our case).
For the ‘End time’ select ‘No end time – accumulate features’.
Set ‘Interpolation’ to ‘Linear interpolation’
Make sure that ID attribute is set to ‘None’ since each trace is for one person.
When you click ‘OK’ you should be taken back to the ‘Settings’ window, now:
Set ‘Show frame for’ to 5 milliseconds – this will ensure that the animation moves fairly quickly.
When you click ‘OK’ to go back to the main window you should see a new layer called ‘Interpolated_points_for…’ – this is where the animation has been saved. To run the animation:
Click on the ‘Power’ button (
).
Set the ‘Time frame size’ to 5 seconds to also help move the animation along.
Click the ‘Play’ button (
).
[Hint: you can also move the time slider around by dragging it with the mouse.] Over to you! Obviously, you can try to save this as a video by clicking on the ‘Export Video’ button. But to make things more interesting, can you add several layers in the Settings window so that several GPS tracks are animated at the same time? With a class this should give a sense of how students may have quite different daily patterns (some go straight home after school, others go off to extracurricular activities, etc.), though I’d test this all out first with a small, technically-minded group of staff or students before rolling it out to the whole class.
Section 3. Simple Spatial Analysis Before we get more stuck into the data in more detail, let’s try some simple spatial analysis! This task is intended to give students a sense of how meaningful patterns can be extracted from a collection of individual Page 4 of 13
Jon Reades; CC BY-NC 4.0
Page 5 of 13
points. There are much more sophisticated ways to do what we’re going to do next, but this is a good first step since it actually incorporates many of the issues that you’d find in ‘proper’ spatial statistics but without requiring the students to understand anything about the maths behind it.
Important Locations How might we find the ‘most important’ locations contained in someone’s GPS data track? One way would, of course, be to show them the map of their traces and ask them to discuss what they were doing. But we could also look at the data to see if it reveals importance: for instance, if FieldTripGB records one location every second, then areas where a smartphone user spent more time (e.g. while measuring a tree) will have more points than areas where they spent less time (e.g. while walking between trees). In industry this is sometimes called ‘dwell time’, but the important thing is that we are just looking for areas with a higher density data points – you can probably do this by eye already, but a heatmap will really make theme pop! [Hint: the HeatMap used to be a separate plugin, but is included with QGIS as of about version 2.12. If you don't see a HeatMap option under the Raster menu then you will need to have a look at the Plugin Manager to see if it's installed and activated; there should be a tick in the checkbox next to the plugin.] Here’s how we do this:
Click on the ‘Raster’ menu item.
Select ‘Heatmap’, and then the ‘Heatmap’ plugin.
The input layer will be the first of your points layers.
Click on the ‘…’ button to browse to that memorable location (e.g. My Documents) and then give your ‘Output raster’ file a memorable name (e.g. ‘MyFirstGPSHeatmap’).
Leave the rest of the settings as they are and just click ‘OK’. [Hint: make sure ‘Add generated file to map’ is checked, or you’ll have to add the file yourself using the ‘Add Raster Layer’ button:
.]
If everything has gone well then you should get something like Figure 3. Notice how it shades from black (for ‘few points’) to white (for ‘lots of points’): in the example below there are two obvious outliers where James spent time during his FieldTripGB data collection test. Figure 3. Heatmap Output
Setting Heatmap Colours We can make it even easier to see the most important locations by changing the colour scheme using the ‘Layer Style’ options:
Right-click on the heatmap layer.
Select the style tab (the paintbrush icon). Page 5 of 13
Jon Reades; CC BY-NC 4.0
Page 6 of 13
Set the options as shown in Figure 4.
Notice that the drop-down menu at the top-left has been changed to ‘Singleband Pseudocolour’ – although our heatmap only has grey values (from black to white, and everything in between) we can map these on to a falsecolour / pseudo-colour scale in which low values are green and high values are red. Figure 4. Heatmap Colour Settings
The process for this is:
Change ‘Render type’ to ‘Singleband pseudocolor’.
The ‘Mode’ should be ‘Continuous’.
Then click ‘Classify’.
Hit ‘OK’.
Now you should have something like what we see in Figure 5. See how the two areas where James spent the most time now really ‘pop’ on the map? Looking at the background map, we can also infer some things about what those two hotspots represent… Figure 5. Pseudocolour Heatmap of Track Points
Page 6 of 13
Jon Reades; CC BY-NC 4.0
Page 7 of 13
Over to you! After performing this same task for at least one other track (try to do it without looking at the steps above), discuss the following questions with your neighbour:
What happens if you change the radius used by the Heatmap plugin: a) how would increasing the radius affect the results? b) how would decreasing the radius affect the results?
How do you think this could be applied to analysing how animals or plants are distributed in space?
What are the implications of this kind of analysis for personal privacy: does the analysis of GPS data ‘leak’ personal data (e.g. for students) in unexpected ways? To put it another way: where do you think James lives?
Are there cases where a heatmap analysis would not give us information such as home address? How might we ensure that if someone got their hands on our GPS data they wouldn’t be able to figure out where we lived?
Section 4. Combining Heatmaps & Extracting Group Locations While it’s handy to look at one person’s trail, it might be even more interesting to look at shared important locations – places where more than one user seems to have spent a bit of time. The easiest way to do this is to combine the heatmaps for several users using the Raster Calculator. What we are doing is taking a set of heatmaps, each of which has a value (coloured red for high, green for low) derived from the number of GPS points recorded in that area (i.e. grid cell). When we use the calculator we can add the values from all of the layers together, so areas where lots of people spent lots of time will come out with very high values, while areas where only one person spent a little bit of time will come out with very low values.
Deriving Group Locations from Raster Addition To perform this calculation:
Click on the ‘Raster’ menu item and select ‘Raster Calculator’.
The existing heatmaps should be listed in the ‘Raster bands’ area with ‘@1’ on the end of the layer name (this is because there is only 1 band in greyscale).
Double-click on a heatmap to add it to the ‘Raster calculator expression’ area at the bottom.
Then click on the ‘+’ icon in the ‘Operators’ area.
Double-click the next heatmap in the list.
Add another ‘+’.
Keep doing this until all heatmaps have been added.
Click on the ‘…’ button to save the ‘Output layer’ to a memorable location with a useful name (e.g. ‘Combined Heatmaps’).
Click ‘OK’.
You should now see a single greyscale layer that is the combined result of adding every single heatmap together. You can give this a pseudocolour traffic-light colour scale in the same way that you did for the individual layers before. Over to you! Some questions to think about now that you’ve extended the heatmaps to a whole group:
Do you understand how the raster analysis worked? Can you explain it to your neighbour?
How does the combined analysis change your understanding of important locations for the group, instead of just the individual?
How might you use these results to plan where to put a shop or other service? Are there other factors that you would want to consider when planning to locate a shop or other service?
Page 7 of 13
Jon Reades; CC BY-NC 4.0
Page 8 of 13
There’s a tendency for physical geographers to work with raster data and for human geographers (who often use Census and administrative data) to work with vector data, but as this task makes clear there is a lot of value to be found in being able to move between the two formats. [Hint: if you need a refresher on the terminology here, the Ordnance Survey has produced the following video: youtube.com/watch?v=aKdRiHezuk0.]
Section 5. Exploring the Attribute Table Everything up to this stage in our practical is about the distribution of points in space, but there’s obviously a lot more that we might like to uncover from our Field Trip adventures:
Which parts of the walk were at the lowest elevation?
Which parts of the walk were at the fastest pace?
To accomplish this we will need to do some mucking about with the GPS data, and to achieve that we’ll need to investigate the attributes collected by FieldTripGB in more detail.
Using the Attribute Table Let’s have a look at the attributes that have been recorded for one of the tracks:
Right-click on a track layer.
Select ‘Open Attribute table…’ (
) and you should see something like Figure 6.
Figure 6. Track Attribute Table
Geographical data, as shown in Figure 6, can seem a little mysterious but by understanding the attribute table we can often make sense of what is going on and how we can make better use the data. There are several basic things to remember when dealing with geo-data:
Programmers are lazy. Why write something clear like ‘Comment’ when you could write something short (and obscure) like ‘cmt’. Generally, many ‘fields’ (i.e. columns) will be abbreviated like this: source becomes ‘src’; description becomes ‘desc’ or ‘dsc’; latitude becomes ‘lat’; and so on.
Also, since spaces are often a problem for computers (remember what we did with the TimeManager?), programmers will tend to either drop them (‘Geoid Height’ becomes ‘geoidht’) or replace them with underscores (‘Geoid Height’ becomes ‘geoid_ht’).
Each feature shown on the map will have a matching row in the attribute table: so each point and each line imported from the GPX file will have an entry in the attribute table of the appropriate layer.
You cannot mix lines, points, and polygons in a single layer, so you’ll never see them mixed up in a single attribute table.
The geographical data (i.e. the locations of the points, lines and polygons) itself is ‘hidden’ in the attribute data table – if it helps, you can imagine that there is a hidden column that contains this location data, but that QGIS (or ArcGIS) is hiding them from you to make life easier and the attribute table a little more manageable. Over to you! I want you to work out the following:
How many features are in the tracks layer?
How many features in the points layer?
Can you find elevation data in the ‘tracks’ layer and, if so, where? Page 8 of 13
Jon Reades; CC BY-NC 4.0
Page 9 of 13
Can you find elevation data in the ‘points’ layer and, if so, where?
Feel free to discuss your thinking with your neighbour, but make a note of your choices as I hope to discuss them before we move on to the next section. However, if you are ahead of the rest of the group then please tackle the following:
Work out how to change the relevant layer style so that it shows elevations on the map.
Think about what would be an appropriate colour scale to show elevation.
Section 6. Preparing GPX Data for Further Analysis As the tracks layer makes clear, GPX trails and points layers contain a lot of irrelevant data (look at all of those NULLs!) and they are also limited in the sense that we can’t edit them either. To make these files editable, and to be able to perform more advanced analysis, we need to save the GPS data as a shapefile.
Exporting GPX Data to Shapefiles In QGIS this is very straightforward:
Right-click a points layer to show the popup menu.
Select ‘Save As…’
Click ‘Browse’ to navigate to the memorable location (e.g. ‘My Documents’) and give the points layer a memorable name (e.g. ‘James Field Trip 1.shp’).
Make sure that ‘Add saved file to map’ is checked.
And, change the map projection to EPSG:27700 (typing 27700 should bring up ‘OSGB 1936’ as the selected option, which is the British National Grid).
Click ‘OK’.
You will now see a new layer appear in the QGIS. [Hint: this layer should show the exact same data as the original GPX points layer; you can now hide the original data by clicking on the tickbox next to layer that you want to hide in the Layers Panel.]
A Side Note About Map Projections Because GPS has to work everywhere in the world, it uses a coordinate system that works everywhere in the world. For any given part of the world there may be a better, more accurate, more rational system, but it is valid only in that part of the world. This is one of the reasons why we have the Ordnance Survey National Grid only in the UK. In North America there is often a separate grid for each state or province because they are so large. So our GPS data uses WGS84, which is the geographic coordinate system for working out where we are on a globe. Up to this point we’ve basically ignored what coordinates our map was using because QGIS has handled this pretty quietly in the background. Now it becomes relevant: WGS84 doesn’t use the metric system because it’s about positioning us on a real planet, not calculating distances. So if you want to know how far apart two points are or how far you’ve travelled, the raw GPS data is not a very good way to answer that question since the answer depends on where you are on the planet. So when we export our GPS data it makes sense to save it to a relevant local system. In our case that’s OSGB 1936, also known as EPSG:27700. Briefly discuss:
EPSG stands for ‘European Petroleum Standards Group’ – can you think whey the petroleum industry would be interested in maps and, more importantly, why they’d be interested in mapping standards?
Data Cleaning Now let’s tidy up the points shapefile so that it only contains the attributes that we need:
Left-click on the points shapefile (not the original track_points layer) so that it’s active.
Page 9 of 13
Jon Reades; CC BY-NC 4.0
Page 10 of 13
Now select ‘Vector’ from the main menu, then ‘Table Manager’ and, again, ‘Table Manager’ to edit the columns in the shapefile.
Delete every column after (i.e. under) the ‘ele’ (elevation) column.
And ‘Save’ your changes (you don’t really care about keeping a backup).
Over to you! While we’re waiting for everyone to catch up, I’d like you to think about the following question:
Why can’t we use the track layer to find out our speed?
How could we use the track and points layers together to find our average speed?
How could we infer speed between a pair of points?
What would we need to be able to do with the points layer in order to derive speed between every set of points?
Section 7. Calculating Speed Calculating Average Speed Working out average speed would seem fairly straightforward:
We need the start and end times of the GPX track.
We need to know the total distance covered.
Total Walk Time You can find the start and end times in the points layer and can work out the total walking time manually. Total Distance But to answer the ‘total distance’ question we need to export the track as a shapefile using the EPSG:27700 standard!
Using the process from Section 6. Preparing GPX Data for Further Analysis, export the track as a new shapefile.
Right-click on the new layer and select ‘Open Attribute Table’.
Click on the abacus icon (
Set up the calculation as shown in Figure 7 below; you will find $length in the ‘Geometry’ section but you can also just type length into the ‘Search’ box.
Double-click on the $length label and it will be added to the left-hand part of the window.
Click ‘OK’ and a new field should appear at the right side of the attribute table containing the length of the track.
) labelled ‘Field Calculator’.
Page 10 of 13
Jon Reades; CC BY-NC 4.0
Page 11 of 13
Figure 7. Setting Up a Field Calculation
Notice that you can information about the functions available in the right-hand side of the calculator window. So in Figure 7 we can see that length will give us the length of a line or border length of a polygon (a point has no length). There are many other functions available and this is where you can move students from taking geographical data as ‘given’ and enable them to start thinking about manipulating data for an analytical purpose. Over to you! Now that you’ve got those two pieces of information you can work out average speed easily.
Calculating Point-to-Point Speed We are going to do three separate things in order to get this to work:
We need to create attributes that allow us to join each pair of sequential points – the TimeManager plugin aside, QGIS doesn’t really know about ‘time’ in the intuitive way that a human being does so we have to tell it: connect point 1 to point 2, point 2 to point 3, etc.
For reasons that will become clear, we need to convert points to lines in two steps, and that means that we need to merge the results into a single file at the end.
And then we want to do a spatial join so that we can associate the elevation data in the points with the line data that we’ve just created.
It sounds hard, but if we’re careful then it should all go smoothly… Laying the Groundwork Now we need to create some fields that will allow us to join the points into a series of lines:
Open the Attribute table (right-click on the layer).
Turn on editing (click on the pencil icon
Open the ‘field calculator’ so that we can create new columns (
Create a new field called first_seg, which is an integer with width 5.
Type the following into the ‘expression’ area:
CASE WHEN track_se_1 % 2 = 0 THEN track_se_1 ELSE track_se_1 - 1 END Look at what has happened in the attribute table!
). )
Page 11 of 13
Jon Reades; CC BY-NC 4.0
Page 12 of 13
Now create another new field using the field calculator called second_seg: CASE WHEN track_se_1 % 2 = 0 THEN track_se_1 - 1 ELSE track_se_1 END
Fix the first row manually so it’s ‘second’ segment number matches the second segment number of the last row in the Attribute Table.
And click the ‘pencil’ icon again to end the editing session (and Save!).
This is the most complicated operation in the entire practical and I do not expect most students (or staff!) to ‘get it’ – this is a demonstration of a simple computer script applied to a geographical problem. It’s a demonstration of computational thinking, instead of relatively more straightforward mathematical or geographical thinking. What makes it harder is that it’s not immediately obvious what the point of this is: all we did was set up a series of numbers in two columns. The thing to look at is how the numbers are paired in each column, and how these pairs differ between the two columns. Try thinking of them as links and see if that helps you to figure out what’s going on… Over to you!
What do you think that the first_seg field will allow us to do?
What do you think that the second_seg field will allow us to do?
Can you understand why we’ve done this?
Points to Paths Now on to turning points into paths! Again, we will want to use a plugin to automate this task for us and there are two plugins available:
The first option is called ‘PointsToPaths’; however, you won’t see it in the Plugin Manager unless you have gone to the ‘Settings’ and checked the option to ‘Show also experimental plugins’.
The second option is called ‘Points2One’ and is available in the ‘normal’ repository.
As far as I can tell, there is no meaningful difference between the two, although PointsToPaths claims to be better for wildlife tracking. The instructions below have been written for PointsToPaths but should also work with Points2One in the same way as the two plugins are related. Either way, if you don’t already have the plugin installed, please install it now using the Plugin Manager (see instructions on Page 2). To link the GPS points into a single track like the one loaded from tracks, we need to:
Open the PointsToPaths plugin by clicking the icon (
)
The ‘Input layer’ is the layer where we just created the new fields.
The ‘Point group field’ is first_seg
The ‘Point order field’ is track_se_1
The ‘Output shapefile’ should be called something like ‘Segment1’
Have a look at the map – what do you see now?
Now do this again, using second_seg as the group field and saving to ‘Segment2’
That’s the hardest part well out of the way, now we just need to merge our two sets of lines into a single shapefile. You can find the tool to do this under:
Vector > Data Management > Merge Shape Files
You want to check ‘Select by layers in the folder’.
Click ‘Browse’ to find your two shapefiles (Segment1 and Segment2) [Hint: you may need to use the Control [ctrl] button to select more than one file!]
And then save it to something like ‘MyJourney’.
Over to you!
Do you see now why we had to do things in two stages?
Do you see why we’ve had to merge the output shapefiles? Page 12 of 13
Jon Reades; CC BY-NC 4.0
Page 13 of 13
In effect, we’ve just done a piece of computation in the Field Calculator – this is something tedious that a computer can do very quickly, provided that we understand how to tackle the problem. These sorts of tasks might be worth discussing with students who are also taking the new Informatics A-level: why did we break the problem down in this way, and why does it seem so hard to define the problem in a way that a computer can understand and use? [Hint: the issue here is around meaning.]
Using a Spatial Join to Add Data So close, but if you look at the Attribute Table for MyJourney you’ll see that we’ve actually lost the GPS information that we wanted to analyse in the first place! The solution to this is to associate the data from the points with the lines we’ve just created (i.e. a join) using geography as the key:
Vector > Data Management > Join Attributes by Location
Target = MyJourney
Join = Points shapefile
Check the ‘Take summary of intersecting features’
We’ll want the Mean, Min, and Max
And ‘Keep all records’
If you look at the Attribute Table now, you’ll see that it has taken the Mean, Minimum, and Maximum of every numeric field in the points file – if you’ve got time, you could tidy this up using the Table Manager plugin, but the main one we’re interested in MEANele, MINele, and MAXele. Finally, we can derive the length of each segment of the line:
In the Attribute Table turn on editing.
Open the Field Calculator.
And create a new field of type ‘Real’ called ‘Length’ with width 10, precision 5
Now click on ‘Geometry’ in the ‘Function list’ area.
Double-click $length and note the help to the right.
You should have seen $length appear in the Expression area.
Click ‘Ok’
You could convert this to a speed or figure out the ‘true’ length using the Pythagorean theorem, but I think that’s enough for today!
Page 13 of 13