Skip to content
Permalink
Browse files

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
  • Loading branch information
jef
jef committed Feb 27, 2011
1 parent c7b937d commit 562942513b0b3e5695d6fe34f3c7b657eec2b4d4
Showing with 32 additions and 0 deletions.
  1. +29 −0 src/providers/ogr/qgsogrprovider.cpp
  2. +3 −0 src/providers/ogr/qgsogrprovider.h
@@ -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;
@@ -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 );
}
@@ -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;

0 comments on commit 5629425

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