You can easily add a new function to get array of z-values from line vertices.
Open Function Editor tab in Field Calculator (or Expression) window. Create a new function by clicking plus icon. Enter a file name, e.g.
z_array_from_line
.Copy/Paste the script. Then, click
Save and Load Functions
(or related button) to register the function. It's added 'Custom' group.from qgis.core import * from qgis.gui import * @qgsfunction(args=0, group='Custom') def get_z_array_from_line_vertices(value1, feature, parent): z_array = [p.z() for p in feature.geometry().vertices()] return z_array
Now, you can use
get_z_array_from_line_vertices()
function in expressions.
The function gives you z-values in the same order as the vertices.
EDIT:
But max()
function in Expression is expecting set of values like max(1,2,3)
, not list or array like max([1,2,3])
. If you need maximum value you can add python max()
which excepts list to the definition of the function or save as a new one.
from qgis.core import *
from qgis.gui import *
@qgsfunction(args=0, group='Custom')
def max_z_value_from_line_vertices(value, feature, parent):
z_array = [p.x() for p in feature.geometry().vertices()]
return max(z_array)