I have found a bug with the "convert lines to polygon" tool of QGIS and would like to know if the bug is known and if there is a workaround?

I want to convert my MultiLineString Z to MultiPolygon Z with Qgis inside a plugin. The results from the processor tool are different from the Python console than from the tool interface.

Polygons are missing in the layer created via the Python console, while all polygons are in the output via the interface. Code and images follow below:

You can access the example data from my Google Drive in shapefile format: https://drive.google.com/drive/folders/1I_uhDnlvqjhrHZfUWmIpZoi-C5nDTG47?usp=sharing

The lines are extracted from citygml file from this source: https://www.opengeodata.nrw.de/produkte/geobasis/3dg/lod2_gml/lod2_gml/LoD2_32_352_5662_1_NW.gml

Python Console executed inside QGis.3.18 Python3.7:

import processing
test = "c:/Users/abc/Desktop/lod2_dev_test/LoD2_32_352_5662_1_NW.shp"
out = "c:/Users/abc/Desktop/lod2_dev_test/Polygone.shp"
processing.run("qgis:linestopolygons", {'INPUT':test,'OUTPUT':out}) 

The output looks like this: Python Console missing polygon

if I run the same algorithm with the interface, the result is correct:

Tool Interface

Here the recorded command from the protocol:

processing.run("qgis:linestopolygons", {'INPUT':'c:/Users/abc/Desktop/lod2_dev_test/LoD2_32_352_5662_1_NW.shp','OUTPUT':'TEMPORARY_OUTPUT'})

The Polygon looks like this:

Result created from interface convert lines to polygon

Since I want to include the command in a plugin, I need the lines as polygons with z values. Does anyone know a solution for the bug or why the polygon is not written?

The lines definitely meet, that I checked in the WKT format of the shape.

2 Answers 2


It seems to be an issue with using shapefile as output. When using GeoPackage, it works seamlessly.

import processing
test = "c:/Users/abc/Desktop/LoD2_32_352_5662_1_NW.shp"
out = "ogr:dbname='C:/Users/abc/Desktop/out.gpkg' table='Polygone' (geom)"

# if you use the next line, you loose a geometry
# out = 'C:/Users/abc/Desktop/Polygone.shp'

result = processing.run("qgis:linestopolygons",

layer = QgsVectorLayer(result, "Layer", "ogr")

With GeoPackage:

enter image description here

With shapefile:

enter image description here

  • The solution with Geopackage is a good workaround. Thanks! The question still remains why the shapefiles are not written out correctly.
    – Muesgen
    Feb 11, 2022 at 7:15

The issue has been fixed in the GDAL/OGR library with PR https://github.com/OSGeo/gdal/pull/7157: it will not occur using a GDAL/OGR release version >= 3.7.0. On Windows, official OSGeo4W stand-alone and network installers of QGIS 3.28.7 and QGIS 3.30.3 and later versions will use GDAL/OGR release version >= 3.7.0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.