Skip to content

Commit e9e7efc

Browse files
committedNov 18, 2017
Fix incorrect extents returned by memory provider when subset string set
1 parent 1cfd6ee commit e9e7efc

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed
 

‎src/core/providers/memory/qgsmemoryprovider.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,30 @@ QgsRectangle QgsMemoryProvider::extent() const
275275
if ( mExtent.isEmpty() && !mFeatures.isEmpty() )
276276
{
277277
mExtent.setMinimal();
278-
Q_FOREACH ( const QgsFeature &feat, mFeatures )
278+
if ( mSubsetString.isEmpty() )
279279
{
280-
if ( feat.hasGeometry() )
281-
mExtent.combineExtentWith( feat.geometry().boundingBox() );
280+
// fast way - iterate through all features
281+
Q_FOREACH ( const QgsFeature &feat, mFeatures )
282+
{
283+
if ( feat.hasGeometry() )
284+
mExtent.combineExtentWith( feat.geometry().boundingBox() );
285+
}
286+
}
287+
else
288+
{
289+
QgsFeature f;
290+
QgsFeatureIterator fi = getFeatures( QgsFeatureRequest().setSubsetOfAttributes( QgsAttributeList() ) );
291+
while ( fi.nextFeature( f ) )
292+
{
293+
if ( f.hasGeometry() )
294+
mExtent.combineExtentWith( f.geometry().boundingBox() );
295+
}
282296
}
283297
}
298+
else if ( mFeatures.isEmpty() )
299+
{
300+
mExtent.setMinimal();
301+
}
284302

285303
return mExtent;
286304
}
@@ -511,6 +529,7 @@ bool QgsMemoryProvider::setSubsetString( const QString &theSQL, bool updateFeatu
511529

512530
mSubsetString = theSQL;
513531
clearMinMaxCache();
532+
mExtent.setMinimal();
514533

515534
emit dataChanged();
516535
return true;

0 commit comments

Comments
 (0)
Please sign in to comment.