Skip to content
Permalink
Browse files

Optimise Extract/Select by Location alg

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 6d94e6fc5cb362f11c1d7263ff41c057dcdbb217
Showing with 9 additions and 3 deletions.
  1. +9 −3 src/core/processing/qgsnativealgorithms.cpp
@@ -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() )
@@ -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() );
@@ -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;

0 comments on commit 6d94e6f

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