5

I have polyline strings with vertices of known elevation / z height and intermediate vertices with null/zero height. Known Zs are spread throughout the line. I'd like to be able to populate the z of the intermediate vertices by linear interpolation between those known points.

I think this is functionality in Arc using IZ.InterpolateZsBetween? Unable to verify due to no Arc access. Seeking functionality in QGIS or any alternative open package?

1
  • I have the exact same issue and would love some hints, too.
    – dru87
    Commented Feb 5, 2021 at 16:23

1 Answer 1

3

Z-values can be added to the vertices of lines by an operation called drape. This is normally done from a raster. Thus we have to get a raster, containing the interpolated z-values. What is a bit tricky: You can't have NULL values for z, they are automatically set to 0. So if you have vertex1 with z=100, vertex2 z=0 and vertex3 z=200, you probably want z for vertex 2 to be 150. So we first have to replace values of 0 with the mean of the value before and after this vertex.

The whole workflow looks as this:

  1. Extract the vertices from you line using Menu Vector / Geomtry Tools / Extract vertices.

  2. On the extracted vertices, create a new field called z using Field calculator. Use the following expression - it checks if the z-value is 0 and in this case, it interpolates the z-value between the last and the next point (creating the mean of the two z-values, see screenshot at the bottom):

     if (
         z($geometry) =0, 
         (z(geometry (get_feature_by_id (@layer, $id-1)))+z(geometry (get_feature_by_id (@layer, $id+1))))/2,
         z($geometry)
     )
    
  3. Create a buffer around your points with a size so that they do not overlap.

  4. Rasterize the buffers and set the field z (calculated in step 2) as Field to use for a burn-in-value.

  5. Use Menu Processing / Toolbox / Drape (set Z value from raster) with your initial line as input and the raster from step 4 as raster layer. This will add the values from the raster (that correspond to the interpolated z-values from step 2) as new z-values to your line.

You can now densify your line using Densify by inerval: thus adding additional vertices. z-values are then automatically interpolated.

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.