PyQGIS script - asPoint() always returning "(0, 0)"

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

PyQGIS script - asPoint() always returning "(0, 0)"

Adrien ANDRÉ
Dear list,

here is my PyQGIS script:

##Points=vector
layer_point = processing.getObject(Points)

iter = layer_point.getFeatures()
for point in iter:
    print "Feature ID %d: " % point.id()

    geom = point.geometry()
    if geom.type() == QGis.Point:
      x = geom.asPoint()
      print "  Point: " + str(x)


It always returns "  Point: (0,0)" for each geometry
despite layer_point.extent().toString() returns:
"402100.4306666287011467,429938.4182564518414438 : 402469.0222782648634166,430309.6282568128081039"


Would you know how i can debug this?


Thank you in advance.


Regards,

Adrien


_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: PyQGIS script - asPoint() always returning "(0, 0)"

Jakob Lanstorp
I have seen this error when the table has geometries of multipoints and not points. If this is the case try to convert your multipoint layer to points.

Jakob
Jakob Lanstorp
Reply | Threaded
Open this post in threaded view
|

Re: PyQGIS script - asPoint() always returning "(0, 0)"

Adrien ANDRÉ
In reply to this post by Adrien ANDRÉ
Thank you!

i used MultipartToSingleparts source to improve my script
(https://github.com/qgis/QGIS/blob/master/python/plugins/processing/algs/qgis/MultipartToSingleparts.py).


Adrien


Le 15/04/2015 13:39, [hidden email] a écrit :
> I have seen this error when the table has geometries of multipoints and not
> points. If this is the case try to convert your multipoint layer to points.
_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-developer