Linear Referencing

The QGis-Plugin "LinearReferencing" supports the measurement of points/sections on reference lines and the acquisition of linearly referenced data sets.

Contents

Principle of linear referencing

"Normal" vector layers save geometrys using numerical coordinates.
"Linearly referenced" layers use numerical stationing on assigned reference lines:
Linear referenced Point-Layer
("PoL", Point-on-Line)
Linear referenced Line-Layer
("LoL", Line-on-Line)
One point per record with reference line assignment and stationing One line segment per record with reference line assignment, two stationings (From...To)
and an additional offset defining the distance from segment to reference line
f.e. Structures on a watercourse:
f.e. Segments on a watercourse:

Required layers

The plugin uses three layers to capture and display a linearly referenced dataset:
Reference-Layer
On the Linestring-Geometries of this layer the assigned linearly referenced features are numerically positioned.
  • Vectorlayer
  • QGis-supported format (GeoPackage, SQLite, SpatiaLite, Shape, Geo-Database...)
  • Type LineString (LineString, LineStringM, LineStringZ, LineStringZM, MultiLineString, MultiLineStringM, MultiLineStringZ, MultiLineStringZM)
  • Any projection
  • unique ID-Field required
  • unique Digitizing direction
    In the examples of watercourses shown here, digitization is generally carried out against flow-direction.
  • LR-Mode "Nabs" and "Nfract":
    • Multi layer types possible, but only one-piece geometrys or multi-part and consecutive without gaps supported
  • LR-Mode "Mabs":
    • Reference layer type with M-values
    • M-Values strictly ascending (see SpatiaLite, functions ST_IsValidTrajectory and ST_TrajectoryInterpolatePoint)
    • Multi layer types possible, but only one-piece geometrys supported
Note on snapping:
The plugin applies "Advanced Configuration", Type "Segment, Line-Endpoints" and a tolerance of 10px to the registered reference layer.
Data-Layer
Stores assignments to reference layer, stationing(s) and any other informations.
  • geometryless vector layer
  • QGis-supported formats (dBase, GeoPackage, SQLite, SpatiaLite, database, office spreadsheets)
Show-Layer
Cartographic representation of the linearly referenced features.
  • virtual layer
  • SQL-query using reference- and data layer
  • SpatiaLite expression in query calculates geometrys (possibly less performant)
  • Projection according to reference layer
  • runs independend from plugin
Notes:
  • Without data- or show-layer the plugin can still be used for measuring.
  • Changes to data or reference layer (fields renamed/deleted/added) or the plugin-settings (registered layers/fields, LR-Mode...) can harm the SQL-query of the virtual layer, revise query if necessary or create a new one

"LR-Mode"

The position of a point on a line can be described numerically in various ways:
  • Running length absolute
  • Running length relative to total length
  • Running length as percentage of total length
  • referencing start of line
  • referencing end of line
  • by use of Vertex-M-Values
  • as vector-layer (without linear referencing)
  • mixed, f.e. stationings calculated from point layer snapped to reference layer
  • ...
The plugin implements the variants
  • "Nabs"
    absolute natural stationing (running length to startpoint of assigned reference line)
    Value range: 0 ... length of line
  • "Nfract"
    relative natural stationing (running length/total length)
    Value range: 0 ... 1
  • "Mabs"
    M-stationing (using Vertex-M-values)
    Value range: M-values first ... last vertex of assigned reference line

Effects of reference geometry changes on linear referenced geometrys

(see Post-Processing)
Example reference geometry:
  • LinestringM
  • Vertices vertically at one height, horizontal distance 10m
  • M-Value == Vertex-Index
  • WKT
    LineStringM (310900 5650000 0, 310910 5650000 1, 310920 5650000 2, 310930 5650000 3, 310940 5650000 4, 310950 5650000 5, 310960 5650000 6, 310970 5650000 7, 310980 5650000 8, 310990 5650000 9, 311000 5650000 10)
Example LoL-Layer:
  • one data-layer for three LR-Modes
  • Sections 1 to 10 start/end on the vertices
  • Sections 11 to 15 subdivide section 7

