<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Ok I understand<br>
Thanks it work perfectly<br>
<br>
Ludovic<br>
<br>
Le 05/08/2010 09:36, Francis Markham a écrit :
<blockquote
cite="mid:AANLkTik+tUQbVHSAOfFPSkQSXqKnCv36VgvS4uNEkGif@mail.gmail.com"
type="cite">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 moz-do-not-send="true"
href="mailto:ludovic.granjon@u-bourgogne.fr" target="_blank">ludovic.granjon@u-bourgogne.fr</a>></span>
wrote:<br>
<blockquote class="gmail_quote"
style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; 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 moz-do-not-send="true" href="mailto:gdal-dev@lists.osgeo.org"
target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a moz-do-not-send="true"
href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</blockquote>
</div>
<br>
</blockquote>
<br>
</body>
</html>