<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.32.2">
</HEAD>
<BODY>
Thanks Frank, excellent tip to be aware of. It's working great now.<BR>
<BR>
-marius<BR>
<BR>
On Wed, 2011-07-13 at 22:19 -0700, Frank Warmerdam wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
On Wed, Jul 13, 2011 at 4:23 PM, Marius Jigmond
<<A HREF="mailto:mariusjigmond@hotmail.com">mariusjigmond@hotmail.com</A>> wrote:
> aqfeat = aqLayer.GetNextFeature()
> aqgeom = aqfeat.GetGeometryRef()
> geomList = [aqgeom]
>
> while aqfeat is not None: #loop thru features in case of islands/multiple
> polygons
> aqfeat = aqLayer.GetNextFeature()
> if aqfeat is not None:
> geomList.append(aqfeat.GetGeometryRef())
Marius,
When you read a new
feature aqfeat is replaced, and the old feature is cleaned up
by the garbage collector. At that point it's associate geometry
is also destroyed even though it is referenced from Python. This
is a weakness caused by the way object lifetimes are handled
in OGR that doesn't map well to Python. So you should be cloning
the geometry when you add it to your list.
eg.
geomList = [aqgeom.Clone()]
...
geomList.append( aqfeat.GetGeometryRef().Clone() )
The rule of thumb is that ogr.Datastore and ogr.Feature are well
handled according to Python reference counting semantics.
But ogr.Layer and ogr.Geometry objects are destroyed when
their owning ogr.Datastore or ogr.Feature is destroyed.
Freestanding ogr.Geometry objects are ok. There is no such
thing as a freestanding ogr.Layer.
This is a common gotcha.
Best regards,
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>