[GIS] Convert OSM XML to GeoJson correctly

geojsonopenstreetmap

I know there are several post already on how to convert OSM to GeoJson, e.g., How do you convert OSM XML to geojson?.

Nevertheless, I tried the mentioned tools, but I always end up with the same problem. Whenever I load the converted GeoJson (http://tyrasd.github.io/osmtogeojson/) or load the OSM data directly (using geojson.io -> Open), I receive an invalid shape:

http://bl.ocks.org/d/5fc3e8038fa1101cdcd51ad3d0404b47

With http://geojsonlint.com/ I receive different errors using the result of the conversion (e.g., the first and last positions in a LinearRing of coordinates must be the same or Polygons and MultiPolygons should follow the right-hand rule). Is there any setting, tool, that may solve these problems? Or generate a valid result? Are there any tips for the OSM data, that I may apply (e.g., remove specific features, nodes, …). The source data is shown correctly in OSM, see http://www.openstreetmap.org/relation/62780.

The complete OSM file used for conversion can be found here on my GitHub:
nuernberg.osm

Best Answer

I clearly don't know where your issue is.

It's working exactly like the http://www.openstreetmap.org/relation/62780 if you use osmtogeojson. You can see a sample in action and there are no broken elements. I make a call using the Overpass API (encoded url) and then do the conversion.

If you need a "one-shot" conversion without depending on third party later e.g Overpass API, just use query-overpass (need to have Node.js installed) and do:

# To install
npm install -g query-overpass
# Put the OverPass query and transform to GeoJSON using the command line 'query-overpass'
echo '[out:json][timeout:25];(relation(62780););out body;>;out skel qt;' | query-overpass --flat-properties > osm-relation-id-62780.geojson