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.
This commit is contained in:
Nyall Dawson 2017-09-10 10:54:27 +10:00
parent 6a760ef3df
commit 6d94e6fc5c

View File

@ -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;