Thursday 18 July 2019

pyqgis - Executing a voronoi polygon to a shapefile With Pycharm


I'm trying to get a voronoi polygon from points using Pycharm. I've tried:


processing.runalg("qgis:voronoipolygons", file ,1, "C:\Voronoi.shp" )


but it doesn't work. It works in the python console in QGIS but not in Pycharm .


This is my code:


import shapefile

import ProcessingLog
import processing
import sys
from sets import Set

from qgis.core import QGis, QgsFeatureRequest, QgsFeature, QgsGeometry, QgsPoint


from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterNumber
from processing.core.outputs import OutputVector
import voronoi
from processing.gui.SilentProgress import SilentProgress
from processing.tools import dataobjects, vector


def runalg(alg, progress=None):

if progress is None:
progress = SilentProgress()
try:
alg.execute(progress)
return True
except GeoAlgorithmExecutionException as e:
ProcessingLog.addToLog(sys.exc_info()[0], ProcessingLog.LOG_ERROR)
progress.error(e.msg)

return False


file = "C:\Armoire.shp"
r = shapefile.Reader("C:\Armoire.shp")
processing.runalg("qgis:voronoipolygons", file ,1, "C:\Voronoi.shp" )

The error is:



QPixmap: Must construct a QApplication before a QPaintDevice






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