1

I am new to QGIS. I am given two layers with point objects. In their attribute table each of this objects has a code (name) given previously to it by someone else. Then I import the lines from AutoCAD that connect those points. For those lines I have created 2 fields in their attribute table that say 'Start point' and 'End point'. In the field 'Start point' in the line object table, I should include the code(name) from the first point object, and in the field 'End point' I should include the name of the end point object.

Since there are many lines like this, and each of them connects 2 point objects, is there an option that can do that automatically without me having to type each code(name) differently?

2
  • How do you decide that a point is start or end point? Commented Feb 12, 2020 at 14:14
  • those lines are cables that connect one pole to each house address. The code for the pole is always a start point and the code for the home address is always an end point.
    – Katerina
    Commented Feb 12, 2020 at 14:19

1 Answer 1

0

Assuming that you have one point layer for the poles and one for the houses, you should be able to get this done using the NNJoin plugin (If your QGIS version is recent you can also use the Join attributes by nearest algorithm).

1) Use NNJoinJoin, with your line layer as Input vector layer, the pole layer as Join vector layer and pole_ as Join prefix. The result is a line layer where for each line, the fields of the nearest pole in the pole layer have been added (the names of these fields will all have pole_ as a prefix), together with the distance from the line to that pole. If you would like to use the distance field from this join, you will have to rename it, so that it is not overwritten in the second step.

2) Use NNJoinJoin, with the output (line) layer from your first join as Input vector layer, the house layer as Join vector layer and house_ as Join prefix. The result is a new line layer where for each line, the field of the nearest house in the house layer has been added (the names of these fields will all have house_ as a prefix), together with the distance from the line to that house.

3) Open the attribute table of the resulting line layer and, using the field calculator, set the value of the Start point field to the value in the pole_name field. Set the value of the End point field to the value in the house_name field in the same way.

4) (optional) Remove the fields that were added from the pole and house layers from the new line layer.

If there are houses closer to the line than the destination house, they will be chosen, because the whole line is considered when searching for the nearest nearest neighbour. To avoid this, you will first have to extract the start and end points of the line and use the resulting point layers for the joining, and afterward join the attribute tables from the results of these joins back into the line layer (remember to include IDs for the lines in the start and end point layers, so that you can join them back after the nearest neighbour join).

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