I am trying to use the python script ogr2osm to convert .shp files to .osm files to use with JOSM, by following the script at http://wiki.openstreetmap.org/wiki/Ogr2osm

When I try and run it, I get the error: "ImportError: No module named ogr". I think it is due to not having the python-gdal bindings or osgeo/ogr python bindings installed but nowhere can I find a step by step explanation of how to do this correctly on a Windows 7 machine. I have installed the OSGeo4W shell using the download link given on the wiki page.

I have not used python before but am familiar with other languages and the use of the Command Prompt in Windows.

asked 19 Nov '11, 02:15

srbrook's gravatar image

srbrook
99351225
accept rate: 13%

1

My mistake was not realising the OSGeo4W icon that had been installed on my desktop was a Command Prompt window with all the right linkages set up and that I should use that instead of the Windows Command Prompt. Thankyou - I now have a .osm file that loads into JOSM and looks right.

(20 Nov '11, 00:40) srbrook

Please be aware that if you plan to import anything from an external source into OSM, you must discuss your plans with the local community and/or on the "imports" mailing list. Imports are not universally welcomed in OSM and your data might be deleted if it is considered to be a "rogue import".

(20 Nov '11, 16:49) Frederik Ramm ♦

Having set up gdal with python bindings on Windows in the past, I can confidently say that it is easier to set up a VM with VirtualBox running ubuntu and install gdal on it.

If you do want to go the Windows route, you need to run it through the OSGeo4W shell which should get the paths right. You may also need to execute a file that I believe is called gdal17.bat to get the correct version loaded.

When I reinstalled Windows I did not reinstall OSGeo4W and I now run all gdal-related stuff on my server.

permanent link

answered 19 Nov '11, 21:57

pnorman's gravatar image

pnorman
2.4k52140
accept rate: 19%

You're almost certainly correct that the import error is because Python can't find the python-gdal bindings.

What I would do is download prebuilt GDAL binaries from: http://www.gisinternals.com/sdk/

That page offers binaries from a variety of compilers. You should choose the compiler that was used to build your copy of Python. You can see what compiler your Python was built with by opening the Python command line -- it's part of the version info that is spat out at startup.

Once you've got the correct GDAL binaries, you'll need to let Python know where they are. You can do this by adding (or updating) PYTHONPATH in your Windows environment variables. You'll want to set it to <your_gdal_install>\bin\gdal\python

Note that I haven't actually used GDAL from Python before, so take my instructions with a grain of salt.

permanent link

answered 19 Nov '11, 22:04

DanHomerick's gravatar image

DanHomerick
1561311
accept rate: 33%

edited 19 Nov '11, 22:06

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×43
×5
×1

question asked: 19 Nov '11, 02:15

question was seen: 4,926 times

last updated: 22 Nov '11, 16:42

powered by OSQA