Home Reference Source Repository

Function

Static Public Summary
public

Returns a stored Projection for a given URI, or undefined if no Projection is stored for that URI.

public

Returns a Promise that succeeds with an already stored Projection or, if not stored, that remotely loads the Projection (currently using http://epsg.io), stores it, and then succeeds with it.

public

set(crsUri: string, proj: string | Projection, options: Object): Projection

Stores a given projection for a given URI that can then be accessed via get and load.

Static Public

public get(crsUri: string): Projection | undefined source

import {get} from 'uriproj/'

Returns a stored Projection for a given URI, or undefined if no Projection is stored for that URI.

Params:

NameTypeAttributeDescription
crsUri string

The CRS URI for which to return a Projection.

Return:

Projection | undefined

A Projection object, or undefined if not stored by load or set.

Example:

// has to be stored previously via load() or set()
var proj = uriproj.get('http://www.opengis.net/def/crs/EPSG/0/27700')
var [longitude, latitude] = [-1.54, 55.5]
var [easting,northing] = proj.forward([longitude, latitude])

public load(crsUri: string): Promise<Projection, Error> source

import {load} from 'uriproj/'

Returns a Promise that succeeds with an already stored Projection or, if not stored, that remotely loads the Projection (currently using http://epsg.io), stores it, and then succeeds with it.

Params:

NameTypeAttributeDescription
crsUri string

The CRS URI for which to return a projection.

Return:

Promise<Projection, Error>

A Promise object succeeding with a Projection object, and failing with an Error object in case of network or PROJ.4 parsing problems.

Example:

Loading a single projection
uriproj.load('http://www.opengis.net/def/crs/EPSG/0/27700').then(proj => {
  var [longitude, latitude] = [-1.54, 55.5]
  var [easting,northing] = proj.forward([longitude, latitude])
})
Loading multiple projections
var uris = [
  'http://www.opengis.net/def/crs/EPSG/0/27700',
  'http://www.opengis.net/def/crs/EPSG/0/7376',
  'http://www.opengis.net/def/crs/EPSG/0/7375']
Promise.all(uris.map(uriproj.load)).then(projs => {
  // all projections are loaded and stored now
  
  // get the first projection
  var proj1 = projs[0]
  // or:
  var proj1 = uriproj.get(uris[0])
})

public set(crsUri: string, proj: string | Projection, options: Object): Projection source

import {set} from 'uriproj/'

Stores a given projection for a given URI that can then be accessed via get and load.

Params:

NameTypeAttributeDescription
crsUri string

The CRS URI for which to store the projection.

proj string | Projection

A proj4 string or a Projection object.

options Object
  • optional

Options object.

options.reverseAxes boolean
  • optional
  • default: false

If proj is a proj4 string, whether to reverse the projection axes.

Return:

Projection

The newly stored projection.

Throw:

Error

If crsUri or proj is missing, or if a PROJ.4 string cannot be parsed by proj4js.

Example:

Storing a projection using a PROJ.4 string
var uri = 'http://www.opengis.net/def/crs/EPSG/0/27700'
var proj4 = '+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 ' +
  '+ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs'
uriproj.set(uri, proj4)
Storing a projection using a Projection object
var uri = 'http://www.opengis.net/def/crs/EPSG/0/27700'
var proj = {
  forward: ([lon,lat]) => [..., ...],
  inverse: ([x,y]) => [..., ...]
}
uriproj.set(uri, proj)