geoKMZer is a JavaScript library designed to convert KMZ into KML files, use with GeoKMLer to convert to GeoJSON.
This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/527113/1538395/GeoKMZer.js
A JavaScript library comprising two main components: GeoKMLer and GeoKMZer. These tools are designed to facilitate the conversion of KML data into GeoJSON format and handle the extraction of KML data from KMZ archives efficiently.
This project is free software licensed under the MIT License. See the LICENSE file for more details.
GeoKMLer / GeoKMZer provides a comprehensive API to parse, extract, and convert KML/KMZ files into a GeoJSON FeatureCollection. It is suitable for use in geographic data visualization and web mapping applications.
<ExtendedData>
elements into GeoJSON properties.GeoKMLer / GeoKMZer makes it easy to work with both KML files directly and KMZ archives. Here’s how you can use these tools in your application:
var geoKMLer = new GeoKMLer(); // Create a new instance of GeoKMLer
// Sample KML data input
const kmlData = `...KML data string...`;
// Parse the KML data
const xmlDoc = geoKMLer.read(kmlData);
// Convert to GeoJSON
const geoJson = geoKMLer.toGeoJSON(xmlDoc);
console.log(geoJson);
(async () => {
// Assume your KMZ file is loaded and represented as `fileBuffer`
const fileBuffer = ...; // Load your KMZ file here (e.g., from a fetch request or a file input)
try {
// Initialize instances of GeoKMZer and GeoKMLer
const geoKMZer = new GeoKMZer();
const geoKMLer = new GeoKMLer();
// Extract KML contents from the KMZ buffer
const kmlContentsArray = await geoKMZer.read(fileBuffer);
// Process each KML and convert to GeoJSON
kmlContentsArray.forEach(({ filename, content }) => {
console.log(`Processing file: ${filename}`);
// Parse the KML content
const kmlDoc = geoKMLer.read(content);
// Convert the KML document to a GeoJSON object
const geoJson = geoKMLer.toGeoJSON(kmlDoc);
// Output the GeoJSON to the console
console.log(`GeoJSON for ${filename}:`, geoJson);
});
} catch (error) {
console.error("Error processing KMZ file:", error);
}
})();
The structure and logic for this project are based on established methods for XML to GeoJSON conversion, leveraging modern JavaScript best practices.