Thanks Frank, excellent tip to be aware of. It's working great now. -marius
On Wed, 2011-07-13 at 22:19 -0700, Frank Warmerdam wrote: > On Wed, Jul 13, 2011 at 4:23 PM, Marius Jigmond > <[email protected]> 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,
_______________________________________________ gdal-dev mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/gdal-dev
