@@ -416,12 +416,39 @@ QString QgsOgrProvider::storageType() const
416
416
return ogrDriverName;
417
417
}
418
418
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
+ }
419
444
420
445
bool QgsOgrProvider::featureAtId ( int featureId,
421
446
QgsFeature& feature,
422
447
bool fetchGeometry,
423
448
QgsAttributeList fetchAttributes )
424
449
{
450
+ setIgnoredFields ( fetchGeometry, fetchAttributes );
451
+
425
452
OGRFeatureH fet = OGR_L_GetFeature ( ogrLayer, featureId );
426
453
if ( fet == NULL )
427
454
return false ;
@@ -606,6 +633,8 @@ void QgsOgrProvider::select( QgsAttributeList fetchAttributes, QgsRectangle rect
606
633
OGR_G_DestroyGeometry ( filter );
607
634
}
608
635
636
+ setIgnoredFields ( fetchGeometry, fetchAttributes );
637
+
609
638
// start with first feature
610
639
OGR_L_ResetReading ( ogrLayer );
611
640
}
0 commit comments