[gdal-dev] Error with using GML with Python

Pekka Sarkola pekka.sarkola at gispo.fi
Sun Nov 9 09:28:13 PST 2014


Hi,

I might have newbie problem with OGR’s GML driver in Python.

I try to read GML files with Python script, but won’t get access to
features. I tried this on Window (ogr version 1.11.1), unfortunately I
couldn’t check this in other enviroments, yet.

So my sample testing script result is
---
Loop aita layer...              
 Count of features: 181         
None                            
None                            
Start Loop...                   
End of Loop                     
---

And sample script is very simple:
--- 
#!/usr/bin/python

# -- Start of test script ---
import sys;
from osgeo import ogr;

driver = ogr.GetDriverByName('GML');

if driver is None:
  print "Error with driver"
  sys.exit(1)

fn = '<your path>/L4131R.xml'
#fn = '/data/nlsfi/MTK-GML/L34131R.xml'
datasrc=driver.Open(fn,0);

if datasrc is None:
  print "Error opening " + fn;
  sys.exit(1);

print "Loop aita layer..."

myLayer=datasrc.GetLayer("Aita")
print " Count of features: "+str(myLayer.GetFeatureCount())

print myLayer.GetNextFeature();

print myLayer.GetFeature(2);

print "Start Loop..."
for feat in myLayer:
  print "a"
  
print "End of Loop"

# -- End of test script ---
---

GML file is National Land Survey of Finland's special GML. I can access with
ogrinfo and other command line tools, but not from Python (version 2.7.3).
You can download sample datasets from Kapsi, example
http://kartat.kapsi.fi/files/maastotietokanta/kaikki/etrs89/gml/L4/L41/

Any help is appreciated. I try to check this also in Ubuntu, but currently I
don't have working environment for GDAL 1.11.1. So if somebody can test this
on Ubuntu 14.04 (or any other version above 12.04)

Rgs,

Pekka

--
Pekka Sarkola
Gispo Oy
pekka.sarkola at gispo.fi   - GSM +358 40 725 2042
www.gispo.fi – www.paikkatieto.com 




More information about the gdal-dev mailing list