Skip to content

Commit

Permalink
Always output algorithm results, even when input source has no
Browse files Browse the repository at this point in the history
features

Allows more versatile models which can handle empty layers
  • Loading branch information
nyalldawson committed Jul 18, 2017
1 parent dd0f183 commit 792e6bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
31 changes: 10 additions & 21 deletions src/core/processing/qgsnativealgorithms.cpp
Expand Up @@ -153,13 +153,11 @@ QVariantMap QgsBufferAlgorithm::processAlgorithm( const QVariantMap &parameters,
const QgsProcessingParameterDefinition *distanceParamDef = parameterDefinition( QStringLiteral( "DISTANCE" ) ); const QgsProcessingParameterDefinition *distanceParamDef = parameterDefinition( QStringLiteral( "DISTANCE" ) );


long count = source->featureCount(); long count = source->featureCount();
if ( count <= 0 )
return QVariantMap();


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


double step = 100.0 / count; double step = count > 0 ? 100.0 / count : 1;
int current = 0; int current = 0;


QList< QgsGeometry > bufferedGeometriesForDissolve; QList< QgsGeometry > bufferedGeometriesForDissolve;
Expand Down Expand Up @@ -254,13 +252,11 @@ QVariantMap QgsDissolveAlgorithm::processAlgorithm( const QVariantMap &parameter
QStringList fields = parameterAsFields( parameters, QStringLiteral( "FIELD" ), context ); QStringList fields = parameterAsFields( parameters, QStringLiteral( "FIELD" ), context );


long count = source->featureCount(); long count = source->featureCount();
if ( count <= 0 )
return QVariantMap();


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


double step = 100.0 / count; double step = count > 0 ? 100.0 / count : 1;
int current = 0; int current = 0;


if ( fields.isEmpty() ) if ( fields.isEmpty() )
Expand Down Expand Up @@ -421,8 +417,11 @@ QVariantMap QgsClipAlgorithm::processAlgorithm( const QVariantMap &parameters, Q
clipGeoms << f.geometry(); clipGeoms << f.geometry();
} }


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

if ( clipGeoms.isEmpty() ) if ( clipGeoms.isEmpty() )
return QVariantMap(); return outputs;


// are we clipping against a single feature? if so, we can show finer progress reports // are we clipping against a single feature? if so, we can show finer progress reports
bool singleClipFeature = false; bool singleClipFeature = false;
Expand Down Expand Up @@ -522,8 +521,6 @@ QVariantMap QgsClipAlgorithm::processAlgorithm( const QVariantMap &parameters, Q
} }
} }


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


Expand Down Expand Up @@ -655,13 +652,11 @@ QVariantMap QgsMultipartToSinglepartAlgorithm::processAlgorithm( const QVariantM
return QVariantMap(); return QVariantMap();


long count = source->featureCount(); long count = source->featureCount();
if ( count <= 0 )
return QVariantMap();


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


double step = 100.0 / count; double step = count > 0 ? 100.0 / count : 1;
int current = 0; int current = 0;
while ( it.nextFeature( f ) ) while ( it.nextFeature( f ) )
{ {
Expand Down Expand Up @@ -754,10 +749,8 @@ QVariantMap QgsExtractByExpressionAlgorithm::processAlgorithm( const QVariantMap
QgsExpressionContext expressionContext = createExpressionContext( parameters, context ); QgsExpressionContext expressionContext = createExpressionContext( parameters, context );


long count = source->featureCount(); long count = source->featureCount();
if ( count <= 0 )
return QVariantMap();


double step = 100.0 / count; double step = count > 0 ? 100.0 / count : 1;
int current = 0; int current = 0;


if ( !nonMatchingSink ) if ( !nonMatchingSink )
Expand Down Expand Up @@ -953,10 +946,8 @@ QVariantMap QgsExtractByAttributeAlgorithm::processAlgorithm( const QVariantMap
QgsExpressionContext expressionContext = createExpressionContext( parameters, context ); QgsExpressionContext expressionContext = createExpressionContext( parameters, context );


long count = source->featureCount(); long count = source->featureCount();
if ( count <= 0 )
return QVariantMap();


double step = 100.0 / count; double step = count > 0 ? 100.0 / count : 1;
int current = 0; int current = 0;


if ( !nonMatchingSink ) if ( !nonMatchingSink )
Expand Down Expand Up @@ -1058,10 +1049,8 @@ QVariantMap QgsRemoveNullGeometryAlgorithm::processAlgorithm( const QVariantMap
std::unique_ptr< QgsFeatureSink > nullSink( parameterAsSink( parameters, QStringLiteral( "NULL_OUTPUT" ), context, nullSinkId, source->fields() ) ); std::unique_ptr< QgsFeatureSink > nullSink( parameterAsSink( parameters, QStringLiteral( "NULL_OUTPUT" ), context, nullSinkId, source->fields() ) );


long count = source->featureCount(); long count = source->featureCount();
if ( count <= 0 )
return QVariantMap();


double step = 100.0 / count; double step = count > 0 ? 100.0 / count : 1;
int current = 0; int current = 0;


QgsFeature f; QgsFeature f;
Expand Down
4 changes: 1 addition & 3 deletions src/core/processing/qgsprocessingalgorithm.cpp
Expand Up @@ -642,13 +642,11 @@ QVariantMap QgsProcessingFeatureBasedAlgorithm::processAlgorithm( const QVariant
return QVariantMap(); return QVariantMap();


long count = mSource->featureCount(); long count = mSource->featureCount();
if ( count <= 0 )
return QVariantMap();


QgsFeature f; QgsFeature f;
QgsFeatureIterator it = mSource->getFeatures(); QgsFeatureIterator it = mSource->getFeatures();


double step = 100.0 / count; double step = count > 0 ? 100.0 / count : 1;
int current = 0; int current = 0;
while ( it.nextFeature( f ) ) while ( it.nextFeature( f ) )
{ {
Expand Down

0 comments on commit 792e6bd

Please sign in to comment.