wkt-to-gml
v0.0.2
Published
A lightweight TypeScript library for converting **Well-Known Text (WKT)** to **Geography Markup Language (GML)**. Supports all standard geometry types with customizable output.
Readme
wkt-to-gml 📍➡️🗺️
A lightweight TypeScript library for converting Well-Known Text (WKT) to Geography Markup Language (GML). Supports all standard geometry types with customizable output.
Features
✅ Supports all standard WKT geometries:
Point,LineString,PolygonMultiPoint,MultiLineString,MultiPolygonGeometryCollection
✅ Customizable GML output:
- Choose your GML namespace (default:
3.2). - Toggle pretty-printing and XML declaration.
✅ TypeScript & JavaScript: Fully typed for seamless integration.
Installation
npm install wkt-to-gmlor
yarn add wkt-to-gmlor
pnpm add wkt-to-gmlUsage
Basic Conversion
import { wktToGml } from 'wkt-to-gml';
const gml = wktToGml('POINT(30 10)');
console.log(gml);Output:
<gml:Point xmlns:gml="http://www.opengis.net/gml/3.2">
<gml:pos>30 10</gml:pos>
</gml:Point>Advanced Options
const gml = wktToGml('LINESTRING(10 20, 30 40)', {
gmlNamespace: 'http://www.opengis.net/gml/3.3', // Custom namespace
prettyPrint: false, // Minified output
headlessXml: true, // Omit <?xml?>
});Output:
<gml:LineString xmlns:gml="http://www.opengis.net/gml/3.3"><gml:posList>10 20 30 40</gml:posList></gml:LineString>API
wktToGml(wktString: string, options?: WktToGmlOptions): string
Options
| Key | Type | Default | Description |
|-----------------|-----------|----------------------------------|-------------|
| gmlNamespace | string | "http://www.opengis.net/gml/3.2" | Custom GML namespace URI. |
| prettyPrint | boolean | true | Pretty-print XML with indentation. |
| headlessXml | boolean | true | Omit <?xml version="1.0"?>. |
Examples
1. Convert a Polygon
wktToGml('POLYGON((30 10, 40 40, 20 40, 10 20, 30 10))');Output:
<gml:Polygon xmlns:gml="http://www.opengis.net/gml/3.2">
<gml:exterior>
<gml:LinearRing>
<gml:posList>30 10 40 40 20 40 10 20 30 10</gml:posList>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>2. Convert a MultiLineString (Minified)
wktToGml('MULTILINESTRING((10 10, 20 20), (30 30, 40 40))', { prettyPrint: false });Output:
<gml:MultiLineString xmlns:gml="http://www.opengis.net/gml/3.2"><gml:lineStringMember><gml:LineString><gml:posList>10 10 20 20</gml:posList></gml:LineString></gml:lineStringMember><gml:lineStringMember><gml:LineString><gml:posList>30 30 40 40</gml:posList></gml:LineString></gml:lineStringMember></gml:MultiLineString>Contributing
PRs welcome! Run tests with:
npm testLicense
MIT © Bartłomiej Strama 2025
