For single part LineString:
layer = QgsProject.instance().mapLayersByName("Single parts")[0]
for feature in layer.getFeatures():
for pnt in feature.geometry().asPolyline():
print(pnt.x(), pnt.y())
For multipart LineString:
layer = QgsProject.instance().mapLayersByName("folyo")[0]
for feature in layer.getFeatures():
for part in feature.geometry().asMultiPolyline():
print("part")
for pnt in part:
print(pnt.x(), pnt.y())
Tested in QGIS 3.16.1
asMultiPolyline()
and asPolyline()
return a list of points, so you can use indexes.
To check the layer geometry type use the geometryType()
method of a layer.
To separate single and multi types use the isSingleType()
method.
Here is the code for it:
layer = QgsProject.instance().mapLayersByName("your_layer")[0]
if layer.geometryType() == QgsWkbTypes.LineGeometry:
for feature in layer.getFeatures():
geom = feature.geometry()
if QgsWkbTypes.isSingleType(geom.wkbType()):
# single
for pnt in geom.asPolyline():
print(pnt.x(), pnt.y())
else:
# multipart
for part in geom.asMultiPolyline():
print("part")
for pnt in part:
print(pnt.x(), pnt.y())
print()
?