pyQGIS convert polygons to lines

This example uses one of the many many algorithms from the powerful processing toolbox.

import processing
import os
polygon_input_file="temp.shp"
line_output_file=os.path.splitext(os.path.basename(polygon_input_file))[0]+"_line.shp"
vlayer = QgsVectorLayer(polygon_input_file, "temp", "ogr")
QgsMapLayerRegistry.instance().addMapLayer(vlayer)
qgis.utils.iface.setActiveLayer(vlayer)
vlayer.selectAll()
processing.runalg("qgis:polygonstolines",vlayer,line_output_file)
QgsMapLayerRegistry.instance().removeMapLayer(vlayer.id())

One thought on “pyQGIS convert polygons to lines

Leave a Reply

Your email address will not be published. Required fields are marked *


× 5 = thirty