3

When I edit a vector layer in qgis, I select a lineString using Node Tool and I can see z coordinate of points in "Vertex Editor". In the image,we can see x,y,z coordinates of a list of points. But how can I get z coordinate of a point using pyqgis. In pyqgis, QgsPoint is a two demension point without z coordinate. And QgsPointV2 is a three demension point. When I get features from a VectorLayer and then get geometry from feature, It seems the geometry can only be convert to a two demension geometry (like QgsPoint, QgsPolyline, QgsPolygon). So how to get z coordinate of point.

part of vertexes of selected lineString

1 Answer 1

2

with QGIS 2.X, you can access to GeometryV2 by doing something like this:

geometryV2 = feature.geometry().geometry()

It's not really straight forward... but it's the way to do it with QGIS 2.X

then you can access to the z value:

geometryV2.zAt(i)

where i is the index of the vertex

With QGIS 3.X the API has changed. I don't know for the moment how it would works with this version but I guess it's more straightforward!

1
  • Got it. Thx. But it's a little weird by using geometry().geometry(). It looks like a temporary method.
    – Guoooo
    Commented Apr 4, 2018 at 1:21

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.