Skip to content

Commit

Permalink
[processing] fix Convex hull algorithm (fix #11725)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Nov 30, 2014
1 parent 7d8a3b1 commit 72fe56c
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions python/plugins/processing/algs/qgis/ConvexHull.py
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit 72fe56c

Please sign in to comment.