Skip to content

Commit 2779260

Browse files
committedJun 12, 2017
Respect dissolve setting in c++ buffer alg
1 parent 15b3012 commit 2779260

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed
 

‎src/core/processing/qgsnativealgorithms.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ QVariantMap QgsBufferAlgorithm::processAlgorithm( const QVariantMap &parameters,
166166
return QVariantMap();
167167

168168
// fixed parameters
169-
//bool dissolve = QgsProcessingParameters::parameterAsBool( parameters, QStringLiteral( "DISSOLVE" ), context );
169+
bool dissolve = parameterAsBool( parameters, QStringLiteral( "DISSOLVE" ), context );
170170
int segments = parameterAsInt( parameters, QStringLiteral( "SEGMENTS" ), context );
171171
QgsGeometry::EndCapStyle endCapStyle = static_cast< QgsGeometry::EndCapStyle >( 1 + parameterAsInt( parameters, QStringLiteral( "END_CAP_STYLE" ), context ) );
172172
QgsGeometry::JoinStyle joinStyle = static_cast< QgsGeometry::JoinStyle>( 1 + parameterAsInt( parameters, QStringLiteral( "JOIN_STYLE" ), context ) );
@@ -184,12 +184,18 @@ QVariantMap QgsBufferAlgorithm::processAlgorithm( const QVariantMap &parameters,
184184

185185
double step = 100.0 / count;
186186
int current = 0;
187+
188+
QList< QgsGeometry > bufferedGeometriesForDissolve;
189+
QgsAttributes dissolveAttrs;
190+
187191
while ( it.nextFeature( f ) )
188192
{
189193
if ( feedback->isCanceled() )
190194
{
191195
break;
192196
}
197+
if ( dissolveAttrs.isEmpty() )
198+
dissolveAttrs = f.attributes();
193199

194200
QgsFeature out = f;
195201
if ( out.hasGeometry() )
@@ -200,18 +206,33 @@ QVariantMap QgsBufferAlgorithm::processAlgorithm( const QVariantMap &parameters,
200206
bufferDistance = QgsProcessingParameters::parameterAsDouble( distanceParamDef, parameters, context );
201207
}
202208

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 )
205211
{
206212
QgsMessageLog::logMessage( QObject::tr( "Error calculating buffer for feature %1" ).arg( f.id() ), QObject::tr( "Processing" ), QgsMessageLog::WARNING );
207213
}
214+
if ( dissolve )
215+
bufferedGeometriesForDissolve << outputGeometry;
216+
else
217+
out.setGeometry( outputGeometry );
208218
}
209-
sink->addFeature( out );
219+
220+
if ( !dissolve )
221+
sink->addFeature( out );
210222

211223
feedback->setProgress( current * step );
212224
current++;
213225
}
214226

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+
215236
QVariantMap outputs;
216237
outputs.insert( QStringLiteral( "OUTPUT_LAYER" ), dest );
217238
return outputs;

0 commit comments

Comments
 (0)
Please sign in to comment.