from qgis.core import QgsGeometry, QgsPointXY # create a line geometry line = QgsGeometry.fromPolylineXY([QgsPointXY(1,1), QgsPointXY(2,2), QgsPointXY(3,1)]) # convert the line geometry into a list of points points = line.asPolyline() print(points) # Output: [QgsPointXY(1.0, 1.0), QgsPointXY(2.0, 2.0), QgsPointXY(3.0, 1.0)]
from qgis.core import QgsProject # get the layer by name layer = QgsProject.instance().mapLayersByName("my_layer")[0] # get the first feature in the layer feature = layer.getFeature(0) # get the geometry of the feature geom = feature.geometry() # convert the geometry into a list of points points = geom.asPolyline() print(points) # Output: [QgsPointXY(1.0, 1.0), QgsPointXY(2.0, 2.0), QgsPointXY(3.0, 1.0)]In both examples above, the qgis.core package/library is used.