Using the following code, I make a polyline with two points.
vl = QgsVectorLayer("LineString", layerName, "memory") pr = vl.dataProvider() vl.startEditing() fet = QgsFeature() fet.setGeometry( QgsGeometry.fromPolyline( [QgsPoint(x1,y1), QgsPoint(x2,y2)] )) pr.addFeatures( [ fet ] )
What I want is to add a line to this polyline while I keep only one id. So I can not use:
fet.setGeometry( QgsGeometry.fromPolyline( [QgsPoint(x3,y3), QgsPoint(x4,y4)] ))
because this will save two lines with two different id's.
I can see in the QGIS API that there is a command:
addPart (const QList< QgsPoint > &points) Adds a new island polygon to a multipolygon feature.
but I do not know if it works or how to use it. Does anybody have any idea how to add points or several points to an existing polygon or polyline?