Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. layer = iface.activeLayer()
  2. iter = layer.getFeatures()
  3. for feature in iter:
  4. # retrieve every feature with its geometry and attributes
  5. # fetch geometry
  6. geom = feature.geometry()
  7. # assume z values are stored in fields "from" and "to"
  8. p0z = feature["from"]
  9. p1z = feature["to"]
  10.  
  11. # access Points, assuming each line has to vertices
  12. oldp0, oldp1 = geom.asPolyline()[0], geom.asPolyline()[1]
  13.  
  14. # creating a new LineString with PointZ-vertices
  15. newp0 = QgsPointV2( QgsWKBTypes.PointZ, oldp0[0], oldp0[1], p0z )
  16. newp1 = QgsPointV2( QgsWKBTypes.PointZ, oldp1[0], oldp1[1], p1z )
  17. linez = QgsLineStringV2()
  18. linez.setPoints([newp0, newp1])
  19. # output
  20. print linez.asWkt()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement