Skip to content

Commit

Permalink
don't set relevant fields for VRT data sources when filtering for a r…
Browse files Browse the repository at this point in the history
…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 d2f89c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/providers/ogr/qgsogrfeatureiterator.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
}

Expand Down
1 change: 1 addition & 0 deletions src/providers/ogr/qgsogrfeatureiterator.h
Expand Up @@ -38,6 +38,7 @@ class QgsOgrFeatureSource : public QgsAbstractFeatureSource
QTextCodec* mEncoding;
QgsFields mFields;
OGRwkbGeometryType mOgrGeometryTypeFilter;
QString mDriverName;

friend class QgsOgrFeatureIterator;
};
Expand Down

0 comments on commit d2f89c5

Please sign in to comment.