Skip to content

projections

This module wraps proj4 to manage coordinate reference system (CRS) definitions.

The WGS84 constant ('WGS84') is the canonical name used by the library for the WGS84 geographic coordinate reference system.

In addition to the projections provided by proj4, several common projections and WGS84 aliases are automatically registered when the module is loaded.

The following projections are available by default:

NameDescription
WGS84WGS84 geographic CRS
EPSG:4326WGS84 geographic CRS
CRS:84OGC WGS84 geographic CRS
CRS84Alias for CRS:84
EPSG:3857Web Mercator
EPSG:2154RGF93 / Lambert-93

Common OGC URN aliases for WGS84 are also supported.

Additional projections can be registered using defineProjection().

normalizeCrsName

Signature

js
normalizeCrsName(name)

Description

Normalizes an OGC EPSG URN to its short EPSG:<code> form.

Other CRS names are returned unchanged.

Parameters

NameTypeRequiredDescription
namestringyesCRS name to normalize

Returns

TypeDescription
stringThe normalized CRS name

Throws

Throws if name is not a non-empty string.

Examples

js
normalizeCrsName('urn:ogc:def:crs:EPSG::2154')
// 'EPSG:2154'

normalizeCrsName('EPSG:2154')
// 'EPSG:2154'

normalizeCrsName('CRS:84')
// 'CRS:84'

listProjections

Signature

js
listProjections()

Description

Returns the names of all registered projections.

This includes projections provided by proj4, projections registered by common-geospatial, and projections added through defineProjection().

Returns

TypeDescription
string[]Array of registered projection names

Examples

js
listProjections()
// ['EPSG:4326', 'EPSG:3857', 'WGS84', 'CRS:84', 'EPSG:2154', ...]

defineProjection

Signature

js
defineProjection(name, definition)

Description

Defines a projection under the given name.

The definition may be either a Proj4 definition string or a Proj4 definition object. If a projection with the same name already exists, it is replaced.

Parameters

NameTypeRequiredDescription
namestringyesProjection name, for example EPSG:2154
definitionstring | objectyesProj4 definition string or definition object

Throws

Throws if name is not a non-empty string or if definition is neither a non-empty string nor a non-empty object.

Examples

js
defineProjection(
  'EPSG:32631',
  '+proj=utm +zone=31 +datum=WGS84 +units=m +no_defs'
)

hasProjection

Signature

js
hasProjection(name)

Description

Returns whether a projection with the given name is defined.

Parameters

NameTypeRequiredDescription
namestringyesProjection name

Returns

TypeDescription
booleantrue if the projection exists

Throws

Throws if name is not a non-empty string.

Examples

js
hasProjection('EPSG:2154')
// true

hasProjection('UNKNOWN')
// false

getProjection

Signature

js
getProjection(name)

Description

Returns the Proj4 definition associated with the given projection name.

Parameters

NameTypeRequiredDescription
namestringyesProjection name

Returns

TypeDescription
object | undefinedProjection definition, or undefined if the projection is not defined

Throws

Throws if name is not a non-empty string.

Examples

js
getProjection('EPSG:2154')
// { projName: 'lcc', ... }

getProjection('UNKNOWN')
// undefined

isWGS84Projection

Signature

js
isWGS84Projection(name)

Description

Returns whether the registered projection is recognized as a WGS84 geographic projection based on its projection and datum definitions.

INFO

The comparison is performed against the registered EPSG:4326 definition.

Parameters

NameTypeRequiredDescription
namestringyesProjection name

Returns

TypeDescription
booleantrue if the projection is equivalent to WGS84

Throws

Throws if name is not a non-empty string.

Examples

js
isWGS84Projection('EPSG:4326')
// true

isWGS84Projection('CRS:84')
// true

isWGS84Projection('EPSG:3857')
// false

isWGS84Projection('EPSG:2154')
// false

isWGS84Projection('UNKNOWN')
// false