{"id":14358,"library":"wkt-parser","title":"WKT Parser for Geographic Data","description":"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.","status":"active","version":"1.5.5","language":"javascript","source_language":"en","source_url":"https://github.com/proj4js/wkt-parser","tags":["javascript"],"install":[{"cmd":"npm install wkt-parser","lang":"bash","label":"npm"},{"cmd":"yarn add wkt-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add wkt-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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');`","wrong":"const parse = require('wkt-parser');","symbol":"parse","correct":"import { parse } from 'wkt-parser';"},{"note":"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.","wrong":"import parse from 'wkt-parser';","symbol":"parse","correct":"const { parse } = require('wkt-parser');"}],"quickstart":{"code":"import { parse } from 'wkt-parser';\n\n// Example 1: Parsing a WKT Point\nconst wktPoint = 'POINT (10 20)';\nconst parsedPoint = parse(wktPoint);\nconsole.log('Parsed Point:\\n', JSON.stringify(parsedPoint, null, 2));\n/*\nExpected output structure (may vary slightly based on internal representation):\n{\n  \"type\": \"Point\",\n  \"coordinates\": [10, 20]\n}\n*/\n\n// Example 2: Parsing a WKT Polygon\nconst wktPolygon = 'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))';\ntry {\n  const parsedPolygon = parse(wktPolygon);\n  console.log('\\nParsed Polygon:\\n', JSON.stringify(parsedPolygon, null, 2));\n} catch (error: any) {\n  console.error('\\nError parsing Polygon:', error.message);\n}\n\n// Example 3: Handling an unsupported WKT type (GEOCCS) - will throw an error\nconst wktGeoccs = 'GEOCCS[\"GEOCENTRICDATUM[\"WGS 84\"]\",PRIMEM[\"Greenwich\",0],UNIT[\"metre\",1]]';\ntry {\n  parse(wktGeoccs);\n  console.log('Unexpectedly parsed GEOCCS, this should not happen.');\n} catch (error: any) {\n  console.warn(`\\nExpected error when parsing GEOCCS (unsupported type): ${error.message}`);\n}\n","lang":"typescript","description":"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."},"warnings":[{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"Support 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"Malformed 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.5.5':79 'advanc':62 'aim':42 'alongsid':65 'applic':106 'capabl':14 'compon':35 'compoundc':127 'comprehens':94 'coordin':71,123,147 'current':75 'data':5,30,111 'deal':107 'dedic':46 'definit':73,149 'design':24 'develop':142 'differenti':91 'explicit':115 'extract':36 'focus':135 'format':112 'frequent':81 'geocc':125 'geocentr':122 'geodet':29 'geograph':4,27 'geospati':110 'hackabl':48 'histori':88 'howev':113 'indic':83 'interpret':54 'javascript':150 'json':68 'key':90 'known':18 'librari':10,40 'limit':117 'make':102,136 'multipl':97 'note':116 'offer':44 'oper':72 'origin':31 'pars':13 'parser':2,9 'partial':130 'proj4js':39 'project':145 'projjson':22,53,66,101 'provid':11 'publish':87 'recent':86 'represent':69 'robust':12 'solut':49 'special':139 'specif':25 'stabl':76 'standalon':34 'standard':64,99 'string':23 'support':56,95,121,131 'system':124,148 'text':19 'tool':140 'updat':82 'various':109 'versatil':104 'version':77 'well':17 'well-known':16 'wkt':1,8,20,51,98 'wkt-parser':7 'wkt1':58,133 'wkt2':63 'work':143","created_at":"2026-04-20T01:59:17.995377+00:00","updated_at":"2026-04-20T01:59:17.995377+00:00","problems":[{"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.","cause":"The input WKT or PROJJSON string contains a syntax error or an unrecognized keyword at the indicated position.","error":"Error: Unexpected token at position X"},{"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.","cause":"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).","error":"TypeError: Cannot read properties of undefined (reading 'coordinates')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.0.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/proj4js/wkt-parser","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/wkt-parser","openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}