wkx-ts
npm install wkx-ts
wkx-ts is a typescript version of the wkx library.
A WKT/WKB/EWKT/EWKB/TWKB/GeoJSON parser and serializer with support for
- Point
- LineString
- Polygon
- MultiPoint
- MultiLineString
- MultiPolygon
- GeometryCollection
Examples
The following examples show you how to work with wkx.
import { Geometry, Point } from 'wkx-ts';
var geometry = Geometry.parse('POINT(1 2)');
var geometry = Geometry.parse('SRID=4326;POINT(1 2)');
var geometry = Geometry.parse(wkbBuffer);
var geometry = Geometry.parse(ewkbBuffer);
var geometry = Geometry.parseTwkb(twkbBuffer);
var geometry = Geometry.parseGeoJSON({ type: 'Point', coordinates: [1, 2] });
var wktString = new Point(1, 2).toWkt();
var wkbBuffer = new Point(1, 2).toWkb();
var ewktString = new Point(1, 2, 0, 0, 4326).toEwkt();
var ewkbBuffer = new Point(1, 2, 0, 0, 4326).toEwkb();
var twkbBuffer = new Point(1, 2).toTwkb();
var geoJSONObject = new Point(1, 2).toGeoJSON();
Regardless of which of the preceeding options you choose, using wkx
in the browser will look the same:
import { Geometry } from 'wkx-ts';
const geometry = Geometry.parse('POINT(1 2)');
console.log(geometry.toGeoJSON());
In addition to the wkx-ts
module, you should install the buffer
module to use the Buffer
class in the browser.
npm install buffer
import {Buffer} from 'buffer/index';
import { Geometry } from 'wkx-ts';
const wkbBuffer = new Buffer('0101000000000000000000f03f0000000000000040', 'hex');
const geometry = Geometry.parse(wkbBuffer);
console.log(geometry.toGeoJSON());