Skip to content

Instantly share code, notes, and snippets.

@akre54
Created March 29, 2014 15:26
Show Gist options
  • Save akre54/9856494 to your computer and use it in GitHub Desktop.
Save akre54/9856494 to your computer and use it in GitHub Desktop.
KML to GeoJSON
fs = require 'fs'
xml2js = require('xml2js').parseString
fs.readFile "#{__dirname}/history.kml", (err, data) ->
xml2js data, (err, result) ->
doc = result.kml.Document[0].Placemark[0]['gx:Track'][0]
points =
type: "Feature"
properties: {}
geometry:
type: "MultiLineString"
coordinates: [(coord.split(' ').slice(0, 2).map(parseFloat) for coord in doc['gx:coord'])]
fs.writeFile "#{__dirname}/public/points.json", JSON.stringify(points), (err, data) ->
console.log 'Done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment