MCPcopy Index your code
hub / github.com/cschwarz/wkx

github.com/cschwarz/wkx @v0.5.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.5.0 ↗ · + Follow
48 symbols 75 edges 21 files 0 documented · 0% 4 cross-repo links updated 3y ago★ 33014 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

wkx Build Status Coverage Status

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.

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:

<script src="https://github.com/cschwarz/wkx/raw/v0.5.0/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:

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:

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());

Extension points exported contracts — how you extend this code

GeoJSONOptions (Interface)
(no doc)
lib/wkx.d.ts

Core symbols most depended-on inside this repo

_write
called by 14
lib/binarywriter.js
_read
called by 8
lib/binaryreader.js
assertParseWkt
called by 1
test/wkx.js
assertParseWkb
called by 1
test/wkx.js
assertParseWkbXdr
called by 1
test/wkx.js
assertParseEwkt
called by 1
test/wkx.js
assertParseEwkb
called by 1
test/wkx.js
assertParseEwkbXdr
called by 1
test/wkx.js

Shape

Function 31
Class 16
Interface 1

Languages

TypeScript100%

Modules by API surface

test/wkx.js18 symbols
lib/wkx.d.ts17 symbols
lib/binarywriter.js2 symbols
lib/binaryreader.js2 symbols
lib/wktparser.js1 symbols
lib/polygon.js1 symbols
lib/point.js1 symbols
lib/multipolygon.js1 symbols
lib/multipoint.js1 symbols
lib/multilinestring.js1 symbols
lib/linestring.js1 symbols
lib/geometrycollection.js1 symbols

For agents

$ claude mcp add wkx \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact