In Python "if myLayer:" can reset feature iteration
|Reported by:||tbnorth||Owned by:||hobu|
After some debugging with EvenR on IRC, we found that
if myLayer: return myLayer.GetNextFeature()
behaves unexpectedly for some drivers (AVCbin for example) because
if myLayer: calls
myLayer.__len__() which calls
GetFeatureCount which re-sets feature iteration for some drivers. So it's as if there's a hidden
myLayer.ResetReading() before the return statement.
if myLayer is not None: is a workaround, but the surprise can be eliminated (it's hard to work out what's going on), if
__notzero__ was defined on
myLayer, that would be called before
__notzero__ could possibly just return True all the time, seeing OGR seems to use None as the value to indicate a non-layer. See Python's __nonzero__ docs.
Usually a layer will only be tested once, immediately after
GetLayer, so the current behaviour won't bother most people, but in cases where the layer is perhaps wrapped in a object feeding features to a client and
if myLayer: is called repeatedly, the issue will interfere.