Skip to content
Permalink
Browse files

[processing] Improve spatial join speed when joining few features to …

…many

E.g. when joining a 7 feature polygon layer to a 3.2 million feature polygon
layer, processing time (on a debug build) has dropped from 696 seconds
to 1.3 seconds
  • Loading branch information
nyalldawson committed Jan 14, 2020
1 parent 771fc3f commit 94cb5f8ca9c36171bbc0de49728f04f898f4f787
Showing with 17 additions and 4 deletions.
  1. +17 −4 src/analysis/processing/qgsalgorithmjoinbylocation.cpp
@@ -184,11 +184,24 @@ QVariantMap QgsJoinByLocationAlgorithm::processAlgorithm( const QVariantMap &par
{
case OneToMany:
case JoinToFirst:
// TODO - consider using some heuristics to determine whether it's always best to iterate over the join
// source. It's best when you're doing a many -> few join (e.g. an input of millions of address points joined to hundreds of locality polygons),
// but poor in other circumstances (e.g. an input of few polygon boundaries joined to thousands of polygon other polygon features)
processAlgorithmByIteratingOverJoinedSource( context, feedback );
{
if ( mBaseSource->featureCount() > 0 && mJoinSource->featureCount() > 0 && mBaseSource->featureCount() < mJoinSource->featureCount() )
{
// joining FEWER features to a layer with MORE features. So we iterate over the FEW features and find matches from the MANY
processAlgorithmByIteratingOverInputSource( context, feedback );
}
else
{
// default -- iterate over the join source and match back to the base source. We do this on the assumption that the most common
// use case is joining a points layer to a polygon layer (taking polygon attributes and adding them to the points), so by iterating
// over the polygons we can take advantage of prepared geometries for the spatial relationship test.

// TODO - consider using more heuristics to determine whether it's always best to iterate over the join
// source.
processAlgorithmByIteratingOverJoinedSource( context, feedback );
}
break;
}

case JoinToLargestOverlap:
processAlgorithmByIteratingOverInputSource( context, feedback );

0 comments on commit 94cb5f8

Please sign in to comment.
You can’t perform that action at this time.