Changes between Version 15 and Version 16 of PythonGotchas


Ignore:
Timestamp:
Oct 24, 2013, 3:22:28 PM (10 years ago)
Author:
sudobangbang
Comment:

updated comments for SetAttributeFilter

Legend:

Unmodified
Added
Removed
Modified
  • PythonGotchas

    v15 v16  
    124124For more information, please see #3552.
    125125
    126 === Layers with attribute filters {{{SetAttributeFilter()}}} will only return filtered features when using {{{GetNextFeature()}}} ===
    127 
    128 If you read the documentation for {{{SetAttributeFilter()}}} carefully you will see the caveat about {{{OGR_L_GetNextFeature()}}}. This means that, if you use {{{GetFeature()}}} instead of {{{GetNextFeature()}}}, you can still access and work with features from the layer that are not covered by the filter. In combination with {{{GetFeatureCount()}}} as a loop, this can lead to some subtle confusion. Iterating over the {{{Layer}}} object or using {{{GetNextFeature()}}} should be the default method for accessing features. :
     126=== Layers with attribute filters ({{{SetAttributeFilter()}}}) will only return filtered features when using {{{GetNextFeature()}}} ===
     127
     128If you read the documentation for {{{SetAttributeFilter()}}} carefully you will see the caveat about {{{OGR_L_GetNextFeature()}}}. This means that if you use {{{GetFeature()}}}, instead of {{{GetNextFeature()}}}, then you can still access and work with features from the layer that are not covered by the filter. {{{GetFeatureCount()}}} will respect the filter and show the correct number of features filtered. However, working with {{{GetFeatureCount()}}} in a loop can lead to some subtle confusion. Iterating over the {{{Layer}}} object or using {{{GetNextFeature()}}} should be the default method for accessing features:
    129129
    130130{{{
     
    134134>>> for i in range( 0, lyr.GetFeatureCount() ):
    135135...    feat = lyr.GetFeature( i )
    136 ...    print feat                                     # this will print out every feature in the layer disregarding the filter 
     136...    print feat                                     # this will print one feat, but it's the first feat in the Layer and not the filtered feat 
    137137...
    138138}}}