# wkx

> A WKT/WKB/EWKT/EWKB/TWKB/GeoJSON parser and serializer

Latest version **0.5.0** (published 2020-03-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install wkx
pnpm add wkx
yarn add wkx
bun add wkx
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.0 |
| Published | 2020-03-26 |
| First published | 2014-08-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 275.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 329 |
| Author | Christian Schwarz |
| Maintainers | cschwarz |
| Keywords | wkt, wkb, ewkt, ewkb, twkb, geojson, ogc, geometry, geography, spatial |

## Links

- npm: https://www.npmjs.com/package/wkx
- Repository: https://github.com/cschwarz/wkx
- Homepage: https://github.com/cschwarz/wkx#readme
- Issues: https://github.com/cschwarz/wkx/issues
- npm.io page: https://npm.io/package/wkx

## Dependencies (1)

- [@types/node](https://npm.io/package/@types/node.md) *

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.5.0 (latest) — 2020-03-26
- 0.4.8 — 2019-07-27
- 0.4.7 — 2019-06-07
- 0.4.6 — 2018-12-09
- 0.4.5 — 2018-05-11
- 0.4.4 — 2018-02-27
- 0.4.3 — 2018-02-27
- 0.4.2 — 2017-09-14
- 0.4.1 — 2016-11-18
- 0.4.0 — 2016-09-13
- 0.3.0 — 2016-06-24
- 0.2.0 — 2015-12-03
- 0.1.0 — 2015-07-03
- 0.0.7 — 2015-05-13
- 0.0.6 — 2015-05-12
- … 3 more at https://npm.io/package/wkx/versions

## README

wkx [![Build Status](https://travis-ci.org/cschwarz/wkx.svg?branch=master)](https://travis-ci.org/cschwarz/wkx) [![Coverage Status](https://coveralls.io/repos/cschwarz/wkx/badge.svg?branch=master)](https://coveralls.io/r/cschwarz/wkx?branch=master)
========

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.

```javascript
var wkx = require('wkx');

//Parsing a WKT string
var geometry = wkx.Geometry.parse('POINT(1 2)');

//Parsing an EWKT string
var geometry = wkx.Geometry.parse('SRID=4326;POINT(1 2)');

//Parsing a node Buffer containing a WKB object
var geometry = wkx.Geometry.parse(wkbBuffer);

//Parsing a node Buffer containing an EWKB object
var geometry = wkx.Geometry.parse(ewkbBuffer);

//Parsing a node Buffer containing a TWKB object
var geometry = wkx.Geometry.parseTwkb(twkbBuffer);

//Parsing a GeoJSON object
var geometry = wkx.Geometry.parseGeoJSON({ type: 'Point', coordinates: [1, 2] });

//Serializing a Point geometry to WKT
var wktString = new wkx.Point(1, 2).toWkt();

//Serializing a Point geometry to WKB
var wkbBuffer = new wkx.Point(1, 2).toWkb();

//Serializing a Point geometry to EWKT
var ewktString = new wkx.Point(1, 2, undefined, undefined, 4326).toEwkt();

//Serializing a Point geometry to EWKB
var ewkbBuffer = new wkx.Point(1, 2, undefined, undefined, 4326).toEwkb();

//Serializing a Point geometry to TWKB
var twkbBuffer = new wkx.Point(1, 2).toTwkb();

//Serializing a Point geometry to GeoJSON
var geoJSONObject = new wkx.Point(1, 2).toGeoJSON();
```

Browser
-------

To use `wkx` in a webpage, simply copy a built browser version from `dist/` into your project, and use a `script` tag
to include it:
```html
<script src="wkx.js"></script>
```

If you use [browserify][] for your project, you can simply `npm install wkx --save`, and just require `wkx` as usual in
your code.

----

Regardless of which of the preceeding options you choose, using `wkx` in the browser will look the same:
```javascript
var wkx = require('wkx');

var geometry = wkx.Geometry.parse('POINT(1 2)');

console.log(geometry.toGeoJSON());
```

In addition to the `wkx` module, the browser versions also export `buffer`, which is useful for parsing WKB:
```javascript
var Buffer = require('buffer').Buffer;
var wkx = require('wkx');

var wkbBuffer = new Buffer('0101000000000000000000f03f0000000000000040', 'hex');
var geometry = wkx.Geometry.parse(wkbBuffer);

console.log(geometry.toGeoJSON());
```
[browserify]: http://browserify.org/

---
_Source: https://npm.io/package/wkx · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
