Search code examples
pythonxmlpython-2.7openstreetmapnetworkx

How to save OSM file in XML using python in the same structure of the exported .osm file from OpenStreetMap website?


I am using python osmnx to deal with OpenStreetMap and I am trying to save a networkx map in an .xml file with the same structure of the exported one from the openstreetmap.org. Is it possible to save the map in same XML structure as downloaded from website?

I am using osmnx for path planning and I am trying to save the map that includes the path in .xml format for further operations using ox.save_graphml(), which saves the map but in a different structure than the exported map for the same area from the OSM website.

ox.save_graphml(subgraph2 , filename='/home/ahmad/catkin_ws/src/osmgraph.xml')

I expect the XML file to have the same structure as the one from the exported .osm file from OpenStreetMap. But the output XML has different structure.


Solution

  • Per the OSMnx documentation, save_graphml saves your graph to disk as a GraphML file. The GraphML file format is unrelated to the OSM XML file format. OSMnx can save your graph to disk as a shapefile or GraphML. It does not support saving to disk as an OSM XML file out of the box.