By Gyenes Márton

2019-01-10 11:58:52 8 Comments

I have a linear shape, all of the vertexes of each segment has a z-value, stored in the geometry.

I need for every record, segment the average, min and max height value aggregated from their vertex heights.

How would I get this information using the field calculator?

I'm using QGIS 3.4 Madeira.


@Gyenes Márton 2019-01-11 08:53:38

After suggestions, I was able to create the dataset. The steps:

  1. I used drape function from processing toolbox to add z value to each vertex of the linear objects
  2. from vector/geometry tools I used extract vertexes function and got a point layer
  3. from vector/geometry tools I used add geometry attribute function on the new point layer
  4. in DB manager I ran 3 queries on the resulting layer of the geometry attribute generation to select the min, max and avg values for each unique id:

select unique_id, max(zcoord) from 'added geom info'
where unique_id=unique_id
group by unique_id 

I added the query results to the project, and with a simple join, based on unique_id I was able to add the good values to each records.

@TeddyTedTed 2019-01-10 14:56:35

For entire line features:

Use the 'Extract Vertices' tool to turn all vertices into points.

In the new points layer create a new field for the height value and populate it using:


Now use 'Join Attributes By Location (Summary)' and join the line feature to the vertices (you may want to delete some of the fields automatically created by extracting the vertices first).

The new Joined Layer will be automatically populated with statistics about the joined attributes, including mean, min, and max.

This will maintain the original IDs, it will result in a lot of unwanted fields which you may want to delete.

For individual segments:

Use 'Explode Lines' to convert the whole line feature into individual segments.

You might have to 'Drape' the result again to restore the z-values.

Create two new columns in the segments layer for the start and end height, in field calculator use the following:





from those values you can create new columns for average, min, and max using the following field calculations:


("start_height" + "end_height") / 2


min("start_height", "end_height")


max("start_height", "end_height")

@Gyenes Márton 2019-01-10 16:00:25

My problems with this solution. 1. I have to keep the original segments unexploded. 2. I have to keep the original segment IDs of the segments. 3. I need the mean, max and min z values derived from of the whole segments' vertexes. On the other hand it may help. I will try to extract the vertexes into point shape, transfer the original ID-s to each object, and try to collect the information from this layer. Thanks

@TeddyTedTed 2019-01-10 16:15:48

Ah I see, edited answer.

Related Questions

Sponsored Content

1 Answered Questions

[SOLVED] Calculate slope of line segments with QGIS

  • 2018-03-03 15:53:56
  • Quarantäne
  • 363 View
  • 1 Score
  • 1 Answer
  • Tags:   qgis line slope

1 Answered Questions

[SOLVED] Compute weight value based on other attributes?

0 Answered Questions

Granularity of elevation in GMTED2010 data / understanding shapefiles

1 Answered Questions

1 Answered Questions

1 Answered Questions

1 Answered Questions

2 Answered Questions

Sponsored Content