I am trying to extract co-ordinate and height data from a contour layer imported from a .shp file. I have loaded the file into QGIS and am attempting to access with Python the height values of each feature - Closest vertex Z or Interpolated Z in the picture below.
I am eventually aiming for something similar to what is achieved in this answer https://gis.stackexchange.com/a/41922/172876, but I can't find a way to adapt their solution to work for me. I have looked through several forum posts, but many rely on using rasters to extract z values, or are using points not contours.
I have been able to select features in the contour layer, and access their attributes using:
layer = iface.activeLayer()
for feature in layer.selectedFeatures():
attrs = feature.attributes()
print(attrs)
But this only accesses the attributes pictured below, and none of the attributes under the (Derived) dropdown in the picture above, which is where the Z values are.
How do I access and extract these using PyQGIS?