@@ -50,24 +50,23 @@ class ConvexHull(GeoAlgorithm):
50
50
def defineCharacteristics (self ):
51
51
self .name = 'Convex hull'
52
52
self .group = 'Vector geometry tools'
53
- self .addParameter (ParameterVector (ConvexHull .INPUT , 'Input layer' ,
54
- [ParameterVector .VECTOR_TYPE_ANY ]))
55
- self .addParameter (ParameterTableField (ConvexHull .FIELD ,
56
- 'Field (optional, only used if creating convex hulls by classes)' ,
57
- ConvexHull .INPUT , optional = True ))
58
- self .addParameter (ParameterSelection (ConvexHull .METHOD , 'Method' ,
59
- ConvexHull .METHODS ))
60
- self .addOutput (OutputVector (ConvexHull .OUTPUT , 'Convex hull' ))
53
+ self .addParameter (ParameterVector (
54
+ self .INPUT , 'Input layer' , [ParameterVector .VECTOR_TYPE_ANY ]))
55
+ self .addParameter (ParameterTableField (
56
+ self .FIELD ,
57
+ 'Field (optional, only used if creating convex hulls by classes)' ,
58
+ self .INPUT , optional = True ))
59
+ self .addParameter (ParameterSelection (
60
+ self .METHOD , 'Method' , self .METHODS ))
61
+ self .addOutput (OutputVector (self .OUTPUT , 'Convex hull' ))
61
62
62
63
def processAlgorithm (self , progress ):
63
- useField = self .getParameterValue (ConvexHull .METHOD ) == 1
64
- fieldName = self .getParameterValue (ConvexHull .FIELD )
65
64
layer = dataobjects .getObjectFromUri (
66
- self .getParameterValue (ConvexHull .INPUT ))
65
+ self .getParameterValue (self .INPUT ))
66
+ useField = self .getParameterValue (self .METHOD ) == 1
67
+ fieldName = self .getParameterValue (self .FIELD )
67
68
68
69
f = QgsField ('value' )
69
- f .setType (QVariant .String )
70
- f .setLength (255 )
71
70
if useField :
72
71
index = layer .fieldNameIndex (fieldName )
73
72
fType = layer .pendingFields ()[index ].type ()
@@ -82,14 +81,14 @@ def processAlgorithm(self, progress):
82
81
f .setType (QVariant .String )
83
82
f .setLength (255 )
84
83
85
- fields = [QgsField ('id' , QVariant .Int , '' , 20 ), f , QgsField ('area' ,
86
- QVariant .Double , '' , 20 , 6 ), QgsField ('perim' ,
87
- QVariant .Double , '' , 20 , 6 )]
84
+ fields = [QgsField ('id' , QVariant .Int , '' , 20 ),
85
+ f ,
86
+ QgsField ('area' , QVariant .Double , '' , 20 , 6 ),
87
+ QgsField ('perim' , QVariant .Double , '' , 20 , 6 )
88
+ ]
88
89
89
- writer = self .getOutputFromName (
90
- ConvexHull .OUTPUT ).getVectorWriter (fields ,
91
- QGis .WKBPolygon ,
92
- layer .dataProvider ().crs ())
90
+ writer = self .getOutputFromName (self .OUTPUT ).getVectorWriter (
91
+ fields , QGis .WKBPolygon , layer .dataProvider ().crs ())
93
92
94
93
outFeat = QgsFeature ()
95
94
inGeom = QgsGeometry ()
@@ -98,21 +97,22 @@ def processAlgorithm(self, progress):
98
97
current = 0
99
98
100
99
fid = 0
101
- val = ''
100
+ val = None
101
+ features = vector .features (layer )
102
102
if useField :
103
103
unique = layer .uniqueValues (index )
104
- total = 100.0 / float (layer .featureCount () * len (unique ))
105
-
104
+ total = 100.0 / (len (features ) * len (unique ))
106
105
for i in unique :
107
- hull = []
108
106
first = True
107
+ hull = []
109
108
features = vector .features (layer )
110
109
for f in features :
111
110
idVar = f [fieldName ]
112
- if unicode (idVar ).strip () == unicode (i ).strip :
111
+ if unicode (idVar ).strip () == unicode (i ).strip () :
113
112
if first :
114
113
val = idVar
115
114
first = False
115
+
116
116
inGeom = QgsGeometry (f .geometry ())
117
117
points = vector .extractPoints (inGeom )
118
118
hull .extend (points )
0 commit comments