[QGIS Commit] r15274 - trunk/qgis/src/providers/ogr
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sun Feb 27 14:33:54 EST 2011
Author: jef
Date: 2011-02-27 11:33:54 -0800 (Sun, 27 Feb 2011)
New Revision: 15274
Modified:
trunk/qgis/src/providers/ogr/qgsogrprovider.cpp
trunk/qgis/src/providers/ogr/qgsogrprovider.h
Log:
ogr provider: add support for ignoring fields (adapted from threading branch)
Modified: trunk/qgis/src/providers/ogr/qgsogrprovider.cpp
===================================================================
--- trunk/qgis/src/providers/ogr/qgsogrprovider.cpp 2011-02-27 19:32:00 UTC (rev 15273)
+++ trunk/qgis/src/providers/ogr/qgsogrprovider.cpp 2011-02-27 19:33:54 UTC (rev 15274)
@@ -416,12 +416,39 @@
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 @@
OGR_G_DestroyGeometry( filter );
}
+ setIgnoredFields( fetchGeometry, fetchAttributes );
+
//start with first feature
OGR_L_ResetReading( ogrLayer );
}
Modified: trunk/qgis/src/providers/ogr/qgsogrprovider.h
===================================================================
--- trunk/qgis/src/providers/ogr/qgsogrprovider.h 2011-02-27 19:32:00 UTC (rev 15273)
+++ trunk/qgis/src/providers/ogr/qgsogrprovider.h 2011-02-27 19:33:54 UTC (rev 15274)
@@ -251,6 +251,9 @@
/** 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;
More information about the QGIS-commit
mailing list