Changes between Version 13 and Version 14 of PythonGotchas


Ignore:
Timestamp:
Oct 23, 2013, 12:30:57 PM (11 years ago)
Author:
sudobangbang
Comment:

added subtle reminder about SetAttributeFilter adn GetNextFeature

Legend:

Unmodified
Added
Removed
Modified
  • PythonGotchas

    v13 v14  
    123123
    124124For more information, please see #3552.
     125
     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 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:
     129
     130{{{
     131#!python
     132>>> lyr = inDataSource.GetLayer()
     133>>> lyr.SetAttributeFilter("PIN = '0000200001'")      # this is a unique filter for only one record
     134>>> for i in range( 0, lyr.GetFeatureCount() ):
     135...    feat = lyr.GetFeature( i )
     136...    print feat                                     # this will print out every feature in the layer disregarding the filter 
     137...
     138}}}
     139
    125140
    126141=== Certain objects contain a {{{Destroy()}}} method, but you should never use it ===