“Virtual layers provide a way to use data that is computed 'on the fly' as the basis for a layer”
In this module, we look at how you can use virtual layers to minimise data duplication and dynamically compute new information from a base dataset.
Goal: To learn how to create a virtual polygon layer based on buffered points.
Check your results:
Once your virtual layer is created, it should show a buffered (to the distance of canopy diameter) polygon around each tree point.
Name | Expectation |
---|---|
CRS |
UTM 34S, WSG84 |
Attribute: species |
Text, length 255 |
Attribute: canopy |
Decimal number, length 10, precision 3 |
Attribute: height |
Decimal number, length 20, precision 3 |
Virtual layer query: |
select id, buffer(geometry, canopy) as geometry, canopy, height, species from trees |
The virtual layers are dynamic - whenever you update the base layers that the virtual layer is defined from, the virtual layer will update too. This can save a lot of overhead in terms of file space and data duplication since you can have the virtual layer derive extra data from the base layers without saving anything to disk.
You can use SQL like constructs to define your virtual layer. Because the virtual layer is dependent on other layers / data-sources, you need to be careful not to rename/ move/ delete the base layers.
There can be a performance overhead when using virtual layers - especially when the virtual layer is defined with a complex query or does complex geometry operations.
When adding/ changing data in the base layers, you will need to refresh the map display (e.g. pan/zoom) in order to see the virtual layer dynamically update.
A virtual layer is:
What do you think this virtual layer will do when based on our trees example: