Skip to content

Commit

Permalink
Optimise Extract/Select by Location alg
Browse files Browse the repository at this point in the history
Only create and prepare the GEOS representation for intersection
layer features when we encounter a feature in the target layer
within that feature's bounding box.
  • Loading branch information
nyalldawson committed Sep 10, 2017
1 parent 6a760ef commit 6d94e6f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/core/processing/qgsnativealgorithms.cpp
Expand Up @@ -1422,6 +1422,7 @@ void QgsLocationBasedAlgorithm::process( QgsFeatureSource *targetSource,
double step = intersectSource->featureCount() > 0 ? 100.0 / intersectSource->featureCount() : 1;
int current = 0;
QgsFeature f;
std::unique_ptr< QgsGeometryEngine > engine;
while ( fIt.nextFeature( f ) )
{
if ( feedback->isCanceled() )
Expand All @@ -1430,10 +1431,9 @@ void QgsLocationBasedAlgorithm::process( QgsFeatureSource *targetSource,
if ( !f.hasGeometry() )
continue;

std::unique_ptr< QgsGeometryEngine > engine( QgsGeometry::createGeometryEngine( f.geometry().geometry() ) );
engine->prepareGeometry();
QgsRectangle bbox = f.geometry().boundingBox();
engine.reset();

QgsRectangle bbox = f.geometry().boundingBox();
request = QgsFeatureRequest().setFilterRect( bbox );
if ( onlyRequireTargetIds )
request.setFlags( QgsFeatureRequest::NoGeometry ).setSubsetOfAttributes( QgsAttributeList() );
Expand All @@ -1451,6 +1451,12 @@ void QgsLocationBasedAlgorithm::process( QgsFeatureSource *targetSource,
continue;
}

if ( !engine )
{
engine.reset( QgsGeometry::createGeometryEngine( f.geometry().geometry() ) );
engine->prepareGeometry();
}

for ( Predicate predicate : qgsAsConst( predicates ) )
{
bool isMatch = false;
Expand Down

0 comments on commit 6d94e6f

Please sign in to comment.