I have file : test.kml and I try to open it with GDAL/OGR (1.6) librairie in Python (2.5).
But I don't succed can you help me ?
This is my code :
from osgeo import ogr adresse = 'test.kml' driver = ogr.GetDriverByName('KML') datasource = driver.Open(adresse) layer = datasource.GetLayer() layerDefn = layer.GetLayerDefn() featDefn = layer.GetLayerDefn() feat = ogr.Feature(featDefn) nbFeat = layer.GetFeatureCount() print nbFeat
ERROR Traceback (most recent call last): File "C:\Documents and Settings\Guilhain\Mes documents\My Dropbox\dev\test.py", line 6, in layer = datasource.GetLayer() AttributeError: 'NoneType' object has no attribute 'GetLayer'
The error you encountered shows that your value for "datasource" is not valid. Instead of using "adresse = 'test.kml'", try entering the full path to the xml file. For example "C:\myfiles\test.kml".
Try adding this to your code to hopefully find out what might be going on with the datasource not being created:
You must provide a name argument to the GetLayer() call, such as datasource.GetLayer("foo"). or use GetLayerByIndex(layer_number_starting_with_0)