(identical presentation for the three show-layers regardless of LR-mode)
Demo-edit of the reference-geometry:
Vertex 6 moved 25 meters to the north:
Effects on the to linear referenced geometries:
Nabs Nfract Mabs
Auxiliary idea:
  • The reference line vertices are a series of posts.
  • The referenced sections form a rigid rope and are color-coded on it
  • The rope is knotted to the first post and slid over the other posts
  • Post 6 is moved, the rope is too short, slides, the markings move in the rear area, the last posts are no longer connected.
  • No change in the front area
  • The overall length of the rope and the spacing of the markings remain unchanged
Auxiliary idea:
  • The reference line vertices are a series of posts.
  • The referenced sections form an elastic cord and are color-coded on it
  • The rope is knotted to the first and last post and slid over the other posts
  • Post 6 is moved, the elastic rope extends evenly and glides over all intermediate posts
  • All markers change their length and position
  • The overall length of the rope changes
  • The length ratios relative to the overall length stay retained
Auxiliary idea:
  • The reference line vertices are a series of posts.
  • The referenced sections form an elastic cord and are color-coded on it
  • The rope is knotted to all posts
  • Post 6 is moved, the elastic rope extends in the area of posts 5, 6 and 7
  • The areas outside posts 5, 6 and 7 remain unchanged
  • The overall length of the rope changes
  • All markings are still on the posts
  • The length ratios relative to the total length change
  • The length ratios between the posts remain unchanged
Advantages/disadvantages (depending on use case, without claim to completeness):
Advantages:
  • Classic representation for stationings
  • Easy to verify in GIS/nature (simply remeasure)
  • Comprehensible numerical editing (f.e. move all sections by a constant amount)
  • Simple usage in calculations f.e. section length == difference from...to stationing
  • Changes of trailing vertices without influence to stationings
Advantages:
  • the mode of choice for relative use cases
  • easy relative positioning (0 ➞ start ... 1 ➞ ende of reference-line)
  • less depending on projection
Advantages:
  • Reference geometry changes only affect linear referenced geometries in the adjacent areas
  • Vertex-M-values independend from "natural" stationings (f.e. usage of timestamps from GPS-recordings)
  • Vertex-M-values independend from projection (f.e. metric stationings for a WGS-84-reference layer)
  • less projection-dependent
  • stationings with offsets possible:
    • Offset > 0: Continuation of stationing in another reference shape
      here:
      Border crossing of the river "Rur" (Germany) to Netherland ("Roer") (the geometry parts DE/NL as separate data records.)
      DE-reference point is not the border crossing, but a point with Vertex-M == 0 in the Netherlands (see below).
    • Offset < 0: Stationings not starting at first vertex
      here:
      Mouth of Rur/Roer into the following water body Maas/Meuse in the Netherlands
      Reference point ist not the intersection of the (fictitious) water axes, but but an (agreed) point with Vertex-M == 0 on the shoreline.
    • The M values of the other vertices correspond to the natural stationing + offset
    • Samples taken from Gewässerstationierungskarte NRW (Water stationing map of north-rhine westfalia)
  • Areas with compressed/stretched positioning possible
Disadvantages:
  • depending on projection: the positions are calculated using the numerical and projected X/Y coordinates
  • Maximal stationing == total length of reference-shape
    ➞ shortening the reference line can cut off linear referenced geometries
  • Changes of leading vertices will influence all stationings (conversion: old stationing +- length change)
Disadvantages:
  • difficult to verify in GIS/nature
  • Modifications of the reference geometry will alter the position of all linear referenced points (while maintaining their relative positions)
Disadvantages:
  • difficult to verify in GIS/nature
  • after reference-geometry changes and/or recording, the corresponding M values must be re-entered (vertex editor) or calculated
  • complex effects of reference geometry edits on the linear referenced geometries, because their positions are influenced by both, cartographic visible edits (move/add/delete vertices) and cartographic not visible vertex-M-alterations.

