5

I am trying to open a *.osm file in Python with GDAL. But I doesn't work. What am I doing wrong?

import ogr
driver = ogr.GetDriverByName('OSM')
datasource = driver.Open('map.osm')
layer = datasource.GetLayer()

Error looks like this

>>> 

Traceback (most recent call last):
  File ".../osm_reader.py", line 3, in <module>
    datasource = driver.Open('map.osm')
AttributeError: 'NoneType' object has no attribute 'Open'

I exported the data directly from the OSM Website. My Python Version is 2.7.5.

About my GDAL Version I am not sure. And this might be the problem.

Easy Install says

U:\>easy_install GDAL
Searching for GDAL
Best match: GDAL 1.10.1
Adding GDAL 1.10.1 to easy-install.pth file

Using c:\python27\lib\site-packages

GDAL Version says

>>> gdal.VersionInfo()
'1810'

Does 1810 mean GDAL 1.10.1? How do I get this to work?

  • You tried opening it simply with ogr.Open(...) ? – Curlew Oct 21 '13 at 21:22
  • >>> print ogr.Open('map.osm') >>> None. What exactly do you mean? – ustroetz Oct 21 '13 at 21:26
  • Well, it works for me, therefore i conclude that there could be only 2 reasons for your problem. (1) You're pointing to a non-existing path (2) your ogr bindings don't support osm files. – Curlew Oct 21 '13 at 22:23
  • You have seen this posting? gis.stackexchange.com/questions/67371/… – Curlew Oct 21 '13 at 22:23
  • Yeah, I saw the other posting. I do have SQLite and Expat. What do you get for ogr.Open(...)? – ustroetz Oct 21 '13 at 22:28
2
>>> gdal.VersionInfo()
'1810'

This means indeed that the GDAL version Python is using is GDAL 1.8. So I re-installed GDAL for Python with this installation.

After that the GDAL version was up to date (1.10.1).

>>> gdal.VersionInfo()
'1100100'

Though now I got a new error:

>>> print ogr.Open('map.osm')
Warning 1: Cannot find osmconf.ini configuration file
ERROR 1: Could not parse configuration file for OSM import
None

After copying the osmconf.ini into my working directory it finally worked.

>>> print ogr.Open('map.osm')
<osgeo.ogr.DataSource; proxy of <Swig Object of type 'OGRDataSourceShadow *' at
0x02275518> >

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.