Registry / data / wkt-parser

wkt-parser

JSON →
library1.0.1jsnpmunverified

The `wkt-parser` library provides robust parsing capabilities for Well-Known Text (WKT) and PROJJSON strings, designed specifically for geographic and geodetic data. Originating as a standalone component extracted from the `proj4js` library, it aims to offer a dedicated and hackable solution for WKT and PROJJSON interpretation. It supports both WKT1 and the more advanced WKT2 standards, alongside PROJJSON, a JSON representation for coordinate operation definitions. The current stable version is 1.5.5, with frequent updates indicated by its recent publish history. A key differentiator is its comprehensive support for multiple WKT standards and PROJJSON, making it versatile for applications dealing with various geospatial data formats. However, it explicitly notes limitations: it does not support geocentric coordinate systems (`GEOCCS`) and `COMPOUNDCS` is only partially supported for WKT1. This focus makes it a specialized tool for developers working with projection and coordinate system definitions.

npm install wkt-parser
INSTALL
IMPORT
SIG · WKT-PARSER
W
wkt-parser
datajavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
import { parse } from 'wkt-parser';
const parse = require('wkt-parser');
The primary function to parse WKT/PROJJSON strings. The library is primarily ESM-first, but CommonJS `require` might work via transpilation or bundler. For CJS, typically `const { parse } = require('wkt-parser');`
parse
const { parse } = require('wkt-parser');
import parse from 'wkt-parser';
CommonJS usage for Node.js environments. If the library uses `exports.parse = ...` or `module.exports = { parse: ... }`, this pattern is correct. A direct default import `import parse from 'wkt-parser'` is less common for libraries exporting a single named utility function.

Demonstrates how to import and use the `parse` function for WKT Point and Polygon strings, and how the parser handles unsupported WKT types with errors.

import { parse } from 'wkt-parser'; // Example 1: Parsing a WKT Point const wktPoint = 'POINT (10 20)'; const parsedPoint = parse(wktPoint); console.log('Parsed Point:\n', JSON.stringify(parsedPoint, null, 2)); /* Expected output structure (may vary slightly based on internal representation): { "type": "Point", "coordinates": [10, 20] } */ // Example 2: Parsing a WKT Polygon const wktPolygon = 'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))'; try { const parsedPolygon = parse(wktPolygon); console.log('\nParsed Polygon:\n', JSON.stringify(parsedPolygon, null, 2)); } catch (error: any) { console.error('\nError parsing Polygon:', error.message); } // Example 3: Handling an unsupported WKT type (GEOCCS) - will throw an error const wktGeoccs = 'GEOCCS["GEOCENTRICDATUM["WGS 84"]",PRIMEM["Greenwich",0],UNIT["metre",1]]'; try { parse(wktGeoccs); console.log('Unexpectedly parsed GEOCCS, this should not happen.'); } catch (error: any) { console.warn(`\nExpected error when parsing GEOCCS (unsupported type): ${error.message}`); }
Debug
Known issues
gotchaThe `wkt-parser` library explicitly states that it does not support geocentric coordinate systems (`GEOCCS`) in its current implementation. Attempting to parse such WKT strings will result in an error.
fix
Avoid using `wkt-parser` for `GEOCCS` definitions. Consider pre-processing your WKT strings to exclude `GEOCCS` or use an alternative parser that supports them.
affects: >=1.0.0
gotchaSupport for `COMPOUNDCS` (Compound Coordinate System) is limited to WKT1. If you are working with WKT2 formatted `COMPOUNDCS` strings, the parser may not interpret them correctly or may throw an error.
fix
Ensure `COMPOUNDCS` strings are formatted according to WKT1 specifications when using this parser. For WKT2 `COMPOUNDCS`, you might need to adapt your input or use a different tool.
affects: >=1.0.0
gotchaMalformed or syntactically incorrect WKT/PROJJSON input will result in parsing errors. The library provides detailed error messages, but robust input validation is crucial for production applications.
fix
Always wrap parsing operations in a `try...catch` block. Implement client-side or server-side validation for WKT/PROJJSON strings before passing them to the parser to prevent unexpected application crashes.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Unexpected token at position X
The input WKT or PROJJSON string contains a syntax error or an unrecognized keyword at the indicated position.
fix
Carefully review the WKT/PROJJSON string for typos, missing parentheses, incorrect delimiters, or unsupported elements. Ensure it adheres strictly to WKT1, WKT2, or PROJJSON specifications.
TypeError: Cannot read properties of undefined (reading 'coordinates')
Attempting to access properties like `coordinates` on the result of a failed parse operation, or on a parsed object that doesn't have that specific property (e.g., trying to get `coordinates` from a non-geometry object if such types are parsed).
fix
Ensure the parsing operation was successful by checking for errors (using `try...catch`). Verify the structure of the parsed output against the expected geometry type before accessing nested properties. The output structure can vary for different WKT types.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
30 hits · last 30 days
node
24
OpenAI (training)
1
Resources
wkt-parser — npm install wkt-parser · libregistry