UNPKG

3 kBMarkdownView Raw
1# uriproj
2
3Map projection functions from standard coordinate reference system (CRS) URIs.
4
5This library makes it easy to retrieve map projection functions from CRS URIs.
6It transparently fetches transformation data from https://epsg.io and uses [proj4js](http://proj4js.org/) to generate a projection out of that.
7Once a projection has been generated, it is stored in a local cache for later use to avoid unnecessary network requests.
8
9uriproj 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.
10
11## Install
12
13uriproj works on browsers and any tool following the CommonJS/node module conventions.
14
15A minified browser version of this library is available in the [GitHub releases](https://github.com/Reading-eScience-Ccentre/uriproj/releases) as well as on [unpkg](https://unpkg.com/uriproj/). It can be included like that:
16```html
17<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.14/proj4.js"></script>
18<script src="https://unpkg.com/uriproj@0.2/uriproj.min.js"></script>
19```
20
21An ES6 import would look like that:
22```js
23import * as uriproj from 'uriproj'
24```
25## API documentation
26
27<https://doc.esdoc.org/github.com/Reading-eScience-Centre/uriproj/>
28
29## Usage
30
31As an example, we load the British National Grid projection and convert geographic coordinates into projection coordinates and vice-versa.
32
33```js
34uriproj.load('http://www.opengis.net/def/crs/EPSG/0/27700').then(proj => {
35 // from WGS84 coordinates to projection coordinates
36 var longitude = -1.54
37 var latitude = 55.5
38 var projected = proj.forward([longitude, latitude])
39 console.log('Easting: ', projected[0])
40 console.log('Northing: ', projected[1])
41
42 // back from projection coordinates to WGS84 geographic coordinates
43 var geo = proj.inverse(projected)
44 console.log('Longitude: ', geo[0])
45 console.log('Latitude: ', geo[1])
46})
47```
48
49Currently, the following URIs are recognized by `load()` (in addition to those stored manually with `set()`):
50
51- http://www.opengis.net/def/crs/OGC/1.3/CRS84
52- http://www.opengis.net/def/crs/EPSG/0/ `<CODE>`
53
54Any projection that has been previously `load()`'ed or stored with `set()` can be directly accessed via `get()`, avoiding the indirection of a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) as in `load()`:
55```js
56var proj = uriproj.get('http://www.opengis.net/def/crs/EPSG/0/27700')
57var projected = proj.forward([longitude, latitude])
58```
59
60Manually storing projections using PROJ.4 strings or projection functions is possible with `set()`:
61
62```js
63var uri = 'http://www.opengis.net/def/crs/EPSG/0/27700'
64var proj4 = '+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 ' +
65 '+ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs'
66uriproj.set(uri, proj4)
67```