placemark / togeojson

convert KML, TCX, and GPX to GeoJSON, without the fuss
https://placemark.github.io/togeojson/
BSD 2-Clause "Simplified" License
409 stars 67 forks source link

Support layered output for KML #57

Closed tmcw closed 2 years ago

tmcw commented 2 years ago

KML supports layers. toGeoJSON ignores then and just gives you all the features in your KML file.

Strawman draft:

output = toGeoJSON.kmlLayered(xmlDocument);
output = [
{
  layer: 'foo',
  geojson: { type: 'FeatureCollection', /* … */ }
},
{
  layer: 'bar',
  geojson: { type: 'FeatureCollection', /* … */ }
}
]
throberto commented 2 years ago

layer name could not be added as collection feature properties?

example:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
         "kmlLayerName": "foo"
       },
      "geometry": {
        "type": "Point",
        "coordinates": [
          83.3203125,
          -27.371767300523032
        ]
      }
    }
  ]
}
tmcw commented 2 years ago

Unfortunately I don't think that would be sufficient - layers have metadata of their own - name, description, etc. They can also be nested, and the order of features in and amongst folders might be important.

5.x, which is now in master, implements a nested tree structure that adds folder support.

tmcw commented 2 years ago

This is released as a major version in 5.0.0, with a nested folder structure!