Tuesday, 22 September 2015

pyqgis - Converting Lines to Polygons in QGIS produces Sliver Polygons


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).



Answer



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)

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...