• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..20-Oct-2018-

LICENSE.mdH A D20-Oct-20181.4 KiB2924

README.mdH A D20-Oct-20185.1 KiB154111

README.md

1# PROJ4JS [![Build Status](https://travis-ci.org/proj4js/proj4js.svg)](https://travis-ci.org/proj4js/proj4js)
2
3Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.
4Originally a port of [PROJ.4](http://trac.osgeo.org/proj/) and [GCTCP C](http://edcftp.cr.usgs.gov/pub//software/gctpc) it is
5a part of the [MetaCRS](http://wiki.osgeo.org/wiki/MetaCRS) group of projects.
6
7## Installing
8
9Depending on your preferences
10
11```bash
12npm install proj4
13bower install proj4
14jam install proj4
15component install proj4js/proj4js
16```
17
18or just manually grab the file `proj4.js` from the [latest release](https://github.com/proj4js/proj4js/releases).
19
20if you do not want to download anything, Proj4js is also hosted on [cdnjs](http://www.cdnjs.com/libraries/proj4js) for direct use in your browser applications.
21
22## Using
23
24the basic signature is:
25
26```javascript
27proj4(fromProjection[, toProjection, coordinates])
28```
29
30Projections can be proj or wkt strings.
31
32Coordinates may an object of the form `{x:x,y:y}` or an array of the form `[x,y]`.
33
34When all 3 arguments  are given, the result is that the coordinates are transformed from projection1 to projection 2. And returned in the same format that they were given in.
35
36```javascript
37var firstProjection = 'PROJCS["NAD83 / Massachusetts Mainland",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4269"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",42.68333333333333],PARAMETER["standard_parallel_2",41.71666666666667],PARAMETER["latitude_of_origin",41],PARAMETER["central_meridian",-71.5],PARAMETER["false_easting",200000],PARAMETER["false_northing",750000],AUTHORITY["EPSG","26986"],AXIS["X",EAST],AXIS["Y",NORTH]]';
38var secondProjection = "+proj=gnom +lat_0=90 +lon_0=0 +x_0=6300000 +y_0=6300000 +ellps=WGS84 +datum=WGS84 +units=m +no_defs";
39//I'm not going to redefine those two in latter examples.
40proj4(firstProjection,secondProjection,[2,5]);
41// [-2690666.2977344505, 3662659.885459918]
42```
43
44If only 1 projection is given then it is assumed that it is being projected *from* WGS84 (fromProjection is WGS84).
45
46```javascript
47proj4(firstProjection,[-71,41]);
48// [242075.00535055372, 750123.32090043]
49```
50
51If no coordinates are given an object with two methods is returned, its methods are `forward` which projects from the first projection to the second and `inverse` which projects from the second to the first.
52
53```javascript
54proj4(firstProjection,secondProjection).forward([2,5]);
55// [-2690666.2977344505, 3662659.885459918]
56proj4(secondProjection,firstProjection).inverse([2,5]);
57// [-2690666.2977344505, 3662659.885459918]
58```
59
60and as above if only one projection is given, it's assumed to be coming from wgs84
61
62```javascript
63proj4(firstProjection).forward([-71,41]);
64// [242075.00535055372, 750123.32090043]
65proj4(firstProjection).inverse([242075.00535055372, 750123.32090043]);
66//[-71, 40.99999999999986]
67//the floating points to answer your question
68```
69
70## Named Projections
71
72If you prefer to define a projection as a string and reference it that way, you may use the proj4.defs method which can be called 2 ways, with a name and projection:
73
74```js
75proj4.defs('WGS84', "+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees");
76```
77
78or with an array
79
80```js
81proj4.defs([
82  [
83    'EPSG:4326',
84    '+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees'],
85  [
86    'EPSG:4269',
87    '+title=NAD83 (long/lat) +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees'
88  ]
89]);
90```
91
92you can then do
93
94```js
95proj4('EPSG:4326');
96```
97
98instead of writing out the whole proj definition, by default proj4 has the following projections predefined:
99
100- 'EPSG:4326', which has the following alias
101    - 'WGS84'
102- 'EPSG:4269'
103- 'EPSG:3857', which has the following aliases
104    - 'EPSG:3785'
105    - 'GOOGLE'
106    - 'EPSG:900913'
107    - 'EPSG:102113'
108
109defined projections can also be accessed through the proj4.defs function (`proj4.defs('EPSG:4326')`).
110
111proj4.defs can also be used to define a named alias:
112
113```javascript
114proj4.defs('urn:x-ogc:def:crs:EPSG:4326', proj4.defs('EPSG:4326'));
115```
116
117## Developing
118to set up build tools make sure you have node and grunt-cli installed and then run `npm install`
119
120to do the complete build and browser tests run
121
122```bash
123grunt
124```
125
126to run node tests run
127
128```bash
129npm test
130```
131
132to run node tests with coverage run
133
134```bash
135node test --coverage
136```
137
138to create a build with only default projections (latlon and Mercator) run
139
140```bash
141grunt build
142```
143
144to create a build with only custom projections include a comma separated list of projections codes (the file name in 'lib/projections' without the '.js') after a colon, e.g.
145
146```bash
147grunt build:tmerc
148#includes transverse Mercator
149grunt build:lcc
150#includes lambert conformal conic
151grunt build:omerc,moll
152#includes oblique Mercator and Mollweide
153```
154