Monday, 23 March 2015

QGIS 2.12 Lines to Polygons not work properly


In QGIS 2.12.3 I have a small shapefile with lines (as often occurs in parcel boundary datasets) of 2 vertices each, snapped to each other (no topology errors, no dangles, no intersections). But the "Lines to Polygons" (screenshot) tool doesn't produce any polygons (in contrast to the two expected polygons).


What am I doing wrong or what am i having to do to make this tool work properly? (I'm checking out 2.14. tomorrow...) I know that in PostGIS the ST_Polygonize works pretty well, but importing my data to PostGIS first or any other workaround seems not a staightforward solution to me.


QGIS 2.12. Lines To Polygons does not work properly



Answer



Hmm. Something seems to be wrong with the algorithm... but the 'polygonize' seems to work.


Use Qgis Console and then (Layer with your lines is the first in the legend):



from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.utils import iface
import processing
output = r"C:/path to where you want to save it/"
input = qgis.utils.iface.activeLayer() #make sure line-layer is active
# if first layer in legend you can also use: input = qgis.utils.iface.legendInterface().layers()[0]

#if None doesn't work; try False instead
processing.runalg("qgis:polygonize", input, None, QGis.WKBLineString, output+"Polygonzetestpoly.shp")

poly = QgsVectorLayer(output+"Polygonzetestpoly.shp","Polygonzetestpoly",'ogr')
QgsMapLayerRegistry.instance().addMapLayer(poly)

Worked for me (windows)


I hope this helps?Screenshot


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