Skip to content

Commit

Permalink
Fix progress reports, joined feature count
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 2, 2020
1 parent c6565ef commit db4c99f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/analysis/processing/qgsalgorithmjoinbylocation.cpp
Expand Up @@ -182,20 +182,18 @@ QVariantMap QgsJoinByLocationAlgorithm::processAlgorithm( const QVariantMap &par
if ( parameters.value( QStringLiteral( "NON_MATCHING" ) ).isValid() && !mUnjoinedFeatures )
throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "NON_MATCHING" ) ) );

qlonglong joinedCount = 0;
QgsFeatureIterator joinIter = joinSource->getFeatures( QgsFeatureRequest().setDestinationCrs( mBaseSource->sourceCrs(), context.transformContext() ).setSubsetOfAttributes( mJoinedFieldIndices ) );
QgsFeature f;

// Create output vector layer with additional attributes
const double step = mBaseSource->featureCount() > 0 ? 100.0 / mBaseSource->featureCount() : 1;
const double step = joinSource->featureCount() > 0 ? 100.0 / joinSource->featureCount() : 1;
long i = 0;
while ( joinIter.nextFeature( f ) )
{
if ( feedback->isCanceled() )
break;

if ( processFeatures( f, feedback ) )
joinedCount++;
processFeatures( f, feedback );

i++;
feedback->setProgress( i * step );
Expand Down Expand Up @@ -243,7 +241,7 @@ QVariantMap QgsJoinByLocationAlgorithm::processAlgorithm( const QVariantMap &par
{
outputs.insert( QStringLiteral( "NON_MATCHING" ), nonMatchingSinkId );
}
outputs.insert( QStringLiteral( "JOINED_COUNT" ), joinedCount );
outputs.insert( QStringLiteral( "JOINED_COUNT" ), static_cast< long long >( mJoinedCount ) );
return outputs;
}

Expand Down Expand Up @@ -376,6 +374,7 @@ bool QgsJoinByLocationAlgorithm::processFeatures( QgsFeature &joinFeature, QgsPr
ok = true;

mAddedIds.insert( baseFeature.id() );
mJoinedCount++;
}
}
return ok;
Expand Down
1 change: 1 addition & 0 deletions src/analysis/processing/qgsalgorithmjoinbylocation.h
Expand Up @@ -59,6 +59,7 @@ class QgsJoinByLocationAlgorithm : public QgsProcessingAlgorithm
OneToMany = 0,
OneToOne = 1,
};
long mJoinedCount = 0;
std::unique_ptr< QgsProcessingFeatureSource > mBaseSource;
QgsAttributeList mJoinedFieldIndices;
bool mDiscardNonMatching = false;
Expand Down

0 comments on commit db4c99f

Please sign in to comment.