Skip to content

Commit d2f89c5

Browse files
committed
don't set relevant fields for VRT data sources when filtering for a rectangle.
OGR might need attributes otherwise considered irrelevant to construct the geometry to filter against (fixes #11223)
1 parent a7e1916 commit d2f89c5

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/providers/ogr/qgsogrfeatureiterator.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,17 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrFeatureSource* source, bool
5959
mSubsetStringSet = true;
6060
}
6161

62-
// make sure we fetch just relevant fields
6362
mFetchGeometry = ( mRequest.filterType() == QgsFeatureRequest::FilterRect ) || !( mRequest.flags() & QgsFeatureRequest::NoGeometry );
6463
QgsAttributeList attrs = ( mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes ) ? mRequest.subsetOfAttributes() : mSource->mFields.allAttributesList();
65-
QgsOgrUtils::setRelevantFields( ogrLayer, mSource->mFields.count(), mFetchGeometry, attrs );
64+
65+
// make sure we fetch just relevant fields
66+
// unless it's a VRT data source filtered by geometry as we don't know which
67+
// attributes make up the geometry and OGR won't fetch them to evaluate the
68+
// filter if we choose to ignore them (fixes #11223)
69+
if ( mSource->mDriverName != "OGR_VRT" || mRequest.filterType() != QgsFeatureRequest::FilterRect )
70+
{
71+
QgsOgrUtils::setRelevantFields( ogrLayer, mSource->mFields.count(), mFetchGeometry, attrs );
72+
}
6673

6774
// spatial query to select features
6875
if ( mRequest.filterType() == QgsFeatureRequest::FilterRect )
@@ -337,6 +344,7 @@ QgsOgrFeatureSource::QgsOgrFeatureSource( const QgsOgrProvider* p )
337344
mSubsetString = p->mSubsetString;
338345
mEncoding = p->mEncoding; // no copying - this is a borrowed pointer from Qt
339346
mFields = p->mAttributeFields;
347+
mDriverName = p->ogrDriverName;
340348
mOgrGeometryTypeFilter = wkbFlatten( p->mOgrGeometryTypeFilter );
341349
}
342350

src/providers/ogr/qgsogrfeatureiterator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class QgsOgrFeatureSource : public QgsAbstractFeatureSource
3838
QTextCodec* mEncoding;
3939
QgsFields mFields;
4040
OGRwkbGeometryType mOgrGeometryTypeFilter;
41+
QString mDriverName;
4142

4243
friend class QgsOgrFeatureIterator;
4344
};

0 commit comments

Comments
 (0)