9

While trying to polygonize the polyline layer in PyQGIS using

processing.runandload("qgis:linestopolygons",explode_path,polygon_path)

command in python console, it does not create polygons corresponding to the line edges. Instead it creates sliver polygons along the curved edges. Why the polygons are not created along the line edges?

enter image description here

On polygonization, the black lines are supposed to be the edges of the created polygons. Instead only few slivers are created along the curved edges(blue polygons).

  • Have you tried the SAGA version of the tool: processing.runandload("saga:convertlinestopolygons",explode_path,polygon_path) – Joseph Sep 23 '16 at 9:19
  • @Joseph tried the SAGA version just now. Still the result is same. – Sjs Sep 23 '16 at 9:51
  • 1
    Try cleaning your line shapefile with the plugin Geometry Checker or the GRASS tool v.clean. – Joseph Sep 23 '16 at 13:04
  • 2
    @Joseph the data is topologically clean. Got the desired result using 'Polygonize' tool. Thank you for the comments. Have come to know about couple of topological checkers :) – Sjs Sep 23 '16 at 15:00
  • Nice one, glad you found the solution =) – Joseph Sep 23 '16 at 15:33
8

Got the exact polygons as desired using the 'Polygonize' algorithm (Processing Toolbox --> QGIS Geoalgorithms --> Polygonize) in the python console.

import processing
polygon_path = "C:\\Documents and Settings\\User\\polygonsFormed.shp"
line_path = "C:\\Documents and Settings\\User\\inputLine.shp"
processing.runandload("qgis:polygonize",line_path,False,False,polygon_path)
0

Had the same problem while using the 'Lines to Polygons' tool available in Vector menu. Got lot of little sliver polygons even though the data is topologically correct.

"Polygonize"

QGIS geoalgorithm available in the processing toolbar worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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