In QGIS I have two layers: a point layer and a polyline layer. Each line starts and ends at a point from the point layer.

For example: Line "ID" 5 from the polyline layer starts at point "ID" 7 from the point layer and ends at point "ID" 9.

Now I want to add two columns to the polyine layer and fill those with the "ID"s of the start point and end point. It doesn't matter which point is the start and which point is the end. I just want both "ID"s in two different fields.

I've tried intersect but that only adds the attributes of one of the points.

Is there a simple solution for this?

3 Answers 3


Maybe try "Vector>Data managment tools>join attributes by location" in Qgis

  • 1
    That works. Thank you. Select polyline layer as target vector Select point layer as join vector Select "Take summary of intersecting features" and select Min and Max QGIS now adds columns with the min_ID and max_ID of the point layer. Since I only have to points for each line these are the two IDs I need. Commented Oct 10, 2016 at 10:39
  • 1
    While this is a valid answer, it might benefit from further expansion. Commented Oct 10, 2016 at 10:42
  • I hit enter to fast. I added details explaining how it gave me the result I needed. Commented Oct 10, 2016 at 10:45
  • When I try this tool, the options are different from what Robert Daniels has. But I run baselayer as a polyline and join layer as point layer, the geometric predicate is intersecting and the others default but it generates another layer which has whole attributes of these two layers and there is no column about start or end id. Actually, our question is the same, if you do any further operations for obtaining the start ids and end ids can you explain to me, Mr. Daniels. Commented Oct 19, 2021 at 19:03

If the order of the points are important (and should correspond to the direction of your polylines), you can use that:
Add a WKT column in your point shp:

geom_to_wkt( $geometry) 

Then use the following for the upstream point:

attribute( get_feature( 'Name_of_point_layer' , 'WKT', geom_to_wkt(start_point($geometry))) , 'ID_of_point_attribute')

and downstream:

attribute( get_feature( 'Name_of_point_layer' , 'WKT', geom_to_wkt(end_point($geometry))) , 'ID_of_point_attribute')

You can also use the plugin Autofields for the different layers for it to work automatically when you add new polylines.


QGIS provides two functions start_point and end_point for this - all you need is to add a new geometry column and then use the field calculator with:

 start_point(  $geometry )
  • Thanks, but I couldn't get this to work. I always get an invalid expression. Commented Oct 10, 2016 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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