i would like to identify the start- and endpoints within a set of polylines and return the coordinates of both points finally.
so far i have been able to iterate the features and found out that ArcGIS's export created a MulitLineString with a number of vertices (where the number corresponds to the length of the line). using
feature.geometry().vertexAt(0) (where feature is the current feature within a for loop) returns the first point of every feature and the print-result looks like that
<QgsPoint: Point (4800744.81731882505118847 2812251.2178244274109602)> but i didn't find a way to set up a "for vertex in vertices"-style iteration to get the last point of every line. the python2.x-style from Can vector layer get start point and end point of line using PyQGIS with
geom = feature.geometry().asPolyline() start_point = QgsPoint(geom)* end_point = QgsPoint(geom[-1])*
doesn't work anymore.
asPolyline() seems to return an empty list.
I've tried to iterate the vertices with
vertices(self) → QgsVertexIterator but cant get any results.
since i am pretty new to pyqgis the QGIS Python API seems really confusing to me.