makinacorpus/togeojson

Name: togeojson

Owner: Makina Corpus

Description: convert KML and GPX to GeoJSON, without the fuss

Created: 2013-04-03 08:25:40.0

Updated: 2017-12-03 16:26:42.0

Pushed: 2013-04-03 08:27:37.0

Homepage: http://macwright.org/togeojson/

Size: 218

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Convert things to GeoJSON.

Build Status

This converts KML into GeoJSON, in a browser or with nodejs.

It is

It is not

Using it as a console utility

Install it into your path with npm install -g togeojson.

ogeojson file.kml > file.geojson
Using it as a nodejs library

Install it into your project with npm install --save togeojson.

sing togeojson in nodejs

tj = require('togeojson'),
fs = require('fs'),
// node doesn't have xml parsing or a dom. use jsdom
jsdom = require('jsdom').jsdom;

kml = jsdom(fs.readFileSync('foo.kml', 'utf8'));

converted = tj.kml(kml);

converted_with_styles = tj.kml(kml, { styles: true });
Using it as a browser library

Download it into your project like

wget https://raw.github.com/tmcw/togeojson/gh-pages/togeojson.js
ipt src='jquery.js'></script>
ipt src='togeojson.js'></script>
ipt>
ax('test/data/linestring.kml').done(function(xml) {
console.log(toGeoJSON.kml(xml));

ript>

toGeoJSON doesn't include AJAX - you can use jQuery, reqwest, d3, or anything else that can request an XML document.

KML

Supported:

Not supported yet:

FAQ
What is hashing?

KML's style system isn't semantic: a typical document made through official tools (read Google) has hundreds of identical styles. So, togeojson does its best to make this into something usable, by taking a quick hash of each style and exposing styleUrl and styleHash to users. This lets you work backwards from the awful representation and build your own styles or derive data based on the classes chosen.

Implied here is that this does not try to represent all data contained in KML styles.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.