Skip to content
Permalink
Browse files

don't set relevant fields for VRT data sources when filtering for a r…

…ectangle.

OGR might need attributes otherwise considered irrelevant to construct the
geometry to filter against (fixes #11223)
  • Loading branch information
jef-n committed Oct 19, 2014
1 parent a7e1916 commit d2f89c5a2042747e36f4f9cd0370cec2da27d1ca
Showing with 11 additions and 2 deletions.
  1. +10 −2 src/providers/ogr/qgsogrfeatureiterator.cpp
  2. +1 −0 src/providers/ogr/qgsogrfeatureiterator.h
@@ -59,10 +59,17 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrFeatureSource* source, bool
mSubsetStringSet = true;
}

// make sure we fetch just relevant fields
mFetchGeometry = ( mRequest.filterType() == QgsFeatureRequest::FilterRect ) || !( mRequest.flags() & QgsFeatureRequest::NoGeometry );
QgsAttributeList attrs = ( mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes ) ? mRequest.subsetOfAttributes() : mSource->mFields.allAttributesList();
QgsOgrUtils::setRelevantFields( ogrLayer, mSource->mFields.count(), mFetchGeometry, attrs );

// make sure we fetch just relevant fields
// unless it's a VRT data source filtered by geometry as we don't know which
// attributes make up the geometry and OGR won't fetch them to evaluate the
// filter if we choose to ignore them (fixes #11223)
if ( mSource->mDriverName != "OGR_VRT" || mRequest.filterType() != QgsFeatureRequest::FilterRect )
{
QgsOgrUtils::setRelevantFields( ogrLayer, mSource->mFields.count(), mFetchGeometry, attrs );
}

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

@@ -38,6 +38,7 @@ class QgsOgrFeatureSource : public QgsAbstractFeatureSource
QTextCodec* mEncoding;
QgsFields mFields;
OGRwkbGeometryType mOgrGeometryTypeFilter;
QString mDriverName;

friend class QgsOgrFeatureIterator;
};

0 comments on commit d2f89c5

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