tyrasd / osmtogeojson

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

Missing element when converting JSON from OSM that have mixed type #62

Closed adhikasp closed 7 years ago

adhikasp commented 7 years ago

I got missing element when trying to convert data with mixed element type (node and way).

Overpass Query

[out:json];
(
  node(1308624679);
  way(326101499);
  way(355858242); 
);
out meta;

JSON response.

Note there are 3 elements in this.

{
  "version": 0.6,
  "generator": "Overpass API",
  "osm3s": {
    "timestamp_osm_base": "2016-12-15T03:52:03Z",
    "copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL."
  },
  "elements": [

{
  "type": "node",
  "id": 1308624679,
  "lat": -1.3813338,
  "lon": 116.0926515,
  "timestamp": "2011-06-02T07:17:38Z",
  "version": 1,
  "changeset": 8316688,
  "user": "jeffhaack",
  "uid": 81521,
  "tags": {
    "is_in:country": "Indonesia",
    "is_in:county": "Long Kali",
    "is_in:region": "Pasir",
    "is_in:state": "Kalimantan Timur",
    "name": "Pinang Jatus",
    "place": "village"
  }
},
{
  "type": "way",
  "id": 326101499,
  "timestamp": "2015-09-06T01:26:45Z",
  "version": 4,
  "changeset": 33824211,
  "user": "Ezagren",
  "uid": 1801604,
  "nodes": [
    3327186888,
    3327186889,
    3327186890,
    3327186891,
    3327186999,
    3327187000,
    3327186888
  ],
  "tags": {
    "addr:full": "Jl. Wahid Hasyim No.28 Samarinda Utara Kota Samarinda, Kalimantan Timur 75119",
    "amenity": "university",
    "building": "yes",
    "building:levels": "3",
    "capacity:persons": "2000",
    "name": "Universitas Widya Gama Mahakam",
    "name:en": "Widya Gama Mahakam University",
    "operator:type": "private",
    "url": "https://plus.google.com/101501859592675238163/about?gl=id&hl=id",
    "website": "http://uwgm-smr.ac.id/"
  }
},
{
  "type": "way",
  "id": 355858242,
  "timestamp": "2015-09-06T03:10:38Z",
  "version": 3,
  "changeset": 33824793,
  "user": "Ezagren",
  "uid": 1801604,
  "nodes": [
    3614070060,
    3614070056,
    3614070044,
    3614070027,
    3614070025,
    3614070043,
    3614070058,
    3614070061,
    3614070063,
    3614070059,
    3614070062,
    3614070060
  ],
  "tags": {
    "addr:full": "Jl. KH. WAHID HASYIM No. 75",
    "amenity": "school",
    "building": "yes",
    "building:levels": "2",
    "capacity:persons": "300",
    "name": "SMK Negeri 5 Samarinda",
    "operator:type": "goverment",
    "school:type_idn": "SMK",
    "url": "http://www.smkn5samarinda.sch.id/",
    "website": "http://referensi.data.kemdikbud.go.id/tabs.php?npsn=30401071"
  }
}

  ]
}

Converting to GeoJSON

Only the first element from JSON data got converted.

{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "id": "node/1308624679",
            "properties": {
                "type": "node",
                "id": 1308624679,
                "tags": {
                    "is_in:country": "Indonesia",
                    "is_in:county": "Long Kali",
                    "is_in:region": "Pasir",
                    "is_in:state": "Kalimantan Timur",
                    "name": "Pinang Jatus",
                    "place": "village"
                },
                "relations": [],
                "meta": {
                    "timestamp": "2011-06-02T07:17:38Z",
                    "version": 1,
                    "changeset": 8316688,
                    "user": "jeffhaack",
                    "uid": 81521
                }
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    116.0926515,
                    -1.3813338
                ]
            }
        }
    ]
}
tyrasd commented 7 years ago

Hi Adhika. Thanks for the report. But this is in fact the expected behaviour for the OSM to GeoJSON conversion. Look at the two ways you requested: They reference other nodes ("nodes": [3327186888, 3327186889, …]) which are not present in the JSON data. Those nodes are needed in order to do the conversion, as only nodes contain actual location coordinates in the OSM format.

Try using out meta geom; instead of out meta; in order to obtain the missing coordinate information. Another option is to recurse statement like this: http://overpass-turbo.eu/s/kFA