Skip to content

Commit

Permalink
[processing] Fix Dissolve: input layer with empty geom. or no feat.
Browse files Browse the repository at this point in the history
  • Loading branch information
agiudiceandrea authored and nyalldawson committed May 19, 2024
1 parent ed7533d commit 9436fde
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/analysis/processing/qgsalgorithmdissolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ QVariantMap QgsCollectorAlgorithm::processCollection( const QVariantMap &paramet
if ( !sink )
throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );

QVariantMap outputs;
outputs.insert( QStringLiteral( "OUTPUT" ), dest );

const QStringList fields = parameterAsStrings( parameters, QStringLiteral( "FIELD" ), context );

const long count = source->featureCount();

if ( !( count > 0 ) )
return outputs;

QgsFeature f;
QgsFeatureIterator it = source->getFeatures( QgsFeatureRequest(), sourceFlags );

Expand Down Expand Up @@ -67,7 +73,7 @@ QVariantMap QgsCollectorAlgorithm::processCollection( const QVariantMap &paramet
firstFeature = false;
}

if ( f.hasGeometry() && !f.geometry().isNull() )
if ( f.hasGeometry() && !f.geometry().isEmpty() )
{
geomQueue.append( f.geometry() );
if ( maxQueueLength > 0 && geomQueue.length() > maxQueueLength )
Expand All @@ -83,7 +89,13 @@ QVariantMap QgsCollectorAlgorithm::processCollection( const QVariantMap &paramet
current++;
}

if ( !separateDisjoint )
if ( geomQueue.isEmpty() )
{
outputFeature.clearGeometry();
if ( !sink->addFeature( outputFeature, QgsFeatureSink::FastInsert ) )
throw QgsProcessingException( writeFeatureError( sink.get(), parameters, QStringLiteral( "OUTPUT" ) ) );
}
else if ( !separateDisjoint )
{
outputFeature.setGeometry( collector( geomQueue ) );
if ( !sink->addFeature( outputFeature, QgsFeatureSink::FastInsert ) )
Expand Down Expand Up @@ -136,7 +148,7 @@ QVariantMap QgsCollectorAlgorithm::processCollection( const QVariantMap &paramet
attributeHash.insert( indexAttributes, f.attributes() );
}

if ( f.hasGeometry() && !f.geometry().isNull() )
if ( f.hasGeometry() && !f.geometry().isEmpty() )
{
geometryHash[ indexAttributes ].append( f.geometry() );
}
Expand Down Expand Up @@ -190,8 +202,6 @@ QVariantMap QgsCollectorAlgorithm::processCollection( const QVariantMap &paramet
}
}

QVariantMap outputs;
outputs.insert( QStringLiteral( "OUTPUT" ), dest );
return outputs;
}

Expand Down

0 comments on commit 9436fde

Please sign in to comment.