Published
Edited
Sep 3, 2019
1 fork
Importers
3 stars
Insert cell
Insert cell
async function kmzToGeoJSON(kmz) {
// prepare the KMZ archive
const zip = await JSZip.loadAsync(kmz);
// find all the files that end with .kml (in case there is other noise like PNGs)
const files = zip.file(/\.kml$/);
const results = {};
for (const file of files) {
// the generated ID of this file
const name = file.name.replace('.kml', '');
// get the raw XML string...
const str = await file.async('string');
// ...and pass it through DOMParser
const kml = new DOMParser().parseFromString(str, 'text/xml');
results[name] = toGeoJSON.kml(kml);
}
return results;
}
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more