Conversion

A subsequent change of the LR-mode requires the recaclulation of already recorded data.
Recommended procedure:
  1. (possibly create a backup copy of the data layer)
  2. start edit session on data-layer
  3. additional numerical field for stationing
  4. open field calculator for data-layer
  5. perform conversion (expression see below, in case of LoL for both stationing fields)
  6. configure new LR-mode in plugin-settings
  7. create show-layer for new mode
  8. visually compare the results of the two show-layers
  9. stop (and eventually save) edit session
Expressions for field calculator
(adapt labels for layers and fields!)
"Nabs" ➞ "Nfract":
"_data_layer_stationing_field_n_abs_" / length(
	geometry(
		get_feature(
			'_reference_layer_',
			'_reference_layer_id_field_',
			"_data_layer_reference_field_"
		)
	)
)
"Nabs" ➞ "Mabs":
m(
	line_interpolate_point(
		geometry(
			get_feature(
				'_reference_layer_',
				'_reference_layer_id_field_',
				"_data_layer_reference_field_"
			)
		),
		"_data_layer_stationing_field_n_abs_"
	)
)
"Nfract" ➞ "Nabs":
"_data_layer_stationing_field_n_fract_" * length(
	geometry(
		get_feature(
			'_reference_layer_',
			'_reference_layer_id_field_',
			"_data_layer_reference_field_"
		)
	)
)
"Nfract" ➞ "Mabs":
m(
	line_interpolate_point(
		geometry(
			get_feature(
				'_reference_layer_',
				'_reference_layer_id_field_',
				"_data_layer_reference_field_"
			)
		),
		"_data_layer_stationing_field_n_fract_" * length(
			geometry(
				get_feature(
					'_reference_layer_',
					'_reference_layer_id_field_',
					"_data_layer_reference_field_"
				)
			)
		)
	)
)
"Mabs" ➞ "Nabs" bzw. "Mabs" ➞ "Nfract"
QGis currently doesn't offer a function for simple conversion from M- to N-stationings (see docs.qgis.org/.../expressions/functions_list.html), as workaroand define a custom function like get_point_m_2.py in field calculator/function editor (copy&paste)... and use it aferwards in the expression:
"Mabs" ➞ "Nabs"
get_point_m_2(
	geometry(
		get_feature(
			'_reference_layer_',
			'_reference_layer_id_field_',
			"_data_layer_reference_field_"
		)
	),
	"_data_layer_stationing_field_m_abs_"
)
"Mabs" ➞ "Nfract"
get_point_m_2(
	geometry(
		get_feature(
			'_reference_layer_',
			'_reference_layer_id_field_',
			"_data_layer_reference_field_"
		)
	),
	"_data_layer_stationing_field_m_abs_"
) / length(
	geometry(
		get_feature(
			'_reference_layer_',
			'_reference_layer_id_field_',
			"_data_layer_reference_field_"
		)
	)
)

Usage

Settings

PoL LoL
Point-on-Line Line-on-Line
Layers and fields:
Reference-Layer
  • When first called up, a line layer loaded is automatically registered.
  • After selection of the reference layer the plugin can already be used for measurements.
  • A unique ID field (integer/string) is required to link the data layer
Data-Layer
PoL LoL
  • ID-field ➞ unique field for 1:1-link to Show-layer (back reference field)
  • reference-field ➞ relationship field to reference-Layer (reference-layer-ID-field)
  • stationings-field ➞ numerical field for stationing
  • LR-mode ➞ Type of numerical stationing, see LR-mode
  • Precision ➞ number of decimals (independend from field-definition, "-1" ➞ maximal precision, also used as display-precision in Feature-Selection and PostProcessing)
  • ID-field ➞ unique field for 1:1-link to Show-layer (Back-Reference-Field)
  • Reference-Field ➞ relationship field to reference-Layer (reference-layer-ID-field)
  • Offset-Field ➞ Offset between segment and reference line
  • From-Field ➞ numerical field for From-stationing
  • To-Field ➞ numerical field for To-stationing
  • LR-mode ➞ Type of the numerical stationing, see LR-mode
  • Precision ➞ number of decimals (independend from field-definition, "-1" ➞ maximal precision, also used as display-precision in Feature-Selection and PostProcessing)
