Skip to content

Commit 894cc7c

Browse files
committedNov 23, 2018
[processing] Fix error in dissolve
Backported from master
1 parent 8f1c51b commit 894cc7c

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed
 

‎src/analysis/processing/qgsalgorithmdissolve.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,30 @@ QgsDissolveAlgorithm *QgsDissolveAlgorithm::createInstance() const
210210
return new QgsDissolveAlgorithm();
211211
}
212212

213+
213214
QVariantMap QgsDissolveAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
214215
{
215-
return processCollection( parameters, context, feedback, []( const QVector< QgsGeometry > &parts )->QgsGeometry
216+
return processCollection( parameters, context, feedback, [ & ]( const QVector< QgsGeometry > &parts )->QgsGeometry
216217
{
217-
return QgsGeometry::unaryUnion( parts );
218+
QgsGeometry result( QgsGeometry::unaryUnion( parts ) );
219+
// Geos may fail in some cases, let's try a slower but safer approach
220+
// See: https://issues.qgis.org/issues/20591 - Dissolve tool failing to produce outputs
221+
if ( ! result.lastError().isEmpty() && parts.count() > 2 )
222+
{
223+
QgsDebugMsg( QStringLiteral( "GEOS exception, taking the slower route ..." ) );
224+
result = QgsGeometry();
225+
for ( const auto &p : parts )
226+
{
227+
result = QgsGeometry::unaryUnion( QVector< QgsGeometry >() << result << p );
228+
}
229+
}
230+
if ( ! result.lastError().isEmpty() )
231+
{
232+
feedback->reportError( result.lastError(), true );
233+
if ( result.isEmpty() )
234+
throw QgsProcessingException( QObject::tr( "The algorithm returned no output." ) );
235+
}
236+
return result;
218237
}, 10000 );
219238
}
220239

0 commit comments

Comments
 (0)
Please sign in to comment.