Skip to content
Permalink
Browse files

[processing] fix Convex hull algorithm (fix #11725)

  • Loading branch information
alexbruy committed Nov 30, 2014
1 parent 7d8a3b1 commit 72fe56cfe4f77bd4a1e3e855b6b086cf77579f8d
Showing with 25 additions and 25 deletions.
  1. +25 −25 python/plugins/processing/algs/qgis/ConvexHull.py
@@ -50,24 +50,23 @@ class ConvexHull(GeoAlgorithm):
def defineCharacteristics(self):
self.name = 'Convex hull'
self.group = 'Vector geometry tools'
self.addParameter(ParameterVector(ConvexHull.INPUT, 'Input layer',
[ParameterVector.VECTOR_TYPE_ANY]))
self.addParameter(ParameterTableField(ConvexHull.FIELD,
'Field (optional, only used if creating convex hulls by classes)',
ConvexHull.INPUT, optional=True))
self.addParameter(ParameterSelection(ConvexHull.METHOD, 'Method',
ConvexHull.METHODS))
self.addOutput(OutputVector(ConvexHull.OUTPUT, 'Convex hull'))
self.addParameter(ParameterVector(
self.INPUT, 'Input layer', [ParameterVector.VECTOR_TYPE_ANY]))
self.addParameter(ParameterTableField(
self.FIELD,
'Field (optional, only used if creating convex hulls by classes)',
self.INPUT, optional=True))
self.addParameter(ParameterSelection(
self.METHOD, 'Method', self.METHODS))
self.addOutput(OutputVector(self.OUTPUT, 'Convex hull'))

def processAlgorithm(self, progress):
useField = self.getParameterValue(ConvexHull.METHOD) == 1
fieldName = self.getParameterValue(ConvexHull.FIELD)
layer = dataobjects.getObjectFromUri(
self.getParameterValue(ConvexHull.INPUT))
self.getParameterValue(self.INPUT))
useField = self.getParameterValue(self.METHOD) == 1
fieldName = self.getParameterValue(self.FIELD)

f = QgsField('value')
f.setType(QVariant.String)
f.setLength(255)
if useField:
index = layer.fieldNameIndex(fieldName)
fType = layer.pendingFields()[index].type()
@@ -82,14 +81,14 @@ def processAlgorithm(self, progress):
f.setType(QVariant.String)
f.setLength(255)

fields = [QgsField('id', QVariant.Int, '', 20), f, QgsField('area',
QVariant.Double, '', 20, 6), QgsField('perim',
QVariant.Double, '', 20, 6)]
fields = [QgsField('id', QVariant.Int, '', 20),
f,
QgsField('area', QVariant.Double, '', 20, 6),
QgsField('perim', QVariant.Double, '', 20, 6)
]

writer = self.getOutputFromName(
ConvexHull.OUTPUT).getVectorWriter(fields,
QGis.WKBPolygon,
layer.dataProvider().crs())
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
fields, QGis.WKBPolygon, layer.dataProvider().crs())

outFeat = QgsFeature()
inGeom = QgsGeometry()
@@ -98,21 +97,22 @@ def processAlgorithm(self, progress):
current = 0

fid = 0
val = ''
val = None
features = vector.features(layer)
if useField:
unique = layer.uniqueValues(index)
total = 100.0 / float(layer.featureCount() * len(unique))

total = 100.0 / (len(features) * len(unique))
for i in unique:
hull = []
first = True
hull = []
features = vector.features(layer)
for f in features:
idVar = f[fieldName]
if unicode(idVar).strip() == unicode(i).strip:
if unicode(idVar).strip() == unicode(i).strip():
if first:
val = idVar
first = False

inGeom = QgsGeometry(f.geometry())
points = vector.extractPoints(inGeom)
hull.extend(points)

0 comments on commit 72fe56c

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