Skip to content

Commit

Permalink
[processing] add Buffer option to Voronoi polygons tool (fix #7661)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Mar 26, 2014
1 parent 024f6a1 commit cbeb528
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion python/plugins/processing/algs/ftools/VoronoiPolygons.py
Expand Up @@ -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
Expand All @@ -42,6 +43,7 @@
class VoronoiPolygons(GeoAlgorithm):

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

# =========================================================================
Expand All @@ -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()
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit cbeb528

Please sign in to comment.