I've got 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 IDs 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 IDs 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? I'm using QGIS.


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. Oct 10 '16 at 10:39
  • While this is a valid answer, it might benefit from further expansion. Oct 10 '16 at 10:42
  • I hit enter to fast. I added details explaining how it gave me the result I needed. Oct 10 '16 at 10:45

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 automatocally 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. Oct 10 '16 at 10:53

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.