@@ -50,10 +50,12 @@ def defineCharacteristics(self):
50
50
[ParameterVector .VECTOR_TYPE_ANY ]))
51
51
self .addParameter (ParameterTableField (self .WEIGHT , 'Weight field' ,
52
52
MeanCoords .POINTS ,
53
- ParameterTableField .DATA_TYPE_NUMBER ))
53
+ ParameterTableField .DATA_TYPE_NUMBER ,
54
+ optional = True ))
54
55
self .addParameter (ParameterTableField (self .UID , 'Unique ID field' ,
55
56
MeanCoords .POINTS ,
56
- ParameterTableField .DATA_TYPE_NUMBER ))
57
+ ParameterTableField .DATA_TYPE_NUMBER ,
58
+ optional = True ))
57
59
58
60
self .addOutput (OutputVector (MeanCoords .OUTPUT , 'Result' ))
59
61
@@ -63,8 +65,17 @@ def processAlgorithm(self, progress):
63
65
weightField = self .getParameterValue (self .WEIGHT )
64
66
uniqueField = self .getParameterValue (self .UID )
65
67
66
- weightIndex = layer .fieldNameIndex (weightField )
67
- uniqueIndex = layer .fieldNameIndex (uniqueField )
68
+ print weightField , uniqueField
69
+
70
+ if weightField is None :
71
+ weightIndex = - 1
72
+ else :
73
+ weightIndex = layer .fieldNameIndex (weightField )
74
+
75
+ if uniqueField is None :
76
+ uniqueIndex = - 1
77
+ else :
78
+ uniqueIndex = layer .fieldNameIndex (uniqueField )
68
79
69
80
fieldList = [QgsField ('MEAN_X' , QVariant .Double , '' , 24 , 15 ),
70
81
QgsField ('MEAN_Y' , QVariant .Double , '' , 24 , 15 ),
@@ -82,7 +93,10 @@ def processAlgorithm(self, progress):
82
93
for feat in features :
83
94
current += 1
84
95
progress .setPercentage (current * total )
85
- clazz = str (feat .attributes ()[uniqueIndex ]).strip ()
96
+ if uniqueIndex == - 1 :
97
+ clazz = "Single class"
98
+ else :
99
+ clazz = str (feat .attributes ()[uniqueIndex ]).strip ()
86
100
if weightIndex == - 1 :
87
101
weight = 1.00
88
102
else :
0 commit comments