[gdal-dev] python/OGR error: interpreter crashes calling geometries method stored inside a python list

G. Allegri giohappy at gmail.com
Wed May 6 11:22:57 EDT 2009

I imagined it was something with features scope. Thanks Howard, for
now I will use your snippet... as I can't find a different way to
prevent the problem.

2009/5/6 Howard Butler <hobu.inc at gmail.com>:
> On May 6, 2009, at 10:02 AM, G. Allegri wrote:
>> geometries = [features[i].GetGeometryRef() for i in range(len(features))]
> features[i] is a temporary and goes poof once it goes out of scope.
>  GetGeometryRef depends on features[i] staying alive for *its* entire
> lifetime as well.  In short, you can't depend on the reference counting of
> the objects in this instance.
> I will note this is awful, but it should not segfault:
> geometries =
> [ogr.CreateGeometryFromWkb(features[i].GetGeometryRef().ExportToWkb()) for i
> in range(len(features))]

More information about the gdal-dev mailing list