I have a road network (line layer). I am trying to get list of coordinates (Lat,Long) from road network in the form of geometry LINESTRING as shown below. However, I am only getting two coordinates as shown in second figure.
What I have tried:
lyr = iface.activeLayer()
fl = ['lat','lon'] #Add these fields before executing code
with edit(lyr):
for f in lyr.getFeatures():
p = f.geometry().centroid().asPoint()
_=f.setAttribute(f.fields().indexFromName(fl[0]), p.y())
_=f.setAttribute(f.fields().indexFromName(fl[1]), p.x())
_=lyr.updateFeature(f)


for f in lyr.getFeatures(): print(f.aswkt())
– Sam Sep 21 '20 at 13:01