I am currently blocked by a quite weird issue I have no idea how to solve.
On Windows 10, with QGIS Desktop 3.22.11. The simple process of doing a difference between a linestring and a polygon breaks up my linestring in a multilinestring but a recuperable one since all parts are in order. So its as simple as concatenating all the points of all parts to rebuild the clipped linestring. However running the same difference operation inside a Debian Docker container having installed the same version of QGIS as the windows desktop version gives the following result which is barelly usable since I need to rebuild the linestring from the multiple parts.
I am unsure of what exactly causes the change in behavior except that it is consistent and repeatable. And that it is probably caused by how the (self-intersecting) geometry that result from the
QgsGeometry.difference() operation is built
test code used to generate the geometry:
from qgis.core import QgsVectorLayer if __name__ == "__main__": poly_layer = QgsVectorLayer("poly.gpkg|layername=poly", "poly", "ogr") linestring_layer = QgsVectorLayer("linestring.gpkg|layername=linestring", "linestring", "ogr") else: poly_layer = QgsProject.instance().mapLayersByName("poly") linestring_layer = QgsProject.instance().mapLayersByName("linestring") linestring = next(linestring_layer.getFeatures()) poly = next(poly_layer.getFeatures()) diff = linestring.geometry().difference(poly.geometry()) print(diff.asWkt()) for geom in diff.constParts(): print(geom.asWkt()) # # or #for geom in diff.asGeometryCollection(): # print(geom.asWkt())