Converter: .osm(.bz2) <=> python <=> josm, mongo, etc

here’s my tool to parse and render .OSM(.bz2) files.

1. Parses OSM files
It’s not well documented, but the usage is simple:

from osm2py.osm2py import parse_file
parse_file(input_stream, element_callback)

input_stream is a file-like object with osm xml data (can be a file, a bz2 file, an HTTP stream, etc)
element_callback is your callback function that will receive the dictionary with element (node, way, relation, bound if you like) and do something with it.

For example, in the package, is a wrapper that has a callback that dumps json data into a file. saves the elements into MongoDB collections.

2. Renders OSM files
It requires Django 1.3 installed on the python path. can

  • render a data into string (.render(), .dumps())
  • stream a rendered template into a file-like object (.dump())
  • compose a dummy way of input nodes (to draw a route way for example)

The data must be like what you get from osm2py.parse_file.

I’m working on a routing in python. For now it’s just bidirectional A*, I want to extend it to ALT+Reach. It works on pre-processed graphs and the results are much better than those of pyroute. If anyone’s interested, contact me please.

Very interesting, thanks for sharing! I’d be interested to know why you’re creating a new router rather than improving pyroute, or even just using/improving pgRouting. I’m trying to understand the routers available for OSM data, and am having difficulty understanding the advantages and disadvantages of all the routers out there. There is a table on the wiki comparing some of them, however it’s not as comprehensive as I’d like. I’m keeping on eye on pgRouting, especially now that there’s a GSOC project to add multi-modal routing. Getting your take on the drawbacks of existing solutions would be helpful.