@math.gl/geospatial/crs
@math.gl/geospatial/crs provides lightweight, proj4-independent TypeScript definitions and syntax codecs
for coordinate reference systems. It has no runtime dependencies and is browser-safe.
The Coordinate Reference Systems developer guide explains CRS families, representations, coordinate epochs, axis order, vertical coordinates, transformation boundaries, and cross-library integration in depth.
For definitions of surface models, paths, reference systems, and distortion properties, see Geospatial terminology.
Usageโ
import type {CRSDefinition, PROJJSONCRS} from '@math.gl/geospatial/crs';
const authorityCode: CRSDefinition = 'EPSG:4326';
const projString: CRSDefinition = '+proj=longlat +datum=WGS84 +no_defs';
const wkt2: CRSDefinition = 'GEOGCRS["WGS 84", /* ... */]';
const projjson: PROJJSONCRS = {
type: 'GeographicCRS',
name: 'WGS 84',
datum: {
name: 'World Geodetic System 1984',
ellipsoid: {
name: 'WGS 84',
semi_major_axis: 6378137,
inverse_flattening: 298.257223563
}
}
};
Featuresโ
| Feature | Support | Notes |
|---|---|---|
| Typed PROJJSON CRS definitions | โ | Strict PROJJSON v0.7 types describe geographic, projected, compound and other supported CRS object shapes. |
| WKT1/WKT2 syntax round trips | โ | Ordered syntax ASTs preserve unknown nodes, delimiters, duplicates and numeric lexemes; optional profile validation is separate. |
| PROJ strings and pipeline syntax | โ | Ordered syntax parsing/encoding retains steps and duplicate parameters; successful parsing does not execute an operation. |
| Spatial-reference provenance and epochs | โ | SpatialReference distinguishes explicit/default/unknown/missing CRS state and retains coordinate epochs. |
| Prepared converter descriptors and target domains | โ | createCRSDescriptor assembles external converters and explicit rendering/domain policy. |
| Asynchronous CRS resolution | โ | Application-owned catalogues/providers resolve definitions without a mandatory projection backend. |
| Universal semantic conversion between serializations | โ | WKT/PROJ syntax models preserve syntax; they do not promise lossless universal conversion into canonical PROJJSON semantics. |
| Bundled comprehensive authority database | โ | No complete built-in EPSG database or implicit catalogue/grid downloads. Applications supply resolution resources. |
| Coordinate transformation execution | โ | Use a projection engine or an external converter; metadata/codec acceptance does not establish executable support. |
Prepared descriptorsโ
Use createCRSDescriptor from
@math.gl/geospatial/crs to assemble metadata, prepared external converters and
rendering policy without importing a projection engine. Descriptor and converter
types are exported from the same entry point. The builder is also available from
@math.gl/geospatial.
Installationโ
npm install @math.gl/geospatial
Definition modelโ
CRSDefinition accepts either a string serialization or a strict PROJJSON CRS object:
The string aliases (CRSIdentifier, WKTCRSDefinition, and PROJStringDefinition) document
intent but are all structurally string. Call the appropriate parser when syntax needs to be
inspected or validated.
PROJJSON and WKTโ
PROJJSON is maintained by the OSGeo PROJ project. It is not independently an OGC or ISO standard; it is designed as a lossless JSON encoding of OGC WKT2:2019 / ISO 19162:2019 and is referenced by OGC standards.
Strict PROJJSON v0.7 is the canonical semantic object model in @math.gl/geospatial/crs. The WKT and PROJ
ASTs are syntax models: they preserve ordering, duplicates, number lexemes, delimiter choice, and
unknown extensions without claiming semantic equivalence or universal PROJJSON conversion.
WKT syntaxโ
parseWKTCRS parses WKT1 and WKT2 serializations, including common GDAL and ESRI extensions, into
a discriminated WKTCRSAst. Parsing is tolerant by default. validateWKTCRS can check a WKT1,
WKT2:2015, or WKT2:2019 profile, and strict: true makes parsing reject validation issues.
import {encodeWKTCRS, parseWKTCRS, validateWKTCRS} from '@math.gl/geospatial/crs';
const ast = parseWKTCRS('GEOGCRS["WGS 84",ID["EPSG",4326]]');
const issues = validateWKTCRS(ast, {profile: 'wkt2:2019'});
const compact = encodeWKTCRS(ast);
const pretty = encodeWKTCRS(ast, {format: 'pretty'});
The parser preserves keyword spelling, bracket or parenthesis delimiters, value order, repeated
elements, unknown nodes, and the source lexeme for each number. WKTCRSSyntaxError reports a
zero-based source offset and one-based line and column.
PROJ string syntaxโ
parsePROJString parses ordinary definitions and pipelines into an ordered PROJStringAst.
Duplicate parameters, flags, quoted values, global pipeline parameters, and step separators are
preserved. encodePROJString emits canonical leading + signs and normalized whitespace.
import {encodePROJString, parsePROJString} from '@math.gl/geospatial/crs';
const ast = parsePROJString('+proj=pipeline +ellps=GRS80 +step +proj=unitconvert +xy_in=deg');
const text = encodePROJString(ast);
Shell command-line syntax and PROJ resource or init-file parsing are intentionally outside the scope of this codec.
Spatial-reference descriptorsโ
SpatialReference reports how a dataset's coordinates are defined without claiming that they were
transformed. Its discriminated CRS state preserves explicit definitions, specification defaults,
explicitly unknown values, and absent metadata.
import {createSpatialReference} from '@math.gl/geospatial/crs';
const spatialReference = createSpatialReference({
crs: {
state: 'explicit',
definition: 'EPSG:4326',
representation: 'identifier',
provenance: 'metadata'
},
coordinateFrame: 'geographic',
coordinateOrder: ['x', 'y'],
units: ['degree', 'degree']
});
The descriptor can retain alternate source representations and a coordinate epoch. PROJJSON definitions and descriptor-owned arrays are cloned and recursively frozen. See the Spatial Reference API.
Imports and bundle boundariesโ
Import syntax codecs, metadata helpers and the optional resolver as named exports
from @math.gl/geospatial/crs or @math.gl/geospatial. Both entry points provide ESM, CommonJS and
TypeScript declarations. Use import type for TypeScript-only APIs.
Tree-shaking bundlers can remove unused codecs and resolution code. CommonJS and
namespace imports can retain more code; inspect emitted bundles when size matters.
APIโ
Optional CRS resolution accepts application-owned
catalogues and asynchronous providers through @math.gl/geospatial/crs.
Resolution supplies definitions; execution support remains engine-specific.
CRSDefinition<T extends PROJJSONCRS = PROJJSONCRS>โ a string definition or PROJJSON object.PROJJSONCRSโ generated from the official v0.7 schema's#/definitions/crs.PROJJSONCRSTypeโ all top-level PROJJSON CRS type literals.PROJJSONCRSByType<T>โ the discriminated subset for one or more top-level types.PROJJSON_SCHEMA_VERSIONโ'0.7'.PROJJSON_SCHEMA_URLโ the canonical official schema URL.WKTCRSAst,WKTCRSNode,WKTCRSValueโ value-preserving WKT syntax tree types.parseWKTCRS,encodeWKTCRS,validateWKTCRSโ WKT syntax codec and profile validation.PROJStringAst,PROJParameterโ ordered PROJ syntax tree types.parsePROJString,encodePROJStringโ ordinary definition and pipeline syntax codec.SpatialReference,CRSReferenceโ immutable discovery descriptors with explicit state, representation, provenance, epoch, frame, order, and units.ReadonlyCRSDefinition,ReadonlyPROJJSONCRSโ serialized CRS text or a deeply readonly PROJJSON definition.createSpatialReferenceโ constructs and freezes a descriptor.inferCRSRepresentationโ conservatively classifies a definition's runtime syntax.normalizeCRSIdentifierโ changes the authority, OGC URN and OGC URI spellings of one registry entry toAUTHORITY:CODE. Use the result to compare identifiers.getCRSAuthorityAxisOrderโ gives the authority axis order (xyoryx) of a PROJJSON or WKT definition, or of an identifier in a small built-in table. It returnsundefinedwhen the order is unknown.
The official MIT-licensed schema is vendored unchanged and can be imported or resolved through
@math.gl/geospatial/crs-projjson.schema.json. It is the PROJJSON runtime validation source of truth. The
package does not add a second Zod schema. It also does not perform coordinate transformations,
authority-registry lookup, semantic CRS comparison, or WKT/PROJ-to-PROJJSON conversion.
See raster mesh preparation for composing domain clipping, refinement and UV provenance.