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 |
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. answered 19 Nov '11, 21:57 pnorman |
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. answered 19 Nov '11, 22:04 DanHomerick |
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.
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".