[gdal-dev] Issue with python bindings.
Vincent Schut
schut at sarvision.nl
Wed Oct 27 04:12:44 EDT 2010
Ivan,
in my experience it is often enough to keep a ref to the dataset to
avoid these segfaults. However, my experience is more with gdal (raster)
than with ogr (vector), so ymmv, and some experimenting might be
required. Just start with keeping a ds reference, if that doesn't work,
go further up the chain and also keep a ref to the layer, and so on.
Vincent Schut.
On 10/26/2010 04:54 PM, Ivan Willig wrote:
> Thanks Frank. That seems to be the issue. Whats the rule about this
> how long you should keep a reference. For example this causes the same
> issue.
>
> ds.GetLayer().GetFeature(0).GetGeometryRef().GetEnvelope()
>
> Which I am going to guess is because I should keep a reference to the
> geometry. Correct?
>
> Ivan Willig
>
>
>
>
> On Tue, Oct 26, 2010 at 10:44 AM, Frank Warmerdam <warmerdam at pobox.com
> <mailto:warmerdam at pobox.com>> wrote:
>
> Ivan Willig wrote:
>
> Hi list,
> I am having an issues with using the python swig based
> bindings. I am on Fedora 13 using the default gdal rpm, which
> is at version 1.6.2. My issue is when i stack method calls.
> For example when I do the following:
> ogr.Open("/home/ivan/dev/bigapps/data/nyco.shp").GetLayer().GetFeature(0)
>
>
> I get a Segmentation fault. Here are the results of strace
> http://paste.pocoo.org/show/281682/. What am I doing wrong?
> Should I just hand compile a new version of gdal? Or is this
> not an advised usage of the python bindings? A limitation in
> swig? Thanks for your help.
>
>
> Ivan,
>
> I believe the problem is object lifetimes. Keep a reference to the
> datasource around until you are done with the feature(s).
>
> ds = ogr.Open("/home/ivan/dev/bigapps/data/nyco.shp")
> feat = ds.GetLayer().GetFeature(0)
> ...
> feat = None
> ds = None
>
> Best regards,
> --
> ---------------------------------------+--------------------------------------
> I set the clouds in motion - turn up | Frank Warmerdam,
> warmerdam at pobox.com <mailto:warmerdam at pobox.com>
> light and sound - activate the windows |
> http://pobox.com/~warmerdam <http://pobox.com/%7Ewarmerdam>
> and watch the world go round - Rush | Geospatial Programmer for
> Rent
>
>
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20101027/9390fded/attachment-0001.html
More information about the gdal-dev
mailing list