By David Crowther
In a recent blog, I started to explore some advanced Data Maintenance functions that are available within QGIS. These included editing table structures, updating columns, attribute and spatial table joins. Why not start by exploring that blog in our Cadline Community website:
In this blog, we will now explore two extra functions, Group Stats and Auto Trace, which I encountered while delivering a QGIS training course for one of Cadlines DynamicMaps clients.
During a recent QGIS course, the delegates wanted to know if it was possible to group and count records in the attribute table. This question came because the delegates were previous MapInfo Pro users and were used to utilsiing the SQL Select command in MapInfo which allows you to write simple SQL queries as well as group, count and order data. After a little bit of research we came across the QIS plugin – Group Stats.
In the previous QGIS Data Maintenance blog we joined the Ashfield Bus Stop points to the Ashfield LSOA polygons to generate a count of Bus Stops per LSOA area:
If we now wish to calculate how many Bus Stops there are per Ward area, we can use the Group Stats plugin.
From the Vector menu choose Group Stats > Group Stats:
The Group Stats acts similar to an Excel Pivot table, allowing you to choose which is the unique field to group on and then what values to count and group. For example, we will use the following settings for the Ashfield_LSOA_BusStops layer:
- Rows – STWARD_NAM: this will be used as the unique field to GROUP each of the LSOA polygons.
- Columns – Sum and Count: this will define what extra fields, in addition to the STWARD_NAM, we which to reveal.
- Value – BusCounts: this is the field within the Ashfield_LSOA_BusStops layer that contains numerical values that will be summed together for each unique Ward Name.
Simply drag and drop the fields as required into the 4 boxes in the bottom right, and then press Calculate to generate the Pivot table:
Tip – you will need to ensure that your BusCounts field is in REAL format, so that the Group Stats tool recognises the field to be numeric and can therefore calculate a Sum, Max, Median, Variance etc.
While undertaking the Data Editing module within our Intro to QGIS course, a common question asked is whether you can trace and snap against existing features. This is a typical GIS routine that both MapInfo and ArcGIS perform – and also one that is well catered for within QGIS! From the View menu choose Toolbars > Advanced Digitising Toolbar and a new editing toolbar will appear.
If we toggle the editing mode for the layer that we wish to edit , notice that both the edit and advanced digitising toolbar become active.
In order to snap and trace you will need to open an existing layer, for example in this case we have opened OS Mastermap buildings. To enable snapping choose the Settings > Snapping Options menu:
Using the Advanced layer selection method, you can choose snapping options for any of the layers in your QGIS project. For the OS Mastermap layer we will choose the Mode to be Vertex and Segment, which will allow you to snap to the nodes and the line segments of the OS Mastermap features. Use the Tolerance setting to decide how accurate you are when using the snap tool. In this case set the value to be 2.
Start your digitising by snapping to a corner or any location along the segment of the OS Mastermap building,…
… and then move your cursor along the building to another location and you can see that the editing tool is now snapping and tracing along the OS Mastermap feature.
Continue to move along the outside of the building and the trace tool will create the new feature by snapping to and tracing the existing nodes without you having to even click in the map.
Once you are ready to finish the object simply left click and the polygon feature will be completed, with all nodes between the start and end point now inserted. This method means you can trace around highly complex objects without having to click to insert points on everything single vertex!
Try exploring these two new Data Maintenance tasks for yourself and see just how easy it is to transition from proprietary software to start managing and working with your spatial data within an Open Source application!