Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
The wkx npm package provides tools to parse and serialize Well-Known Text (WKT) and Well-Known Binary (WKB) formats, commonly used for representing geometric objects in Geographic Information Systems (GIS). It supports conversion between these formats and GeoJSON, making it useful for applications involving geospatial data manipulations.
Parsing WKT to Geometry
This feature allows the parsing of Well-Known Text (WKT) into a Geometry object, which can then be converted to other formats like GeoJSON.
const wkx = require('wkx');
const wkt = 'POINT (30 10)';
const geometry = wkx.Geometry.parse(wkt);
console.log(geometry.toGeoJSON());
Serializing Geometry to WKT
This feature enables the serialization of Geometry objects (e.g., Point) into the Well-Known Text (WKT) format.
const wkx = require('wkx');
const point = new wkx.Point(30, 10);
const wkt = point.toWkt();
console.log(wkt);
Parsing WKB to Geometry
This feature allows the parsing of Well-Known Binary (WKB) into a Geometry object, which can then be converted to formats like GeoJSON.
const wkx = require('wkx');
const wkbBuffer = Buffer.from('0101000000000000000000F03F000000000000F03F', 'hex');
const geometry = wkx.Geometry.parse(wkbBuffer);
console.log(geometry.toGeoJSON());
Serializing Geometry to WKB
This feature enables the serialization of Geometry objects into the Well-Known Binary (WKB) format.
const wkx = require('wkx');
const point = new wkx.Point(30, 10);
const wkb = point.toWkb();
console.log(wkb.toString('hex'));
This package also parses and serializes WKT. It is part of the Terraformer project, which provides tools for converting between different geospatial formats. Compared to wkx, it is specifically focused on WKT and does not handle WKB.
Similar to wkx, 'wellknown' parses and serializes WKT. It is lightweight and focuses solely on WKT, without support for WKB, making it less versatile for applications that require WKB handling.
A WKT/WKB/EWKT/EWKB/TWKB/GeoJSON parser and serializer with support for
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();
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="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());
FAQs
A WKT/WKB/EWKT/EWKB/TWKB/GeoJSON parser and serializer
We found that wkx demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.