Greasy Fork is available in English.

GeoKMLer

geoKMLer is a JavaScript library designed to convert KML data into GeoJSON format efficiently. It supports conversion of Placemarks containing Point, LineString, Polygon, and MultiGeometry elements.

이 스크립트는 직접 설치해서 쓰는 게 아닙니다. 다른 스크립트가 메타 명령 // @require https://update.greasyfork.org/scripts/524747/1534527/GeoKMLer.js(으)로 포함하여 쓰는 라이브러리입니다.

질문, 리뷰하거나, 이 스크립트를 신고하세요.
개발자
JS55CT
버전
2.1.0
생성
2025-01-24
갱신
2025-02-09
Size
12.9KB
라이선스
MIT

GeoKMLer

GeoKMLer is a JavaScript library designed to convert KML data into GeoJSON format efficiently. It supports the conversion of various KML geometries and extended data, making it ideal for integrating KML spatial data into web mapping applications.

License

This project is free software licensed under the MIT License. See the LICENSE file for more details.

Overview

GeoKMLer provides a straightforward API to parse KML files and convert them into a GeoJSON FeatureCollection. It is suitable for use in geographic data visualization and web mapping applications.

Features

  • Convert KML to GeoJSON: Supports points, linestrings, polygons, and multigeometries.
  • Handle Extended Data: Converts KML <ExtendedData> elements into GeoJSON properties.
  • Robust XML Handling: Efficient parsing and normalization of XML data.
  • No External Dependencies: Lightweight and easy to integrate into various projects.

Usage

To use GeoKMLer, create an instance of GeoKMLer and use its methods to perform conversions from KML strings to GeoJSON objects.

Example

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);

Key Methods

  • read(kmlText): Parses a KML string into an XML Document using DOMParser.
  • toGeoJSON(document): Converts an XML Document into a GeoJSON FeatureCollection.
  • extractExtendedData(placemark): Extracts extended data from a KML Placemark and includes it as GeoJSON properties.

Acknowledgments

The structure and logic for this project are based on established methods for XML to GeoJSON conversion, leveraging modern JavaScript best practices.

Project Home

https://github.com/YourUsername/GeoKMLer