I am working on a project where I am determining the slopes of sewer pipes.

I have elevations recorded in field called "Elev" in a point shapefile.

In a line shapefile the represents the sewer lines, I have an "UpstreamElev" field that should contain the elevation of the point located at the starting node of the line, and a "DownstreamElev" that that should contain the elevation of the point located at the end node of the line.

What is the best way to add the "Elev" from the point shapefile to the corresponding field in the line shapefile? As it stands, I am manually updating the line shapefile fields by typing in the elevations displayed on the layer labels.

Screenshot of water sewer lines and elevations.

  • "Best" questions are problematic, since they are inherently opinion-based. You haven't mentioned a software platform in the Question body, and have both QGIS and ArcGIS tagged, which makes this two questions.
    – Vince
    Commented Feb 21, 2023 at 17:13

1 Answer 1


With QGIS, you can add Fields to the line (Pipe) layer thanks to the Field Calculator in the Attribute Table:

enter image description here

Where points is the name of the point layer, "Elev" is the elevation field:

aggregate('points','array_agg',"Elev",intersects($geometry,start_point(geometry(@parent))))[0]  --- for the first field

aggregate('points','array_agg',"Elev",intersects($geometry,end_point(geometry(@parent))))[0]  --- for the second field

enter image description here

enter image description here

To then label the lines, you can create a 3rd String field, or use the Label expression to concatenate a string from both Elev fields

  • I don't think it always a given that the order of features returned by overlay_intersects() will be in the desired direction - the default order is based on order of feature creation I think. For example I created elevation points in the order of the line, then deleted one in the middle and re-added it at the end - now the segment has the earlier created vertex ordered first, even though it's downstream. See this example i.imgur.com/lI89Hxp.jpeg
    – she_weeds
    Commented Feb 21, 2023 at 22:09
  • Good catch, I had assumed it was based on the line start/end point order, I'll dig into it and update the answer
    – Kasper
    Commented Feb 21, 2023 at 22:15
  • I couldn't get overlay_intersects() to order based on line_locate_point() (which would show the order along the line), even with storing the parent/line geometry as a variable using with_variable(). I did manage a solution using the older method of aggregate() though - aggregate('Vertices','array_agg',"elevation",intersects($geometry,geometry(@parent)),order_by:=line_locate_point(geometry(@parent),$geometry))
    – she_weeds
    Commented Feb 21, 2023 at 22:23
  • 1
    Yes, or I was thinking about aggregate with intersects($geometry,start_point(geometry(@parent)))[0] as the formal need is the starting point in one column, the end point in another
    – Kasper
    Commented Feb 21, 2023 at 22:26
  • 1
    Yes, that's definitely an option, you just need two separate expressions (one with start_point() and one with end_point()) of course for each field. order_by:=line_locate_point() is probably more concise if you were using the expression directly in the line label field so you can use the one expression to get both points and then concatenate.
    – she_weeds
    Commented Feb 21, 2023 at 22:35

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.