The <span style="font-family: courier new,monospace;">driver </span>and <span style="font-family: courier new,monospace;">datasource </span>are going out of scope. The former can be fixed by using <span style="font-family: courier new,monospace;">ogr.Open </span>instead of <span style="font-family: courier new,monospace;">driver.Open </span>The latter can be fixed by returning it from the function. A revised version of your code would look like:<br>
<br style="font-family: courier new,monospace;"><blockquote><span style="font-family: courier new,monospace;"># import modules</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
from osgeo import ogr</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
def openShapeLine(shapefile):</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
#Ouverture du shapefile avec ogr</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
datasource = ogr.Open(shapefile)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
layer = datasource.GetLayer()</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
return (datasource, layer)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
ds, couche = openShapeLine('/data/axe.shp')</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
print couche.GetName()</span><br></blockquote>
<br><div class="gmail_quote">On 5 August 2010 17:23, Ludovic Granjon <span dir="ltr"><<a href="mailto:ludovic.granjon@u-bourgogne.fr" target="_blank">ludovic.granjon@u-bourgogne.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hello<br>
<br>
I'm trying to develop with ogr in python. I'm on ubuntu 10.4 and I use gdal 1.7<br>
When I try to get back a layer object from a function, I have the following message when I do python monscript.py :<br>
"Erreur de segmentation"<br>
<br>
This is my code :<br>
<br>
-----------------------<br>
# import modules<br>
from osgeo import ogr<br>
<br>
def openShapeLine(shapefile):<br>
#Ouverture du shapefile avec ogr<br>
driver = ogr.GetDriverByName("ESRI Shapefile")<br>
datasource = driver.Open(shapefile)<br>
layer = datasource.GetLayer()<br>
return (layer)<br>
<br>
couche = openShapeLine('/data/axe.shp')<br>
<br>
print couche.GetName()<br>
------------------------<br>
<br>
If I do a "print layer.GetName()" inside the openShapeLine function, there's no problem ...<br>
<br>
Have you any idea ?<br>
<br>
Thanks all<br>
<br>_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br></blockquote></div><br>