Re: [Qgis-developer] How to get feat.geometry() from SpatiaLite in pyQGis ?
Il giorno Thu, 5 Dec 2013 11:10:03 +0100 Geo DrinX geodr...@gmail.com ha scritto: Hello all, Hi Roberto (sorry for my bad english :-) as in object, within pyQGis I need to read the geometry of a SpatiaLite vector layer. This is my source code: layer = iface.mapCanvas().currentLayer() iter = layer.getFeatures() for feat in iter: geom = feat.geometry() elem = geom.asPolyline() print(ELEM %s\n) %(elem) for p1 in elem: x1,y1 = p1.x(),p1.y() print(XY= %lf %lf\n) %(x1, y1) But... it returns only: ELEM [] ELEM [] ELEM [] ELEM [] . Somebody can help me to understand how to get geometry from SpatiaLite ? I tried in python console on a Spatialite linestring layer: cLayer=iface.activeLayer() iter=cLayer.getFeatures() feat=iter.next() geom=feat.geometry() ln=geom.asPolyline() pnt=ln[0] print pnt.x(),pnt.y() with the correct answer: 1511590.31375 5099925.78455 (but I'm on a old 1.9.0-Master) Thank you in advance Roberto bye, giuliano ___ Qgis-developer mailing list Qgis-developer@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-developer
Re: [Qgis-developer] How to get feat.geometry() from SpatiaLite in pyQGis ?
Hi Christos (!), sorry but your code works only in QGis 1.8 version. I am using the 2.0.1 version and pyQGis methods are changed: http://hub.qgis.org/wiki/quantum-gis/Python_plugin_API_changes_from_18_to_20 BTW, my problem is: - using a SHP file layer, elements are returned - using SpatiaLite layer, elements are returned, but each is empty. It 'a known issue? Someone in the list has tried it? Roberto 2013/12/6 mmekuria sail...@yahoo.com Hi, Roberto: I think the query from layer.getFeatures() returns an iterator and that means you use the nextFeature(feat) to get the next feature until it fails to return a feature, then it means you have reached the end of the iterator list. iter = layer.getFeatures() while iter.nextFeature(feat): geom = feat.geometry() elem = geom.asPolyline() print(ELEM %s\n) %(elem) for p1 in elem: x1,y1 = p1.x(),p1.y() print(XY= %lf %lf\n) %(x1, y1) Should work for you, - Maaza Christos, PhD www.Axumcorp.com -- View this message in context: http://osgeo-org.1560.x6.nabble.com/How-to-get-feat-geometry-from-SpatiaLite-in-pyQGis-tp5092891p5093041.html Sent from the Quantum GIS - Developer mailing list archive at Nabble.com. ___ Qgis-developer mailing list Qgis-developer@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-developer ___ Qgis-developer mailing list Qgis-developer@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-developer
[Qgis-developer] How to get feat.geometry() from SpatiaLite in pyQGis ?
Hello all, as in object, within pyQGis I need to read the geometry of a SpatiaLite vector layer. This is my source code: layer = iface.mapCanvas().currentLayer() iter = layer.getFeatures() for feat in iter: geom = feat.geometry() elem = geom.asPolyline() print(ELEM %s\n) %(elem) for p1 in elem: x1,y1 = p1.x(),p1.y() print(XY= %lf %lf\n) %(x1, y1) But... it returns only: ELEM [] ELEM [] ELEM [] ELEM [] etcetera, instead of something like this : ELEM [(2.37786e+06,4.60302e+06), (2.37784e+06,4.60304e+06)] ... that I had with a normal qgis layer. Sure, I miss something. Somebody can help me to understand how to get geometry from SpatiaLite ? Thank you in advance Roberto ___ Qgis-developer mailing list Qgis-developer@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-developer
Re: [Qgis-developer] How to get feat.geometry() from SpatiaLite in pyQGis ?
Hi, Roberto: I think the query from layer.getFeatures() returns an iterator and that means you use the nextFeature(feat) to get the next feature until it fails to return a feature, then it means you have reached the end of the iterator list. iter = layer.getFeatures() while iter.nextFeature(feat): geom = feat.geometry() elem = geom.asPolyline() print(ELEM %s\n) %(elem) for p1 in elem: x1,y1 = p1.x(),p1.y() print(XY= %lf %lf\n) %(x1, y1) Should work for you, - Maaza Christos, PhD www.Axumcorp.com -- View this message in context: http://osgeo-org.1560.x6.nabble.com/How-to-get-feat-geometry-from-SpatiaLite-in-pyQGis-tp5092891p5093041.html Sent from the Quantum GIS - Developer mailing list archive at Nabble.com. ___ Qgis-developer mailing list Qgis-developer@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-developer