Show-Layer
Back-Reference-Field ➞ 1:1-link to data-layer ID-field
Style: Customize the style of the temporary auxiliary graphics
PoL LoL
Store/Restore Configuration:
  • Stores current settings (layers, fields, style)
  • Number of configurations in current QGis-Project ist limited to 100.
  • Helpful when using several linearly referenced layers inside a project.
Miscellaneous:
  • opens attrribute-table for reference-, data or show layer
  • opens expression builder for "Display Name", used in QGis for identify and attribute-tables as well as in the plugin Feature-- and Post-Processing-Selection.
  • Create new preconfigured data- or show layer

Measurement

Procedure:
PoL LoL
  1. Dialog: open register "Measurement"
  2. Dialog: Press button [ New Measurement]
  3. Canvas: Move the mouse pointer on the reference line
    ➞ Continuous output of measured values (reference-feature and stationings)
  4. Canvas: Click on reference line
    ➞ fix measured values in dialog
    ➞ show measurement graphically on map
    ➞ measurement finished
  5. repeat mouse-click on reference-line or press [ New Measurement ] to continue
  1. Dialog: open register "Measurement"
  2. Dialog: Press button [ New Measurement]
  3. Canvas: Move the mouse pointer on the reference line
    ➞ Continuous output of measured From-values (reference-feature and stationings)
  4. Canvas: MouseDown on reference-line , hold mousebutton
    ➞ fix reference-feature in dialog
    ➞ fix measured From-Values in dialog
    ➞ show From measurement graphically on map
  5. Canvas: MouseMove with button pressed on reference-line
    ➞ Continuous output of measured To- and Difference-values
    ➞ Show To-measurement and segment graphically on map
  6. Canvas: MouseUp on reference-line
    ➞ fix all measurements in dialog
    ➞ measurement finished
  7. repeat mouse-Down/Move/Up on reference line or press [ New Measurement ] to continue
Results:
  1. selected reference-feature Open formular Zoom to feature
  2. cursor- and snap-coords X/Y
  3. absolute natural distance to start-point of reference line
    editable via spin-buttons or numerical input
  4. relative natural distance to start-point of reference line (percentage, editable via spin-buttons or numerical input)
  5. absolute M-distance to start-point of reference line
    editable via spin-buttons or numerical input
  6. relative M-distance to start-point of reference line (percentage, editable via spin-buttons or numerical input)
  7. interpolated Z-value
  8. Follow-up functions:
    move point to start of reference line
    move point in direction of startpoint
    Insert new record
    Update selected recors (feature-ID displayed)
    New measurement: reset dialog and start new measurement
    move point in direction of endpoint
    move point to endpoint of reference line
    Zoom to point
    interactive move point on selected reference line
  1. selected reference-feature Open formular Zoom to feature
  2. cursor-coordinates From/To X/Y
    input field for distance segment to reference line
    ➞ move from-point
    ➞ move to-point
    Snap-coordinates From/To X/Y
  3. absolute natural distance From/To to start-point of reference line and difference
    editable via spin-buttons or numerical input
  4. relative natural distance From/To to start-point of reference line and difference (percentage, editable via spin-buttons or numerical input)
  5. absolute M-distance From/To to start-point of reference line and difference
    editable via spin-buttons or numerical input
  6. relative M-distance From/To to start-point of reference line and difference (percentage, editable via spin-buttons or mittels numerical input)
  7. interpolated Z-value From/To and difference
  8. Follow-up functions:
    move segment to start of reference line setzen
    flip segment in direction of start (old From ➞ new To)
    move segment in direction start
    Insert new record
    Update selected record (feature-ID displayed)
    New Measurement: reset dialog, start new measurement
    move segment in direction of end
    flip segment in direction of end (old To ➞ new From)
    move segment to the end of reference line
    interactive move segment on selected reference line
    interactive set distance segment to reference line
    Zoom to segment
