[Qgis-developer] How to get feat.geometry() from SpatiaLite in pyQGis ?

giulianc51 giulianc51 at gmail.com
Fri Dec 6 00:27:14 PST 2013


Il giorno Thu, 5 Dec 2013 11:10:03 +0100
Geo DrinX <geodrinx at 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



More information about the Qgis-developer mailing list