[Qgis-developer] grab Z value

Pedro Venâncio pedrongvenancio at gmail.com
Mon Sep 28 12:04:31 PDT 2015


Hi Marco,

The new node editor widget does not suport Z value of 3d shapefiles, right?

Could Paulo's proposal be interesting to add to the node widget?

Thanks!
Pedro




2015-09-26 14:15 GMT+01:00 Paulo Pires <paulopires16 at gmail.com>:

> Hello, see my code, please. I intend to maintain Z value on shapefile, so:
> I write first on canvas... even I give the Z value, it will write Z = 0.0,
> ok...
>
> feat = QgsFeature()
> feat.setGeometry(QgsGeometry.fromWkt("LINESTRING (151620 319350 10, 151710
> 319350 10)"))
> layerCanvas.dataProvider().addFeatures([feat])
> layerCanvas.commitChanges()
> self.iface.mapCanvas().refresh()
>
> So, for grab the Z value, I go to the shapefile and update Z...
>
> driver = ogr.GetDriverByName('ESRI Shapefile')
> dataSource = driver.Open(myfilepath, 1)
> layer = dataSource.GetLayer()
>
> oldGeom = ogr.CreateGeometryFromWkt("LINESTRING (151620 319350 0, 151710
> 319350 0)")
> newGeom = ogr.CreateGeometryFromWkt("LINESTRING (151620 319350 10, 151710
> 319350 10)")
>
> # write shapefile
> for feature in layer:
>         if feature.GetGeometryRef() is not None:
>                 geom = feature.GetGeometryRef()
>
>                 if geom.Distance(oldGeom) <= 0.1:
>
>                         # delete oldGeom
>                         featureId = feature.GetFID()
>                         layer.DeleteFeature(featureId)
>
>                         # create newGeom
>                         feature.SetGeometry(newGeom)
>                         feature.SetFID(featureId)
>                         layer.CreateFeature(feature)
>
>                         feature.Destroy()
>
>                         msg = "+++++++++++++++"
>                         # refresh
>                         self.getShpData()
>                         self.iface.mapCanvas().refresh()
>                         break
>
> dataSource.Destroy()
>
> In canvas, I see the right Z :)
> But when I edit something, I lost that geometry...
> In point geometry, that's all ok, but in linestring, it disappears...
> Thanks
>
>
>
> --
> View this message in context:
> http://osgeo-org.1560.x6.nabble.com/grab-Z-value-tp5226284.html
> Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20150928/12892a01/attachment.html>


More information about the Qgis-developer mailing list