Virtual layers in QGIS and the task of identifying spatially coincident point features
A typical housekeeping task in my workplace is finding historic drillholes that have been entered into a database in an approximate manner, all with the same coordinates (and not their correct position)!. This may have happened for several valid reasons including when the location of the holes in an old investigation was not provided, other than on a basic plan, and those entering the data did not have time to determine accurate coordinates. The other situation is when a drill hole has been entered multiple times into a database by mistake and possibly given a different name that makes it difficult to easily identify by a standard attribute search.
So is it possible to find point features (such as drill holes or sample locations) that have been given coincident coordinates in order to fix them? While there may be several ways of doing this, the answer is surprisingly simple through the use of virtual layers in QGIS!Virtual layers allows the power of SQL database functionality to be applied to a layer or layers without need to change the data. The layer may be a local feature class or shapefile, or even an external database(s) such as a Web Feature Service, and if this is the case, there is no need to make a local copy.
Some of the capabilities SQL can do include:
- 1. Attribute tables can be changed (alias field names assigned, filters applied, etc)
- 2. Virtual joins to other layers are possible
- 3. Aggregate functionalities can be applied: max, min, count, etc.
Normally one would use an aggregate function on an attribute table field to do this, but QGIS allows the geometry field to be considered as well. Given this surprising capability, the following syntax can be used on a virtual layer (in this case the file name is drilling and a temporary field name, DuplicateRecords, has been created to store the count of duplicate records).
group by geometry
The virtual layer will appear as a point file that can be labelled, symbolised and filtered using the DuplicateRecords field. The virtual layer does not have an identifier field but if you load the database as a regular layer in QGIS as well you can identify individual records. By assigning the corrected coordinates to each feature the virtual layer will reflect the updates.
Try this on a real drill hole database sometime such as the boreholes layer (a Web Feature Service) on the Mineral Resources Tasmania website where there are some problematic drillholes still to sort out.
I hope I have explained this properly. Let me know if it is confusing and I can provide some screen grabs! There may be a more elegant use of SQL syntax than what I provided but start simple!
Regards
Colin
(colinintas@gmail.com)
Comments
Post a Comment