This package lets you:
- Parse WKT (Well-known text) into GeoJSON
- Stringify GeoJSON into WKT
npm install wkt
Turn Well-known text string into GeoJSON
const wkt = require('wkt');
const { parse } = require('wkt');
// See return values in output section
wkt.parse('POINT(1 2)');
parse("POINT Z (58.51466818909509 8.629797415591964 61.77237)");
parse("LINESTRING (30 10, 10 30, 40 40)");
parse("POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))");
{ type: 'Point', coordinates: [ 1, 2 ] }
{ type: 'Point', coordinates: [ 58.51466818909509, 8.629797415591964, 61.77237 ] }
{ type: 'LineString', coordinates: [ [ 30, 10 ], [ 10, 30 ], [ 40, 40 ] ] }
{ type: 'Polygon', coordinates: [[[30,10], [40,40], [20,40], [10,20], [30,10]]] }
Turn GeoJSON geometry
object or Feature object into WKT (Well-known text)
const { stringify } = require('wkt');
const geometry = {
type: "Point",
coordinates: [125.6, 10.1, 54.2]
};
const geometry2 = {
type: 'LineString',
coordinates: [ [ 30, 10 ], [ 10, 30 ], [ 40, 40 ] ]
};
// See return values in output section
stringify(geometry);
stringify(geometry2);
"POINT Z (125.6 10.1 54.2)"
"LINESTRING (30 10, 10 30, 40 40)"
Parse Well-known text string into GeoJSON
Stringifies a GeoJSON geometry
object or Feature object into a WKT (Well-known text) string.
Throws an error if given a FeatureCollection
or unknown input.
- Point + MultiPoint
- LineString + MultiLineString
- Polygon + MultiPolygon
- GeometryCollection
- WKT's containing "Z"