Skip to content

Commit 6d94e6f

Browse files
committed
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.
1 parent 6a760ef commit 6d94e6f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/core/processing/qgsnativealgorithms.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,7 @@ void QgsLocationBasedAlgorithm::process( QgsFeatureSource *targetSource,
14221422
double step = intersectSource->featureCount() > 0 ? 100.0 / intersectSource->featureCount() : 1;
14231423
int current = 0;
14241424
QgsFeature f;
1425+
std::unique_ptr< QgsGeometryEngine > engine;
14251426
while ( fIt.nextFeature( f ) )
14261427
{
14271428
if ( feedback->isCanceled() )
@@ -1430,10 +1431,9 @@ void QgsLocationBasedAlgorithm::process( QgsFeatureSource *targetSource,
14301431
if ( !f.hasGeometry() )
14311432
continue;
14321433

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

1436+
QgsRectangle bbox = f.geometry().boundingBox();
14371437
request = QgsFeatureRequest().setFilterRect( bbox );
14381438
if ( onlyRequireTargetIds )
14391439
request.setFlags( QgsFeatureRequest::NoGeometry ).setSubsetOfAttributes( QgsAttributeList() );
@@ -1451,6 +1451,12 @@ void QgsLocationBasedAlgorithm::process( QgsFeatureSource *targetSource,
14511451
continue;
14521452
}
14531453

1454+
if ( !engine )
1455+
{
1456+
engine.reset( QgsGeometry::createGeometryEngine( f.geometry().geometry() ) );
1457+
engine->prepareGeometry();
1458+
}
1459+
14541460
for ( Predicate predicate : qgsAsConst( predicates ) )
14551461
{
14561462
bool isMatch = false;

0 commit comments

Comments
 (0)