Skip to content

Commit

Permalink
ogr provider: add support for ignoring fields (adapted from threading…
Browse files Browse the repository at this point in the history
… branch)

git-svn-id: http://svn.osgeo.org/qgis/trunk@15274 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Feb 27, 2011
1 parent d5a6beb commit 8c1c2ad
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -416,12 +416,39 @@ QString QgsOgrProvider::storageType() const
return ogrDriverName;
}

void QgsOgrProvider::setIgnoredFields( bool fetchGeometry, const QgsAttributeList& fetchAttributes )
{
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
if ( OGR_L_TestCapability( ogrLayer, OLCIgnoreFields ) )
{
QVector<const char*> ignoredFields;
OGRFeatureDefnH featDefn = OGR_L_GetLayerDefn( ogrLayer );
for ( int i = 0; i < mAttributeFields.size(); i++ )
{
if ( !fetchAttributes.contains( i ) )
{
// add to ignored fields
ignoredFields.append( OGR_Fld_GetNameRef( OGR_FD_GetFieldDefn( featDefn, i ) ) );
}
}

if ( !fetchGeometry )
ignoredFields.append( "OGR_GEOMETRY" );
ignoredFields.append( "OGR_STYLE" ); // not used by QGIS
ignoredFields.append( NULL );

OGR_L_SetIgnoredFields( ogrLayer, ignoredFields.data() );
}
#endif
}

bool QgsOgrProvider::featureAtId( int featureId,
QgsFeature& feature,
bool fetchGeometry,
QgsAttributeList fetchAttributes )
{
setIgnoredFields( fetchGeometry, fetchAttributes );

OGRFeatureH fet = OGR_L_GetFeature( ogrLayer, featureId );
if ( fet == NULL )
return false;
Expand Down Expand Up @@ -606,6 +633,8 @@ void QgsOgrProvider::select( QgsAttributeList fetchAttributes, QgsRectangle rect
OGR_G_DestroyGeometry( filter );
}

setIgnoredFields( fetchGeometry, fetchAttributes );

//start with first feature
OGR_L_ResetReading( ogrLayer );
}
Expand Down
3 changes: 3 additions & 0 deletions src/providers/ogr/qgsogrprovider.h
Expand Up @@ -251,6 +251,9 @@ class QgsOgrProvider : public QgsVectorDataProvider
/** find out the number of features of the whole layer */
void recalculateFeatureCount();

/** tell OGR which fields not to fetch in nextFeature/featureAtId */
void setIgnoredFields( bool fetchGeometry, const QgsAttributeList& fetchAttributes );

private:
unsigned char *getGeometryPointer( OGRFeatureH fet );
QgsFieldMap mAttributeFields;
Expand Down

0 comments on commit 8c1c2ad

Please sign in to comment.