Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- layer = iface.activeLayer()
- iter = layer.getFeatures()
- for feature in iter:
- # retrieve every feature with its geometry and attributes
- # fetch geometry
- geom = feature.geometry()
- # assume z values are stored in fields "from" and "to"
- p0z = feature["from"]
- p1z = feature["to"]
- # access Points, assuming each line has to vertices
- oldp0, oldp1 = geom.asPolyline()[0], geom.asPolyline()[1]
- # creating a new LineString with PointZ-vertices
- newp0 = QgsPointV2( QgsWKBTypes.PointZ, oldp0[0], oldp0[1], p0z )
- newp1 = QgsPointV2( QgsWKBTypes.PointZ, oldp1[0], oldp1[1], p1z )
- linez = QgsLineStringV2()
- linez.setPoints([newp0, newp1])
- # output
- print linez.asWkt()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement