25
25
26
26
__revision__ = '$Format:%H$'
27
27
28
- from qgis .core import (QgsProcessing ,
29
- QgsProcessingException ,
28
+ from qgis .core import (QgsProcessingException ,
30
29
QgsProcessingParameterDefinition ,
31
30
QgsProcessingParameterFeatureSource ,
32
31
QgsProcessingParameterField ,
@@ -61,7 +60,7 @@ def initAlgorithm(self, config=None):
61
60
self .tr ('Dissolve field' ),
62
61
None ,
63
62
self .INPUT ,
64
- QgsProcessingParameterField .Any ))
63
+ QgsProcessingParameterField .Any , optional = True ))
65
64
self .addParameter (QgsProcessingParameterString (self .GEOMETRY ,
66
65
self .tr ('Geometry column name' ),
67
66
defaultValue = 'geometry' ))
@@ -85,7 +84,7 @@ def initAlgorithm(self, config=None):
85
84
self .tr ('Numeric attribute to calculate statistics on' ),
86
85
None ,
87
86
self .INPUT ,
88
- QgsProcessingParameterField .Any ,
87
+ QgsProcessingParameterField .Numeric ,
89
88
optional = True ))
90
89
params .append (QgsProcessingParameterString (self .OPTIONS ,
91
90
self .tr ('Additional creation options' ),
@@ -160,15 +159,17 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
160
159
161
160
params = ',' .join (tokens )
162
161
if params :
163
- if self .parameterAsBool (parameters , self .KEEP_ATTRIBUTES , context ):
164
- sql = "SELECT ST_Union({}) AS {}{}, {} FROM '{}' GROUP BY {}" .format (geometry , geometry , other_fields , params , layerName , fieldName )
165
- else :
166
- sql = "SELECT ST_Union({}) AS {}, {}, {} FROM '{}' GROUP BY {}" .format (geometry , geometry , fieldName , params , layerName , fieldName )
162
+ params = ', ' + params
163
+
164
+ group_by = ''
165
+ if fieldName :
166
+ group_by = ' GROUP BY {}' .format (fieldName )
167
+
168
+ if self .parameterAsBool (parameters , self .KEEP_ATTRIBUTES , context ):
169
+ sql = "SELECT ST_Union({}) AS {}{}{} FROM '{}'{}" .format (geometry , geometry , other_fields , params , layerName , group_by )
167
170
else :
168
- if self .parameterAsBool (parameters , self .KEEP_ATTRIBUTES , context ):
169
- sql = "SELECT ST_Union({}) AS {}{} FROM '{}' GROUP BY {}" .format (geometry , geometry , other_fields , layerName , fieldName )
170
- else :
171
- sql = "SELECT ST_Union({}) AS {}, {} FROM '{}' GROUP BY {}" .format (geometry , geometry , fieldName , layerName , fieldName )
171
+ sql = "SELECT ST_Union({}) AS {}{}{} FROM '{}'{}" .format (geometry , geometry , ', ' + fieldName if fieldName else '' ,
172
+ params , layerName , group_by )
172
173
173
174
arguments .append (sql )
174
175
0 commit comments