Skip to content
Permalink
Browse files

[processing] add Buffer option to Voronoi polygons tool (fix #7661)

  • Loading branch information
alexbruy committed Mar 26, 2014
1 parent 024f6a1 commit cbeb5288b5c9598d7b0385b9567abb582806fec3
Showing with 9 additions and 1 deletion.
  1. +9 −1 python/plugins/processing/algs/ftools/VoronoiPolygons.py
@@ -34,6 +34,7 @@
from processing.core.GeoAlgorithmExecutionException import \
GeoAlgorithmExecutionException
from processing.parameters.ParameterVector import ParameterVector
from processing.parameters.ParameterNumber import ParameterNumber
from processing.outputs.OutputVector import OutputVector
from processing.algs.ftools import voronoi
from processing.tools import dataobjects, vector
@@ -42,6 +43,7 @@
class VoronoiPolygons(GeoAlgorithm):

INPUT = 'INPUT'
BUFFER = 'BUFFER'
OUTPUT = 'OUTPUT'

# =========================================================================
@@ -55,20 +57,26 @@ def defineCharacteristics(self):

self.addParameter(ParameterVector(self.INPUT, 'Input layer',
[ParameterVector.VECTOR_TYPE_POINT]))
self.addParameter(ParameterNumber(
self.BUFFER, 'Buffer region', 0.0, 100.0, 0.0))

self.addOutput(OutputVector(self.OUTPUT, 'Voronoi polygons'))

def processAlgorithm(self, progress):
layer = dataobjects.getObjectFromUri(
self.getParameterValue(self.INPUT))

buf = self.getParameterValue(self.BUFFER)

writer = self.getOutputFromName(
self.OUTPUT).getVectorWriter(layer.pendingFields().toList(),
QGis.WKBPolygon, layer.crs())

inFeat = QgsFeature()
outFeat = QgsFeature()
extent = layer.extent()
extraX = extent.height() * (buf / 100.0)
extraY = extent.width() * (buf / 100.0)
height = extent.height()
width = extent.width()
c = voronoi.Context()
@@ -104,7 +112,7 @@ def processAlgorithm(self, progress):
for (site, edges) in c.polygons.iteritems():
request = QgsFeatureRequest().setFilterFid(ptDict[ids[site]])
inFeat = layer.getFeatures(request).next()
lines = self.clip_voronoi(edges, c, width, height, extent, 0, 0)
lines = self.clip_voronoi(edges, c, width, height, extent, extraX, extraY)

geom = QgsGeometry.fromMultiPoint(lines)
geom = QgsGeometry(geom.convexHull())

0 comments on commit cbeb528

Please sign in to comment.
You can’t perform that action at this time.