Skip to content

Commit

Permalink
Optimise QgsFeaturePool construction
Browse files Browse the repository at this point in the history
- Avoid double iteration over complete layer when all features are
being used
- Avoid iterating over non-required features when selected features
are being used
  • Loading branch information
nyalldawson committed Aug 20, 2018
1 parent 26631b3 commit 4a8d84b
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/analysis/vector/geometry_checker/qgsfeaturepool.cpp
Expand Up @@ -32,25 +32,23 @@ QgsFeaturePool::QgsFeaturePool( QgsVectorLayer *layer, double layerToMapUnits, c
, mLayerToMapTransform( layerToMapTransform )
, mSelectedOnly( selectedOnly )
{
// Build spatial index
QgsFeature feature;
QgsFeatureRequest req;
req.setSubsetOfAttributes( QgsAttributeList() );
if ( selectedOnly )
{
mFeatureIds = layer->selectedFeatureIds();
}
else
{
mFeatureIds = layer->allFeatureIds();
req.setFilterFids( mFeatureIds );
}

// Build spatial index
QgsFeature feature;
QgsFeatureRequest req;
req.setSubsetOfAttributes( QgsAttributeList() );
QgsFeatureIterator it = layer->getFeatures( req );
while ( it.nextFeature( feature ) )
{
if ( mFeatureIds.contains( feature.id() ) && feature.geometry() )
if ( feature.geometry() )
{
mIndex.insertFeature( feature );
mFeatureIds.insert( feature.id() );
}
else
{
Expand Down

0 comments on commit 4a8d84b

Please sign in to comment.