1

I want to be able to assign a point layer a new attribute field with the polyline that the points are within. What method would work best in this scenario?

6
  • Do you already have the polyline or do you need to create the boundary from the points?
    – Cary H
    Feb 22, 2021 at 20:11
  • Hi Cary thanks for chiming in. I already have a polyline layer with a few boundaries.
    – sudofizz
    Feb 22, 2021 at 20:13
  • gis.stackexchange.com/questions/144128/… There are a few possibilities with the standard Processing Menu. If you have not used this yet. Click on the Processing menu item then Toolbox. You may have to change polylines to closed polygons - also in processing.
    – Cary H
    Feb 22, 2021 at 20:25
  • If you are up to some code I have did something similar in the past and can send you the python code.
    – Cary H
    Feb 22, 2021 at 22:05
  • Kadir has a great code answer for you here - gis.stackexchange.com/questions/362436/…
    – Cary H
    Feb 22, 2021 at 22:08

2 Answers 2

1

Use one of these expressions using the overlay functions (available since QGIS 3.16) in field calculator on the points-layer and replace line with the name of your line-layer. You also might need to have to adapt the max_distance:= values, set to 1 here:

array_first(overlay_nearest('line', id, max_distance:=1))

Depending on your data (see below), a simpler expression could also work:

 array_first(overlay_intersects( 'line', id))

An alternative would be: apply a small buffer around your line and than use this expression:

array_first(overlay_within('buffer', id))

Explanation:

In my test setting, overlay_intersects() did not - as it should - reliably identify the points being exactly on the line. I suppose that's because of rounding errors in the saved coordinate values, even if I snapped the points to the line: Snapping is not always reliable in QGIS.

So I had to opt for overlay_nearest() the find the line closest the each point. As this would also assign a value for the points that are not at all on the line, I had to add a maximum distance: only points closer to the line than this one will get a value from the line. So adapt this value: high enough that all points that should be on the line are recognized, small enough that points clearly not on the line are ignored.

Screenshot: the red points are labeled with the first expression from above as being part of line 1 or 2: enter image description here

0

If you could share a screenshot or image it would be easier to provide some more feedback.

Is the polyline enclosed? like a circle/rectangle shape? In that case you can use the polygonize tool to create a polygon from your line features. Then afterwards, use the "Join attributes by Location" tool to combine the attribute field.

In case the lines are not fully enclosed, you could use buffer to create a small polygon, making sure that respective points you want to match fall inside the buffer, and then use the "Join attributes by Location" to combine attributes.

1
  • Hi, the polylines are enclosed and mostly rectangular. I attempted to polygonize and join but I got a NULL field. I get this error: No spatial index exists for input layer, performance will be severely degraded.
    – sudofizz
    Feb 22, 2021 at 21:47

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.