Skip to content
Permalink
Browse files

Optimise QgsFeaturePool construction

- 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 19, 2018
1 parent 26631b3 commit 4a8d84bdf905fdf3c20ca6eafd1f31afde801456
Showing with 7 additions and 9 deletions.
  1. +7 −9 src/analysis/vector/geometry_checker/qgsfeaturepool.cpp
@@ -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
{

0 comments on commit 4a8d84b

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