jeudi 29 janvier 2015

Efficiently generate Voronoi layers in qgis via Python


The following python commands both appear to function when called in qgis 2.6 to generate Voronoi diagrams:



processing.runalg("qgis:voronoipolygons", pointLayer, 1, None)
processing.runalg("grass:v.voronoi",pointLayer,False,False, bbox,-1,0.0001,0, None)


but neither of them seems to work well. The first (qgis) is extremely slow, taking 38 seconds with 180 points vs 2 seconds for the grass method. The qgis method also seems to ignore the output variable when it is specified ("C:/tmp/output.shp" in place of None), but the output layer does appear in the Layers pane so I can iterate through the layers and find it.


The second algorithm seems to ignore the output parameter (again, "C:/tmp/output.shp" in place of None), and no result seems to appear in the layer pane. Trying to use memory:name generated an error message. However, the following results in a temp file path being returned:



output = processing.runalg("grass:v.voronoi",PointLayer,False,False, bbox,-1,0.0001,0, None)
print output.output


My datasets will have thousands of points, so the qgis library is much too slow and the grass library requires a workaround to get the result out.


Is there a way to make qgis:voronoipolygons run faster? Is there a syntax I am missing to get the result layer from the algorithm? It will be an intermediate result used for future calculations so memory storage is preferred.





Aucun commentaire:

Enregistrer un commentaire