GeoWKTer

GeoWKTer is a JavaScript library designed to convert Well-Known Text (WKT) representations of geometries into GeoJSON format. This tool is useful for developers and GIS specialists who need to work with geographic data across different standards.

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/523986/1575829/GeoWKTer.js

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

作者
JS55CT
版本
2.3.0
建立日期
2025-01-16
更新日期
2025-04-22
尺寸
23.1 KB
授權條款
MIT

GeoWKTer: WKT to GeoJSON Converter

GeoWKTer is a JavaScript library designed to facilitate the conversion of Well-Known Text (WKT) geometries into GeoJSON format. This library is especially beneficial for developers and GIS specialists working with geographic data across varying standards. By implementing robust methods for parsing and conversion, GeoWKTer ensures seamless transitions between WKT and GeoJSON representations.

Features

  • Support for Various WKT Types: Accurately converts diverse geometry types, including POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, and GEOMETRYCOLLECTION.
  • Streamlined API: Provides a simple and intuitive interface for converting WKT inputs into GeoJSON FeatureCollections.

Usage

Below is a basic example of how to use the GeoWKTer library:

// @require             https://update.greasyfork.org/scripts/523986/1575829/GeoWKTer.js

// Initialize the GeoWKTer instance
let geoWKTer = new GeoWKTer();

// Example WKT input
let wktText = "GEOMETRYCOLLECTION(POINT(4 6), LINESTRING(4 6, 7 10))";

// Convert WKT to GeoJSON
let wktDataArray = geoWKTer.read(wktText, 'Example Label');
let geoJsonData = geoWKTer.toGeoJSON(wktDataArray);

// Output GeoJSON
console.log(JSON.stringify(geoJsonData, null, 2));

API

GeoWKTer

  • read(wktText, label):

    • Description: Parses a WKT string into an array of geometry objects. Assigns a specified label to each parsed geometry.
    • Parameters:
    • wktText (string): The Well-Known Text string representing the geometries.
    • label (string): An optional label to associate with the geometries for identification or classification.
  • toGeoJSON(dataArray):

    • Description: Converts an array of parsed WKT data into a GeoJSON FeatureCollection.
    • Parameters:
    • dataArray (Object[]): The internal data array produced by the read method, ready for transformation into GeoJSON format.

License

GeoWKTer is licensed under the MIT License. For more details, please see the LICENSE file.

Acknowledgments

GeoWKTer is also inspired by the work of Wicket.js and Terraformer.