Skip to content

Commit

Permalink
ogr provider: actually only use relevant fields in feature iterator (f…
Browse files Browse the repository at this point in the history
…ixes #9062)
  • Loading branch information
jef-n committed Nov 13, 2013
1 parent eabfa48 commit af73f30
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/providers/ogr/qgsogrfeatureiterator.cpp
Expand Up @@ -91,7 +91,7 @@ void QgsOgrFeatureIterator::ensureRelevantFields()
{
mFetchGeometry = ( mRequest.filterType() == QgsFeatureRequest::FilterRect ) || !( mRequest.flags() & QgsFeatureRequest::NoGeometry );
QgsAttributeList attrs = ( mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes ) ? mRequest.subsetOfAttributes() : P->attributeIndexes();
P->setRelevantFields( mFetchGeometry, attrs );
P->setRelevantFields( ogrLayer, mFetchGeometry, attrs );
P->mRelevantFieldsForNextFeature = true;
}

Expand Down
12 changes: 6 additions & 6 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -555,7 +555,7 @@ QStringList QgsOgrProvider::subLayers() const
// Count features for geometry types
QMap<OGRwkbGeometryType, int> fCount;
// TODO: avoid reading attributes, setRelevantFields cannot be called here because it is not constant
//setRelevantFields( true, QgsAttributeList() );
//setRelevantFields( ogrLayer, true, QgsAttributeList() );
OGR_L_ResetReading( layer );
OGRFeatureH fet;
while (( fet = OGR_L_GetNextFeature( layer ) ) )
Expand Down Expand Up @@ -714,7 +714,7 @@ QString QgsOgrProvider::storageType() const
return ogrDriverName;
}

void QgsOgrProvider::setRelevantFields( bool fetchGeometry, const QgsAttributeList &fetchAttributes )
void QgsOgrProvider::setRelevantFields( OGRLayerH ogrLayer, bool fetchGeometry, const QgsAttributeList &fetchAttributes )
{
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
if ( OGR_L_TestCapability( ogrLayer, OLCIgnoreFields ) )
Expand Down Expand Up @@ -972,7 +972,7 @@ bool QgsOgrProvider::addFeature( QgsFeature& f )

bool QgsOgrProvider::addFeatures( QgsFeatureList & flist )
{
setRelevantFields( true, attributeIndexes() );
setRelevantFields( ogrLayer, true, attributeIndexes() );

bool returnvalue = true;
for ( QgsFeatureList::iterator it = flist.begin(); it != flist.end(); ++it )
Expand Down Expand Up @@ -1074,7 +1074,7 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr

clearMinMaxCache();

setRelevantFields( true, attributeIndexes() );
setRelevantFields( ogrLayer, true, attributeIndexes() );

for ( QgsChangedAttributesMap::const_iterator it = attr_map.begin(); it != attr_map.end(); ++it )
{
Expand Down Expand Up @@ -1170,7 +1170,7 @@ bool QgsOgrProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
OGRFeatureH theOGRFeature = 0;
OGRGeometryH theNewGeometry = 0;

setRelevantFields( true, attributeIndexes() );
setRelevantFields( ogrLayer, true, attributeIndexes() );

for ( QgsGeometryMap::iterator it = geometry_map.begin(); it != geometry_map.end(); ++it )
{
Expand Down Expand Up @@ -2382,7 +2382,7 @@ void QgsOgrProvider::recalculateFeatureCount()
{
featuresCounted = 0;
OGR_L_ResetReading( ogrLayer );
setRelevantFields( true, QgsAttributeList() );
setRelevantFields( ogrLayer, true, QgsAttributeList() );
OGR_L_ResetReading( ogrLayer );
OGRFeatureH fet;
while (( fet = OGR_L_GetNextFeature( ogrLayer ) ) )
Expand Down
2 changes: 1 addition & 1 deletion src/providers/ogr/qgsogrprovider.h
Expand Up @@ -270,7 +270,7 @@ class QgsOgrProvider : public QgsVectorDataProvider
void recalculateFeatureCount();

/** tell OGR, which fields to fetch in nextFeature/featureAtId (ie. which not to ignore) */
void setRelevantFields( bool fetchGeometry, const QgsAttributeList& fetchAttributes );
void setRelevantFields( OGRLayerH ogrLayer, bool fetchGeometry, const QgsAttributeList& fetchAttributes );

/** convert a QgsField to work with OGR */
static bool convertField( QgsField &field, const QTextCodec &encoding );
Expand Down

0 comments on commit af73f30

Please sign in to comment.