Instead of interactive measurement, you can select reference line in dialog and enter numerical stationings manually

Feature-Selection

In this table you can collect, visualize and edit a user-defined collection of linear referenced features.
Procedure:
Dialog: open the tab "Feature-Selection":

  • [Data-Layer] ➞  fetch records from data-layer
  • [ Show-Layer] ➞ fetch records from show-layer
  •  ➞  open data/show layer attribute table , select from table see Feature-selection from attribute forms and tables
  •  ➞  interactive selection from map *
Result:
PoL LoL
  • remove from feature-selection
  • open attribute form
  • show feature on map
  • select record in layer
  • delete record
  • move feature on reference line (stationing)
  • reposition feature (reference + stationing)
  • remove from feature-selection
  • open attribute form
  • show feature on map
  • select record in layer
  • delete record
  • move feature on reference line (stationing)
  • reposition feature (reference + stationing)
  • move from-point on reference line
  • move to-point on reference line
  • change distance segment...reference line
click on table-row ➞ select feature, highlight on map, show meta-data in Measurement-Tab
for the textual contents of reference-, data- and show-layer the layer-property "Display Name" is used, accessible via standard-dialog or [] in the Plugin-Settings-Tab
for display-precision of stationings see precision in Data-Layer-Settings
Faulty features are marked with red text color, the error-reason is indicated in the FlyOut
Note:
The plugin treads records with stationings out of value-range as "faulty", because they can lead to faulty calculations (f.e. segment-length from difference Nabs-from-to-stationings).
In show-layer these records are nevertheless displayed and positioned to start/end of the assigned reference line.
Follow-up functions:
  • [ Zoom to selection]
  • [ Clear selection]
  • [ Select in layer] ➞ selects these features in data- and show-layer
  • [ Selection as filter] ➞ use selection to filter data- and show-layer

Feature-selection from attribute forms and tables:

The plugin implements "Layer-Actions" on the registered data- and show-Layer to select features out of attribute forms and tables:

Post-Processing

Edits of reference-geometries can affect linear referenced geometries, the decisive factor is:
  • the kind of reference-geometry-change (move geometry, move/add/delete vertex)
  • the LR-mode
  • the position of the reference-geometry-edit relative to the linear referenced positions

Example:

After renaturation, the original course of the river was edited in QGis which unintentionally changed the position in some other layers...
Initial situation:
  • reference-layer with water courses
  • PoL-Layer: Structures on water courses (bridges, culverts ...)
  • LoL-Layer: Sections of use next to the watercourses
  • LR-mode "Nabs" (natural stationing)
  • reference-layer and linear referenced layers loaded to the same QGis-project
  • plugin-dialogs once opened before edit-session of the reference layer started (initialization)
PoL LoL
before:
after:
the following points (in digitize-direction) have moved by the dimension of the extension in direction of mouth (previous points not affected with LR-mode "Nabs") the following segments (in digitize-direction) have moved by the dimension of the extension in direction of mouth rsp. adapted to the new course (previous segments not affected with LR-mode "Nabs").
Post-Processing-Dialog:
PoL LoL
  • highlight feature on map
  • open attribute form
  • show edits in referencelayer
  • remove row from table (ends post-processing for this feature)
  • move geometry interactive
  • delete record
  • highlight feature on map
  • open attribute form
  • show edits in referencelayer
  • remove row from table (ends post-processing for this feature)
  • move geometry interactive
  • delete record
  • move from-point
  • move to-point
click on table-row ➞ select feature and highlight on map
for the textual contents of reference- and data-layer the layer-property "Display Name" is used, accessible via standard-dialog or [] in the Plugin-Settings-Tab
for display-precision of stationings see precision in Data-Layer-Settings
Follow-up functions:
  • [ Zoom to selection]
  • [ Clear selection] (ends post-processing)
The number of Post-Processing-Features is limited to 100 reference lines with total 500 linear referenced features.

Development and Support

<<    <     >    >>