What it writes
Serialize CRS definitions without losing their shape.
WKTCRSWriter normalizes insignificant whitespace while retaining keyword spelling, delimiters, ordering, repeated and unknown nodes, and original number lexemes.
Input
A WKTCRSAst from @math.gl/geospatial/crs
Output
Compact or pretty WKT-CRS text
Preserves
Structure, ordering, and numeric lexemes
Boundary
Serialization, not coordinate transformation
Detailed guide
WKTCRSWriter reference
The sections below document installation, usage, formatting options, and the supported AST contract.
Encodes a WKTCRSAst from @math.gl/geospatial/crs as WKT. See
Coordinate Reference Systems for the shared
type model and the distinction between syntax preservation and coordinate transformation.
Installation
npm install @loaders.gl/core @loaders.gl/geospatial @math.gl/geospatial
Usage
import {encodeText, parse} from '@loaders.gl/core';
import {WKTCRSLoader, WKTCRSWriter} from '@loaders.gl/geospatial/wkt';
const ast = await parse('GEOGCRS["WGS 84",ID["EPSG",4326]]', WKTCRSLoader);
const compactWKT = await encodeText(ast, WKTCRSWriter);
Options
Pass math.gl encoder options under the writer namespace:
const prettyWKT = await encodeText(ast, WKTCRSWriter, {
'wkt-crs': {format: 'pretty', indent: 2}
});
Compact output is the default. Encoding normalizes insignificant whitespace but retains keyword spelling, delimiter choice, value order, repeated or unknown nodes, and number lexemes.
The writer accepts the v5 WKTCRSAst; it no longer accepts the v4 nested-array/hybrid-object
shape or the raw: string convention.