Created
March 29, 2014 15:26
-
-
Save akre54/9856494 to your computer and use it in GitHub Desktop.
KML to GeoJSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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