from qgis.core import QgsGeometry # Create a list of QgsGeometry objects representing line segments segments = [ QgsGeometry.fromPolylineXY([(0, 0), (1, 0), (1, 1)]), QgsGeometry.fromPolylineXY([(1, 1), (0, 1)]) ] # Create a multi-polyline geometry from the line segments multi_polyline = QgsGeometry.fromMultiPolyline(segments) print(multi_polyline.wkt()) # Output: MULTIPLINESTRING((0 0,1 0,1 1),(1 1,0 1))
from qgis.core import QgsGeometry # Create a list of OGR-style geometry strings representing line segments segments = [ "LINESTRING(0 0,1 0,1 1)", "LINESTRING(1 1,0 1)" ] # Create a multi-polyline geometry from the line segments multi_polyline = QgsGeometry.fromMultiPolyline(segments, "ogr") print(multi_polyline.wkt()) # Output: MULTIPLINESTRING((0 0,1 0,1 1),(1 1,0 1))In both examples, the fromMultiPolyline method is used to create a multi-polyline geometry from a set of line segments. The first example uses QgsGeometry objects to represent the line segments, while the second example uses OGR-style string representations. The package library for QgsGeometry is the qgis.core module in the QGIS Python API.