[QGIS Commit] r14839 - branches/threading-branch/src/providers/ogr

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Dec 4 15:50:02 EST 2010


Author: wonder
Date: 2010-12-04 12:50:02 -0800 (Sat, 04 Dec 2010)
New Revision: 14839

Modified:
   branches/threading-branch/src/providers/ogr/qgsogrfeatureiterator.cpp
   branches/threading-branch/src/providers/ogr/qgsogrprovider.cpp
   branches/threading-branch/src/providers/ogr/qgsogrprovider.h
Log:
Optimized access to features with OGR >= 1.8


Modified: branches/threading-branch/src/providers/ogr/qgsogrfeatureiterator.cpp
===================================================================
--- branches/threading-branch/src/providers/ogr/qgsogrfeatureiterator.cpp	2010-12-04 16:53:16 UTC (rev 14838)
+++ branches/threading-branch/src/providers/ogr/qgsogrfeatureiterator.cpp	2010-12-04 20:50:02 UTC (rev 14839)
@@ -56,6 +56,8 @@
     OGR_G_DestroyGeometry( filter );
   }
 
+  P->setIgnoredFields( fetchGeometry, fetchAttributes );
+
   //start with first feature
   OGR_L_ResetReading( P->ogrLayer );
 

Modified: branches/threading-branch/src/providers/ogr/qgsogrprovider.cpp
===================================================================
--- branches/threading-branch/src/providers/ogr/qgsogrprovider.cpp	2010-12-04 16:53:16 UTC (rev 14838)
+++ branches/threading-branch/src/providers/ogr/qgsogrprovider.cpp	2010-12-04 20:50:02 UTC (rev 14839)
@@ -413,7 +413,32 @@
   return QgsFeatureIterator( new QgsOgrFeatureIterator( this, fetchAttributes, rect, fetchGeometry, useIntersect ) );
 }
 
+void QgsOgrProvider::setIgnoredFields( bool fetchGeometry, const QgsAttributeList& fetchAttributes )
+{
+#if GDAL_VERSION_NUM >= 1800 // from GDAL 1.8
+  if ( OGR_L_TestCapability( ogrLayer, OLCIgnoreFields ) )
+  {
+    QVector<const char*> ignoredFields;
+    OGRFeatureDefnH featDefn = OGR_L_GetLayerDefn( ogrLayer );
+    for ( int i = 0; i < mAttributeVector.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,
@@ -422,6 +447,8 @@
   // make sure no other thread is accessing the layer right now
   QMutexLocker layerLocker( &mLayerMutex );
 
+  setIgnoredFields( fetchGeometry, fetchAttributes );
+
   OGRFeatureH fet = OGR_L_GetFeature( ogrLayer, featureId );
   if ( fet == NULL )
     return false;

Modified: branches/threading-branch/src/providers/ogr/qgsogrprovider.h
===================================================================
--- branches/threading-branch/src/providers/ogr/qgsogrprovider.h	2010-12-04 16:53:16 UTC (rev 14838)
+++ branches/threading-branch/src/providers/ogr/qgsogrprovider.h	2010-12-04 20:50:02 UTC (rev 14839)
@@ -244,6 +244,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