{"id":13555982,"url":"https://github.com/mapbox/togeojson","last_synced_at":"2025-05-14T11:11:16.539Z","repository":{"id":5847317,"uuid":"7063835","full_name":"mapbox/togeojson","owner":"mapbox","description":"convert KML and GPX to GeoJSON, without the fuss","archived":false,"fork":false,"pushed_at":"2024-04-09T17:19:02.000Z","size":5367,"stargazers_count":1286,"open_issues_count":30,"forks_count":329,"subscribers_count":161,"default_branch":"master","last_synced_at":"2025-05-04T10:41:18.212Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://mapbox.github.io/togeojson/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mapbox.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-12-08T04:17:57.000Z","updated_at":"2025-04-25T16:52:41.000Z","dependencies_parsed_at":"2024-06-18T12:17:56.274Z","dependency_job_id":"6683f51a-b081-4dd7-89c2-f17ea4cbf2f2","html_url":"https://github.com/mapbox/togeojson","commit_stats":{"total_commits":219,"total_committers":35,"mean_commits":6.257142857142857,"dds":"0.36073059360730597","last_synced_commit":"4c46c477bdf3b938eb12503573394a7f285ee004"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mapbox%2Ftogeojson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mapbox%2Ftogeojson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mapbox%2Ftogeojson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mapbox%2Ftogeojson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mapbox","download_url":"https://codeload.github.com/mapbox/togeojson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254129511,"owners_count":22019628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T12:03:32.714Z","updated_at":"2025-05-14T11:11:11.478Z","avatar_url":"https://github.com/mapbox.png","language":"JavaScript","readme":"[![Build status](https://img.shields.io/travis/mapbox/togeojson.svg \"Build status\")](http://travis-ci.org/mapbox/togeojson)\n[![Coverage status](https://img.shields.io/coveralls/mapbox/togeojson.svg \"Coverage status\")](https://coveralls.io/r/mapbox/togeojson)\n[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmapbox%2Ftogeojson.svg?type=shield)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmapbox%2Ftogeojson?ref=badge_shield)\n\n# Convert KML and GPX to GeoJSON.\n\nThis converts [KML](https://developers.google.com/kml/documentation/) \u0026 [GPX](http://www.topografix.com/gpx.asp)\nto [GeoJSON](http://www.geojson.org/), in a browser or with [Node.js](http://nodejs.org/).\n\n* [x] Tiny\n* [x] Tested\n* [x] Node.js + Browsers\n\nWant to use this with [Leaflet](http://leafletjs.com/)? Try [leaflet-omnivore](https://github.com/mapbox/leaflet-omnivore)!\n\n## API\n\n### `toGeoJSON.kml(doc)`\n\nConvert a KML document to GeoJSON. The first argument, `doc`, must be a KML\ndocument as an XML DOM - not as a string. You can get this using jQuery's default\n`.ajax` function or using a bare XMLHttpRequest with the `.response` property\nholding an XML DOM.\n\nThe output is a JavaScript object of GeoJSON data. You can convert it to a string\nwith [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)\nor use it directly in libraries like [mapbox.js](http://www.mapbox.com/mapbox.js/).\n\n### `toGeoJSON.gpx(doc)`\n\nConvert a GPX document to GeoJSON. The first argument, `doc`, must be a GPX\ndocument as an XML DOM - not as a string. You can get this using jQuery's default\n`.ajax` function or using a bare XMLHttpRequest with the `.response` property\nholding an XML DOM.\n\nThe output is a JavaScript object of GeoJSON data, same as `.kml` outputs.\n\n## CLI\n\nInstall it into your path with `npm install -g @mapbox/togeojson`.\n\n```\n~\u003e togeojson file.kml \u003e file.geojson\n```\n\n## Node.js\n\nInstall it into your project with `npm install --save @mapbox/togeojson`.\n\n```javascript\n// using togeojson in nodejs\n\nvar tj = require('@mapbox/togeojson'),\n    fs = require('fs'),\n    // node doesn't have xml parsing or a dom. use xmldom\n    DOMParser = require('xmldom').DOMParser;\n\nvar kml = new DOMParser().parseFromString(fs.readFileSync('foo.kml', 'utf8'));\n\nvar converted = tj.kml(kml);\n\nvar convertedWithStyles = tj.kml(kml, { styles: true });\n```\n\n## Browser\n\nDownload it into your project like\n\n    wget https://raw.githubusercontent.com/mapbox/togeojson/master/togeojson.js\n\n```html\n\u003cscript src='jquery.js'\u003e\u003c/script\u003e\n\u003cscript src='togeojson.js'\u003e\u003c/script\u003e\n\u003cscript\u003e\n$.ajax('test/data/linestring.kml').done(function(xml) {\n    console.log(toGeoJSON.kml(xml));\n});\n\u003c/script\u003e\n```\n\ntoGeoJSON doesn't include AJAX - you can use [jQuery](http://jquery.com/) for\njust AJAX.\n\n### KML Feature Support\n\n* [x] Point\n* [x] Polygon\n* [x] LineString\n* [x] name \u0026 description\n* [x] ExtendedData\n* [x] SimpleData\n* [x] MultiGeometry -\u003e GeometryCollection\n* [x] Styles with hashing\n* [x] Tracks \u0026 MultiTracks with `gx:coords`, including altitude\n* [x] [TimeSpan](https://developers.google.com/kml/documentation/kmlreference#timespan)\n* [x] [TimeStamp](https://developers.google.com/kml/documentation/kmlreference#timestamp)\n* [ ] NetworkLinks\n* [ ] GroundOverlays\n\n### GPX Feature Support\n\n* [x] Line Paths\n* [x] Line styles\n* [ ] Properties\n  * [x] 'name', 'cmt', 'desc', 'link', 'time', 'keywords', 'sym', 'type' tags\n  * [ ] 'author', 'copyright' tags\n\n## FAQ\n\n### What is hashing?\n\nKML's style system isn't semantic: a typical document made through official tools\n(read Google) has hundreds of identical styles. So, togeojson does its best to\nmake this into something usable, by taking a quick hash of each style and exposing\n`styleUrl` and `styleHash` to users. This lets you work backwards from the awful\nrepresentation and build your own styles or derive data based on the classes\nchosen.\n\nImplied here is that this does not try to represent all data contained in KML\nstyles.\n\n### Why doesn't toGeoJSON support NetworkLinks?\n\nThe NetworkLink KML construct allows KML files to refer to other online\nor local KML files for their content. It's often used to let people pass around\nfiles but keep the actual content on servers.\n\nIn order to support NetworkLinks, toGeoJSON would need to be asynchronous\nand perform network requests. These changes would make it more complex and less\nreliable in order to hit a limited usecase - we'd rather keep it simple\nand not require users to think about network connectivity and bandwidth\nin order to convert files.\n\nNetworkLink support could be implemented in a separate library as a pre-processing\nstep if desired.\n\n### Should toGeoJSON support feature X from KML?\n\nThis module should support converting all KML and GPX features that have commonplace\nequivalents in GeoJSON.\n\nKML is a very complex format with many features. Some of these features, like NetworkLinks,\nfolders, and GroundOverlays, don't have a GeoJSON equivalent. In these cases,\ntoGeoJSON doesn't convert the features. It also doesn't crash on these constructs:\ntoGeoJSON should be able to run on all valid KML and GPX files without crashing:\nbut for some files it may have no output.\n\nWe encourage other libraries to look into supporting these features, but\nsupport for them is out of scope for toGeoJSON.\n\n## Protips:\n\nHave a string of XML and need an XML DOM?\n\n```js\nvar dom = (new DOMParser()).parseFromString(xmlStr, 'text/xml');\n```\n\n## License\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmapbox%2Ftogeojson.svg?type=large)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmapbox%2Ftogeojson?ref=badge_large)\n","funding_links":[],"categories":["JavaScript","others"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmapbox%2Ftogeojson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmapbox%2Ftogeojson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmapbox%2Ftogeojson/lists"}