Ok I understand Thanks it work perfectly Ludovic
Le 05/08/2010 09:36, Francis Markham a écrit :
The driver and datasource are going out of scope. The former can be fixed by using ogr.Open instead of driver.Open The latter can be fixed by returning it from the function. A revised version of your code would look like:# import modules from osgeo import ogr def openShapeLine(shapefile): #Ouverture du shapefile avec ogr datasource = ogr.Open(shapefile) layer = datasource.GetLayer() return (datasource, layer) ds, couche = openShapeLine('/data/axe.shp') print couche.GetName()On 5 August 2010 17:23, Ludovic Granjon <ludovic.gran...@u-bourgogne.fr <mailto:ludovic.gran...@u-bourgogne.fr>> wrote:Hello I'm trying to develop with ogr in python. I'm on ubuntu 10.4 and I use gdal 1.7 When I try to get back a layer object from a function, I have the following message when I do python monscript.py : "Erreur de segmentation" This is my code : ----------------------- # import modules from osgeo import ogr def openShapeLine(shapefile): #Ouverture du shapefile avec ogr driver = ogr.GetDriverByName("ESRI Shapefile") datasource = driver.Open(shapefile) layer = datasource.GetLayer() return (layer) couche = openShapeLine('/data/axe.shp') print couche.GetName() ------------------------ If I do a "print layer.GetName()" inside the openShapeLine function, there's no problem ... Have you any idea ? Thanks all _______________________________________________ gdal-dev mailing list gdal-dev@lists.osgeo.org <mailto:gdal-dev@lists.osgeo.org> http://lists.osgeo.org/mailman/listinfo/gdal-dev
<<attachment: ludovic_granjon.vcf>>
_______________________________________________ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev