tyrasd / osmtogeojson

convert osm to geojson
http://tyrasd.github.io/osmtogeojson/
MIT License
683 stars 112 forks source link

Broken geometry produced from references to objects without coordinates #142

Open jleedev opened 9 months ago

jleedev commented 9 months ago

I discovered this through using out center, which produces object without coordinates but also produces separate Feature items from the center point; I think this is a red herring and this is only caused by the missing coordinates but I mention it for completeness. (Difficult to make a nice reproduction.)

(As a workaround, I can, of course, remember to instead use out center tags; in my overpass queries.)

1: A way that has references to nodes which lack coordinates: way(387635995);out;node(w);out ids;

Input:

{ "elements": [
{ "type": "way", "id": 1, "nodes": [2, 3] },
{ "type": "node", "id": 2 },
{ "type": "node", "id": 3 }
] }

Output:

{"type":"FeatureCollection","features":[
{"type":"Feature","id":"way/1","properties":{"id":"way/1"},
"geometry":{"type":"LineString","coordinates":[[null,null],[null,null]]}}
]}

2: A relation that has references to ways which lack coordinates: rel(544634);out;way(r);out;

Input:

{ "elements": [

{ "type": "relation", "id": 1,
"members": [ {"type":"way","ref":2},{"type":"way","ref":3 } ],
"tags": {"type":"route"} },

{ "type": "way", "id": 2, "nodes": [4, 5] },
{ "type": "way", "id": 3, "nodes": [6, 7] }
] }

Output:

{"type":"FeatureCollection","features":[
{"type":"Feature","id":"relation/1",
"properties":{"type":"route","id":"relation/1"},
"geometry":{"type":"MultiLineString","coordinates":[[],[]]}}
]}

I believe in both of these cases the geometry should either be tainted (if some geometry is present) or null (if no geometry is present), in which case I believe the library will simply discard the feature; it's valid GeoJSON to have a null geometry but I don't think this library does that.