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

Python Gis pygis2010 at yahoo.com
Thu Jul 22 07:22:43 EDT 2010


Thanks Luke
this is exactly the approach I have used, solving the issue
To me looks strange that a layer can't exist without the datasource in the 
scope, with other GIS API is not so.
But anyway, good to know
best regards



----- Original Message ----
From: "Pinner, Luke" <Luke.Pinner at environment.gov.au>
To: Python Gis <pygis2010 at yahoo.com>
Cc: gdal-dev at lists.osgeo.org
Sent: Thu, July 22, 2010 1:21:23 AM
Subject: RE: [gdal-dev] python bindings: strange behavior with layer

The datasource "ds" is still going out of scope as it is local to your
"getLayer2" function.
Lots of ways to avoid this. Try not wrapping it up in a function, or
return a tuple of datasource and layer e.g.

def getDSandLayer(shape_fullname):
    ds = ogr.Open(shape_fullname, 0)
    layer = ds.GetLayer(0)
    print 'Name from method: %s' % layer.GetName()
    return ds,layer;

ds,layer = getLayer2('output/myshape.shp')
print 'Name from main: %s' % layer.GetName()

Luke


------
If you have received this transmission in error please notify us immediately by 
return e-mail and delete all copies. If this e-mail or any attachments have been 
sent to you in error, that error does not constitute waiver of any 
confidentiality, privilege or copyright in respect of information in the e-mail 
or attachments. 




Please consider the environment before printing this email.

------


      


More information about the gdal-dev mailing list