LRS (Linear Reference System) is a spatial reference method where the places along a path have distance measures compared to some specific points, like milestones of a road.
Imagine the following scenario:
You want to automatically create 3 different layer for each new operation added to the table, that is, when you add a line to the table you want that these 3 layers update accordingly. These 3 layers are:
The base layers are only rivers
and operation_table
.
It is important that these 2 tables have a common field that identifies the
river, in this example river_name
for the layer rivers
and route
for the
table operation_table
.
Virtual layers have been introduced long time ago in QGIS and allow you to run real SQL queries on each data type. So if you have shapefiles as input, you can create virtual layers from them without experiencing any problem.
The main advantage? Virtual layers behave like database views: when the source layer values change, views update accordingly.
Another big advantage? Views (and therefore virtual layers) are in place queries of existing data, so nothing is written on the disk.
By using a combination of ST_Line_Interpolate_Point and ST_Length functions we can get the 3 layers that we were looking for.
Moreover, with a smart customization of the QGIS forms we can add a line to the
attribute table of operation_table
(so, a new operation made on rivers) and
the layers will update continuously. Have a look at the small video: