3

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.

1

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

4
  • 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
  • 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. Oct 19 at 19:03
1

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.

Cheers,

0

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 )
1
  • 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.