3

I have a huge vector layer as a line, that represents the river. The problem is that the flow direction is sometimes wrong (goes uphill). But I can't correct that manually, cause the layer is too big.

I also have a DEM for the entire area. So is it a way to reverse only the lines that go uphill? I mean something like selecting the line that the end_point is at a higher altitude than the start_point, and flipping the selection?

1 Answer 1

2

Solution 1

  1. Use select by expression with this expression where DEM is the name of your raster layer (digital elevation model):

    raster_value ('DEM', 1, start_point ($geometry)) <
    raster_value ('DEM', 1, end_point ($geometry))
    
  2. Then reverse line direction for selected features (see screenshot below).

Solution 2

You could also do it directly in one step with Geometry by expression, creating a new layer:

if (
    raster_value( 'DEM', 1, start_point ($geometry)) <
    raster_value( 'DEM', 1, end_point ($geometry)),
    reverse( $geometry),
    $geometry
)

The line at the botten right will be selected: enter image description here

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.