Skip to content

Commit

Permalink
Avoid extra feature requests in spatial query plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 6, 2016
1 parent d3cbe04 commit f686551
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/plugins/spatialquery/qgsspatialquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@ void QgsSpatialQuery::populateIndexResult(
QgsFeatureIds &qsetIndexResult, QgsFeatureId idTarget, QgsGeometry * geomTarget,
bool ( QgsGeometryEngine::* op )( const QgsAbstractGeometryV2&, QString* ) const )
{
QList<QgsFeatureId> listIdReference;
listIdReference = mIndexReference.intersects( geomTarget->boundingBox() );
QgsFeatureIds listIdReference = mIndexReference.intersects( geomTarget->boundingBox() ).toSet();
if ( listIdReference.isEmpty() )
{
return;
Expand All @@ -289,10 +288,10 @@ void QgsSpatialQuery::populateIndexResult(

QgsFeature featureReference;
const QgsGeometry * geomReference;
QList<QgsFeatureId>::iterator iterIdReference = listIdReference.begin();
for ( ; iterIdReference != listIdReference.end(); ++iterIdReference )
QgsFeatureIterator listIt = mLayerReference->getFeatures( QgsFeatureRequest().setFilterFids( listIdReference ) );

while ( listIt.nextFeature( featureReference ) )
{
mLayerReference->getFeatures( QgsFeatureRequest().setFilterFid( *iterIdReference ) ).nextFeature( featureReference );
geomReference = featureReference.constGeometry();

if (( geomEngine->*op )( *( geomReference->geometry() ), 0 ) )
Expand All @@ -309,8 +308,7 @@ void QgsSpatialQuery::populateIndexResultDisjoint(
QgsFeatureIds &qsetIndexResult, QgsFeatureId idTarget, QgsGeometry * geomTarget,
bool ( QgsGeometryEngine::* op )( const QgsAbstractGeometryV2&, QString* ) const )
{
QList<QgsFeatureId> listIdReference;
listIdReference = mIndexReference.intersects( geomTarget->boundingBox() );
QgsFeatureIds listIdReference = mIndexReference.intersects( geomTarget->boundingBox() ).toSet();
if ( listIdReference.isEmpty() )
{
qsetIndexResult.insert( idTarget );
Expand All @@ -323,11 +321,11 @@ void QgsSpatialQuery::populateIndexResultDisjoint(

QgsFeature featureReference;
const QgsGeometry * geomReference;
QList<QgsFeatureId>::iterator iterIdReference = listIdReference.begin();
QgsFeatureIterator listIt = mLayerReference->getFeatures( QgsFeatureRequest().setFilterFids( listIdReference ) );

bool addIndex = true;
for ( ; iterIdReference != listIdReference.end(); ++iterIdReference )
while ( listIt.nextFeature( featureReference ) )
{
mLayerReference->getFeatures( QgsFeatureRequest().setFilterFid( *iterIdReference ) ).nextFeature( featureReference );
geomReference = featureReference.constGeometry();
if (( geomEngine->*op )( *( geomReference->geometry() ), 0 ) )
{
Expand Down

0 comments on commit f686551

Please sign in to comment.