I have a loop which calculates two points for each iteration (x3,y3) and (x4,y4). As seen in the code these two points are added for each iteration, which gives i-1 lines. Each line has a individual id.
What I want is to add all these points at the same time, so it makes one polyline with only one id. This is done by adding all the points in the line:
fet.setGeometry( QgsGeometry.fromMultiPolyline([[QgsPoint(x3,y3), QgsPoint(x4,y4)]]))
instead of only these two points at the time. But I can not figure out how to change the loop to make it work. I guess for each iteration, I have to save a string with QgsPoint(x3,y3), QgsPoint(x4,y4) for the given iteration and add the next two points as a string in the next iteration. But I can not see how?
for i in range(0,len(points)-1): coor1 = points[i] x1 = coor1 y1 = coor1 dist = 0 coor2 = points[i+1] x2 = coor2 y2 = coor2 dn = ((x1-x2)**2 + (y1-y1)**2)**0.5 x3 = x1 + dist*(y1-y2) / dn y3 = y1 - dist*(x1-x2) / dn x4 = x2 + dist*(y1-y2) / dn y4 = y2 - dist*(x1-x2) / dn fet.setGeometry( QgsGeometry.fromMultiPolyline([[QgsPoint(x3,y3), QgsPoint(x4,y4)]])) pr.addFeatures( [ fet ] )