TransWikia.com

QGIS Assign point data to a line layer considering line direction

Geographic Information Systems Asked on February 1, 2021

I have a line layer representing a river bank. The river bank is divided in numerous separate line features representing zones, each separate line has many vertices. The lines have a set direction.

I also have a points layer. The points are located at the start of each line (and therefore the end of the preceding line if following in the line direction). The points contain data.

I wish to assign the data associated with each point to the line segment following it, when considering the line direction.

Does anyone know of a way to achieve this utilising QGIS?

2 Answers

There is a possibility using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer...

Let's assume there are five features in 'rivers' (for simplification "id" is equal to "Zone") and five features in 'some_points' layer accordingly, where points are located at the start of each 'rivers''s feature, see image below.

Original_data

With the following query, it is possible to assign the data associated with each point to the line segment following it, when considering the line direction.

SELECT r.*, sp.DataField
FROM rivers AS r, some_points AS sp 
WHERE st_intersects(StartPoint(r.geometry),sp.geometry)

The output Virtual Layer will maintain initial attributes and geometries of 'rivers' and additional field "DataField" from 'some_points' layer.

Output

Answered by Taras on February 1, 2021

Here's another approach using the QGIS Field Calculator (if SQL and Virtual Layers are not your things - although personally, I'm a big fan).

Add a calculated field to the 'rivers' layer:

aggregate(layer:='some_points',
          aggregate:='max',
          expression:="DataField",
          filter:=intersects($geometry, start_point(geometry(@parent)))
          )

This will retrieve the maximum value (there should be only one anyway) of "DataField" from the 'some_points' layer where the point intersects the first point of the 'rivers' geometries.

This will only work in QGIS 3. If you want multiple values from the 'some_points' layer you would need to add a calculated column for each one.

If you want lots of columns or need to support QGIS 2 the virtual layers from @Taras is the way to go.

Answered by M Bain on February 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP