Skip to content

Map projection functions from standard coordinate reference system URIs

License

Notifications You must be signed in to change notification settings

Reading-eScience-Centre/uriproj

Repository files navigation

uriproj

Map projection functions from standard coordinate reference system (CRS) URIs.

This library makes it easy to retrieve map projection functions from CRS URIs. It transparently fetches transformation data from https://epsg.io and uses proj4js to generate a projection out of that. Once a projection has been generated, it is stored in a local cache for later use to avoid unnecessary network requests.

uriproj also supports manually adding a projection to the local cache together with its URI, either by supplying a PROJ.4 string or a Projection object with forward() and inverse() functions.

Install

uriproj works on browsers and any tool following the CommonJS/node module conventions.

A minified browser version of this library is available in the GitHub releases as well as on jsDelivr. It can be included like that:

<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.14/proj4.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/uriproj.min.js"></script>

An ES6 import would look like that:

import * as uriproj from 'uriproj'

API documentation

https://doc.esdoc.org/github.com/Reading-eScience-Centre/uriproj/

Usage

As an example, we load the British National Grid projection and convert geographic coordinates into projection coordinates and vice-versa.

uriproj.load('http://www.opengis.net/def/crs/EPSG/0/27700').then(proj => {
  // from WGS84 coordinates to projection coordinates
  var longitude = -1.54
  var latitude = 55.5  
  var projected = proj.forward([longitude, latitude])
  console.log('Easting: ', projected[0])
  console.log('Northing: ', projected[1])
  
  // back from projection coordinates to WGS84 geographic coordinates
  var geo = proj.inverse(projected)
  console.log('Longitude: ', geo[0])
  console.log('Latitude: ', geo[1])
})

Currently, the following URIs are recognized by load() (in addition to those stored manually with set()):

Any projection that has been previously load()'ed or stored with set() can be directly accessed via get(), avoiding the indirection of a Promise as in load():

var proj = uriproj.get('http://www.opengis.net/def/crs/EPSG/0/27700')
var projected = proj.forward([longitude, latitude])

Manually storing projections using PROJ.4 strings or projection functions is possible with set():

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)

About

Map projection functions from standard coordinate reference system URIs

Resources

License

Stars

Watchers

Forks

Packages

No packages published