1

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

Philipp
  • 143
  • 6

2 Answers2

2

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
ThomasG77
  • 30,725
  • 1
  • 53
  • 93
  • Thanks! That helps a lot. I'll have a look at the output of the overpass-api to see where the different is! – Philipp Nov 16 '16 at 04:58
  • First thing is the fact that it returns JSON instead of XML (more light, more easy to manipulate by third party libraries) as I rely on Overpass API http://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide#Choose_file_format_.28ouput.3Djson.2C_.5Bout:json.5D.29 I don't think it's the cause of your issues as osmtogeojson deal with both JSON and XML OSM data. – ThomasG77 Nov 16 '16 at 05:47
  • I still have one problem and I don't understand why that happens (but does it happen with your approach?). If I extract the OSM-XML for, e.g., San Francisco, I get the following file: https://github.com/pmeisen/public/blob/master/stackoverflow/sanfrancisco.osm . If I now convert it with https://tyrasd.github.io/osmtogeojson/, I get https://github.com/pmeisen/public/blob/master/stackoverflow/sanfrancisco.geo.json. The result contains several additional ways and nodes (see, http://geojson.io/#id=gist:anonymous/9eb2735310eb8be05e6b554c489357f4&map=9/37.5250/-122.7502 (Table)), why is that? – Philipp Nov 18 '16 at 20:49
  • It does not happen with my approach (tested FYI). Your issue IMO is in the how If I extract the OSM-XML for, e.g., San Francisco. As you do not provide it at the moment, it's not possible to answer. – ThomasG77 Nov 19 '16 at 00:44
  • The extraction is pretty simple, look for an id in the XML file (e.g., North America and retrieve all dependent ids. I uploaded the final OSM XML file: https://github.com/pmeisen/public/blob/master/stackoverflow/sanfrancisco.osm – Philipp Nov 20 '16 at 09:21
0

I found the problem. The boundary of the file cuts of some nodes and ways from the OSM file. So that the whole shape is not included in the file. I will try to create a complete shape (did that with smaller things and it worked).

Nevertheless, one thing is still bothering me (and if I figured that out I'll edit this answer). There is a hole in the polygon (bottom right), which is not correctly converted. The conversion includes the hole, but also some polygon, which covers the whole. I'll investigate a little more.

Sorry for the confusion.

Philipp
  • 143
  • 6
  • can you remake your selection from http://overpass-turbo.eu/ ? It exports geojson directly. – scruss Nov 15 '16 at 23:24
  • yes I could do that, but I need to get the whole conversion to be automated (because of the amount). I have to see if overpass-turbo.eu supports such a feature. – Philipp Nov 16 '16 at 00:35