Convert OSM XML to GeoJSON – How to Convert in Leaflet or Polymaps

geojsonleafletopenstreetmappolymapsxml

I want to take the XML output of a Xapi query and display it using leaflet or polymaps. How can I do that? Is there an easy way to convert XML to geojson

Best Answer

You can convert OSM XML to GeoJson with ogr2ogr. To convert to GeoJSON without getting the following error:

ERROR 6: GeoJSON driver doesn't support creating more than one layer

You can use one of the following commands or all of them:

ogr2ogr -f GeoJSON points.json data.osm.pbf points
ogr2ogr -f GeoJSON lines.json data.osm.pbf lines
ogr2ogr -f GeoJSON multilinestrings.json data.osm.pbf multilinestrings
ogr2ogr -f GeoJSON multipolygons.json data.osm.pbf multipolygons
ogr2ogr -f GeoJSON other_relations.json data.osm.pbf other_relations