[gdal-dev] python bindings: strange behavior with layer

Francis Markham fmarkham at gmail.com
Tue Jul 20 19:30:29 EDT 2010


Is there an FAQ somewhere we can put this?  It bit me when I was
starting with GDAL and Python too.

Cheers,

Francis

On 21 July 2010 04:00, Howard Butler <hobu.inc at gmail.com> wrote:
>
> On Jul 20, 2010, at 12:51 PM, Python Gis wrote:
>
>> Hi
>> this is my code:
>>
>> from osgeo import ogr
>>
>> def OpenLayer(shape_path, shape_name):
>>    drv_shp = ogr.GetDriverByName('ESRI Shapefile')
>>    shp_ds = drv_shp.Open(shape_path, 1)
>>    layer = shp_ds.GetLayerByName(shape_name)
>>    print 'Name from method: %s' % layer.GetName()
>>    return layer;
>>
>> layer = OpenLayer('output', 'myshapefile')
>> print 'Name from main: %s' % layer.GetName()
>>
>> and this is the output:
>>
>> $ python testogr.py
>> Name from method: firenews
>> Segmentation fault
>>
>> what can it be?
>> thanks a lot
>>
>
> drv_shp and shp_ds are going out of scope.  Use ogr.Open, which will take care of all of this for you.
>
> Howard_______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>


More information about the gdal-dev mailing list