On 24 April 2017 at 11:52, Martin Bain <martin.b...@lismore.nsw.gov.au> 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:qgis-user-boun...@lists.osgeo.org] On Behalf Of Anke > zur Gölden > Sent: Sunday, 23 April 2017 4:39 PM > To: QGIS User List <qgis-user@lists.osgeo.org> > 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 > Qgis-user@lists.osgeo.org > List info: https://lists.osgeo.org/mailman/listinfo/qgis-user > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user _______________________________________________ Qgis-user mailing list Qgis-user@lists.osgeo.org List info: https://lists.osgeo.org/mailman/listinfo/qgis-user Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user