3

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?

  • 1
    Have you tried join attributes by location? If so, using which parameters and how does the outcome not suit your needs? – Erik May 23 at 10:44
  • I have, but each point lies between two separate lines. So I need to be able to specify that the join occurs for the start of the desired line, not the end of the unwanted line. Only one of the lines is to share the data with a particular point. – Mick May 23 at 11:05
  • I can see that somehow I need to be able to access the line geometry startpoint in a join operation but not sure how this can be achieved. – Mick May 23 at 11:18
  • Each line has the start and end of its geometry in a specific orientation. In other words the start of one line is always at the end of the other. In doing more research, I feel the start of a solution may be to extract the use the field calculator to store X and Y of the start_point, then somehow use this. – Mick May 23 at 11:42
  • The lines started out as one line and were divided using SAGA Split lines at points. – Mick May 23 at 11:52
5

Tested on QGIS 2.18 and QGIS 3.4

I can suggest using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer...

Let's assume we have 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 achieve the result

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

  • thankyou @Taras, that seems to be exactly what I need, however I can't get that to work. I've even renamed my 2 layers to rivers and some_points and renamed one of the fields in some_points to DataField, but it throws up an error. – Mick May 23 at 12:44
  • It's working now - I needed to clean up some data. Thanks for your help. – Mick May 23 at 14:04
  • 1
    Don’t forget to accept the answer if it solves your issue. Otherwise request for more solutions indicating your methodological requirements. – Taras May 23 at 14:14
  • 1
    Thanks again Taras – Mick May 23 at 22:29
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.