Nice! Thanks Nyall

-----Original Message-----
From: Nyall Dawson [mailto:[email protected]] 
Sent: Monday, 24 April 2017 3:07 PM
To: Martin Bain <[email protected]>
Cc: QGIS User List <[email protected]>
Subject: Re: [Qgis-user] Number of vertices

On 24 April 2017 at 11:52, Martin Bain <[email protected]> wrote:
> Hi Anke,
>
> The asPolyline() function of a geometry returns a list of points.  You 
> can then simply get the length of the list:
>
>
>
>
>
> lyr=iface.activeLayer()
>
> sel=lyr.selectedFeatures()
>
> obj=sel[0].geometry()
>
> verts=obj.asPolyline()
>
> print verts
>
> [(526002,6.81305e+06), (526011,6.81309e+06), (526016,6.81311e+06)]
>
>
>
> print len(verts)
>
> 3

While this will work, it's quite slow as it requires copying all the geometry's 
points into a new list. A faster approach is:

feature.geometry().geometry().nCoordinates()

In case you're wondering, the extra ".geometry()" gives you access to the 
QgsAbstractGeometry interface containing all the low level methods for working 
with geometry primitives.

Nyall


>
>
>
> Cheers,
>
> Martin.
>
>
>
> From: Qgis-user [mailto:[email protected]] On Behalf 
> Of Anke zur Gölden
> Sent: Sunday, 23 April 2017 4:39 PM
> To: QGIS User List <[email protected]>
> Subject: [Qgis-user] Number of vertices
>
>
>
> Good morning
>
>
>
> is there a way to get the number of vertices for a Polyline?
>
> I am looking for the python method to get if possible
>
>
>
> thx
>
> Anke
>
>
>
>
> This email is intended for the named recipient only. The information 
> it contains may be confidential. If you are not the intended recipient 
> you must not reproduce or distribute any part of this email, disclose 
> its contents to any other party or take any action in reliance on it. 
> If you have received this email in error, please contact the sender 
> immediately and delete the message.
>
> _______________________________________________
> Qgis-user mailing list
> [email protected]
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

This email is intended for the named recipient only.  The information it 
contains may be confidential.  If you are not the intended recipient you must 
not reproduce or distribute any part of this email, disclose its contents to 
any other party or take any action in reliance on it.  If you have received 
this email in error, please contact the sender immediately and delete the 
message.
_______________________________________________
Qgis-user mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to