@@ -166,7 +166,7 @@ QVariantMap QgsBufferAlgorithm::processAlgorithm( const QVariantMap ¶meters,
166
166
return QVariantMap ();
167
167
168
168
// fixed parameters
169
- // bool dissolve = QgsProcessingParameters:: parameterAsBool( parameters, QStringLiteral( "DISSOLVE" ), context );
169
+ bool dissolve = parameterAsBool ( parameters, QStringLiteral ( " DISSOLVE" ), context );
170
170
int segments = parameterAsInt ( parameters, QStringLiteral ( " SEGMENTS" ), context );
171
171
QgsGeometry::EndCapStyle endCapStyle = static_cast < QgsGeometry::EndCapStyle >( 1 + parameterAsInt ( parameters, QStringLiteral ( " END_CAP_STYLE" ), context ) );
172
172
QgsGeometry::JoinStyle joinStyle = static_cast < QgsGeometry::JoinStyle>( 1 + parameterAsInt ( parameters, QStringLiteral ( " JOIN_STYLE" ), context ) );
@@ -184,12 +184,18 @@ QVariantMap QgsBufferAlgorithm::processAlgorithm( const QVariantMap ¶meters,
184
184
185
185
double step = 100.0 / count;
186
186
int current = 0 ;
187
+
188
+ QList< QgsGeometry > bufferedGeometriesForDissolve;
189
+ QgsAttributes dissolveAttrs;
190
+
187
191
while ( it.nextFeature ( f ) )
188
192
{
189
193
if ( feedback->isCanceled () )
190
194
{
191
195
break ;
192
196
}
197
+ if ( dissolveAttrs.isEmpty () )
198
+ dissolveAttrs = f.attributes ();
193
199
194
200
QgsFeature out = f;
195
201
if ( out.hasGeometry () )
@@ -200,18 +206,33 @@ QVariantMap QgsBufferAlgorithm::processAlgorithm( const QVariantMap ¶meters,
200
206
bufferDistance = QgsProcessingParameters::parameterAsDouble ( distanceParamDef, parameters, context );
201
207
}
202
208
203
- out. setGeometry ( f.geometry ().buffer ( bufferDistance, segments, endCapStyle, joinStyle, miterLimit ) );
204
- if ( !out. geometry () )
209
+ QgsGeometry outputGeometry = f.geometry ().buffer ( bufferDistance, segments, endCapStyle, joinStyle, miterLimit );
210
+ if ( !outputGeometry )
205
211
{
206
212
QgsMessageLog::logMessage ( QObject::tr ( " Error calculating buffer for feature %1" ).arg ( f.id () ), QObject::tr ( " Processing" ), QgsMessageLog::WARNING );
207
213
}
214
+ if ( dissolve )
215
+ bufferedGeometriesForDissolve << outputGeometry;
216
+ else
217
+ out.setGeometry ( outputGeometry );
208
218
}
209
- sink->addFeature ( out );
219
+
220
+ if ( !dissolve )
221
+ sink->addFeature ( out );
210
222
211
223
feedback->setProgress ( current * step );
212
224
current++;
213
225
}
214
226
227
+ if ( dissolve )
228
+ {
229
+ QgsGeometry finalGeometry = QgsGeometry::unaryUnion ( bufferedGeometriesForDissolve );
230
+ QgsFeature f;
231
+ f.setGeometry ( finalGeometry );
232
+ f.setAttributes ( dissolveAttrs );
233
+ sink->addFeature ( f );
234
+ }
235
+
215
236
QVariantMap outputs;
216
237
outputs.insert ( QStringLiteral ( " OUTPUT_LAYER" ), dest );
217
238
return outputs;
0 commit comments