Skip to content

Commit 5629425

Browse files
author
jef
committedFeb 27, 2011
ogr provider: add support for ignoring fields (adapted from threading branch)
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15274 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
 

‎src/providers/ogr/qgsogrprovider.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,39 @@ QString QgsOgrProvider::storageType() const
416416
return ogrDriverName;
417417
}
418418

419+
void QgsOgrProvider::setIgnoredFields( bool fetchGeometry, const QgsAttributeList& fetchAttributes )
420+
{
421+
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
422+
if ( OGR_L_TestCapability( ogrLayer, OLCIgnoreFields ) )
423+
{
424+
QVector<const char*> ignoredFields;
425+
OGRFeatureDefnH featDefn = OGR_L_GetLayerDefn( ogrLayer );
426+
for ( int i = 0; i < mAttributeFields.size(); i++ )
427+
{
428+
if ( !fetchAttributes.contains( i ) )
429+
{
430+
// add to ignored fields
431+
ignoredFields.append( OGR_Fld_GetNameRef( OGR_FD_GetFieldDefn( featDefn, i ) ) );
432+
}
433+
}
434+
435+
if ( !fetchGeometry )
436+
ignoredFields.append( "OGR_GEOMETRY" );
437+
ignoredFields.append( "OGR_STYLE" ); // not used by QGIS
438+
ignoredFields.append( NULL );
439+
440+
OGR_L_SetIgnoredFields( ogrLayer, ignoredFields.data() );
441+
}
442+
#endif
443+
}
419444

420445
bool QgsOgrProvider::featureAtId( int featureId,
421446
QgsFeature& feature,
422447
bool fetchGeometry,
423448
QgsAttributeList fetchAttributes )
424449
{
450+
setIgnoredFields( fetchGeometry, fetchAttributes );
451+
425452
OGRFeatureH fet = OGR_L_GetFeature( ogrLayer, featureId );
426453
if ( fet == NULL )
427454
return false;
@@ -606,6 +633,8 @@ void QgsOgrProvider::select( QgsAttributeList fetchAttributes, QgsRectangle rect
606633
OGR_G_DestroyGeometry( filter );
607634
}
608635

636+
setIgnoredFields( fetchGeometry, fetchAttributes );
637+
609638
//start with first feature
610639
OGR_L_ResetReading( ogrLayer );
611640
}

‎src/providers/ogr/qgsogrprovider.h

+3
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ class QgsOgrProvider : public QgsVectorDataProvider
251251
/** find out the number of features of the whole layer */
252252
void recalculateFeatureCount();
253253

254+
/** tell OGR which fields not to fetch in nextFeature/featureAtId */
255+
void setIgnoredFields( bool fetchGeometry, const QgsAttributeList& fetchAttributes );
256+
254257
private:
255258
unsigned char *getGeometryPointer( OGRFeatureH fet );
256259
QgsFieldMap mAttributeFields;

0 commit comments

Comments
 (0)
Please sign in to comment.