[gdal-dev] Layers and features

Even Rouault even.rouault at mines-paris.org
Wed Feb 26 13:02:22 PST 2014


Tim,

> When I extract a feature from a layer, what issues arise with the lifetime
> of the feature and the layer? If I keep the layer alive, will the feature
> continue to be valid?

Yes, feature objects (at least at C++ objects, not speaking about bindings) 
retrieved by GetNextFeature() and GetFeature() are completely free-standing. 
You can close the datasource and they should still be valid (reason: they keep 
a reference to their feature definition object, and once the last feature has 
been destroyed and the datasource closed, the feature definition will be 
destroyed)

> 
> If I clone a feature, is it now standalone or does it still depend on the
> layer/datasource in anyway?

No, and you don't need to clone it actually. See above

> 
> I see the note about destroying features prior to deleting the layer but
> need a bit of clarification on the dependencies.

Are you refering to "It is critical that
 all features associated with an OGRLayer (more specifically an 
 OGRFeatureDefn) be deleted before that layer/datasource is deleted." ?
Well, I think the note is wrong actually. Perhaps it dates back to old ages 
where the feature definition was not yet ref-counted ??

Best regards,

Even

-- 
Geospatial professional services
http://even.rouault.free.fr/services.html


More information about the gdal-dev mailing list