proj4 2.7.5 → 2.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,31 @@
1
+ # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3
+
4
+ name: Node.js CI
5
+
6
+ on:
7
+ push:
8
+ branches: [ "master" ]
9
+ pull_request:
10
+ branches: [ "master" ]
11
+
12
+ jobs:
13
+ build:
14
+
15
+ runs-on: ubuntu-latest
16
+
17
+ strategy:
18
+ matrix:
19
+ node-version: [14.x, 16.x, 18.x]
20
+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21
+
22
+ steps:
23
+ - uses: actions/checkout@v3
24
+ - name: Use Node.js ${{ matrix.node-version }}
25
+ uses: actions/setup-node@v3
26
+ with:
27
+ node-version: ${{ matrix.node-version }}
28
+ cache: 'npm'
29
+ - run: npm ci
30
+ - run: npm run build --if-present
31
+ - run: npm test
package/Gruntfile.js CHANGED
@@ -31,7 +31,8 @@ var projs = [
31
31
  'qsc',
32
32
  'robin',
33
33
  'geocent',
34
- 'tpers'
34
+ 'tpers',
35
+ 'geos'
35
36
  ];
36
37
  module.exports = function (grunt) {
37
38
  grunt.initConfig({
package/README.md CHANGED
@@ -23,12 +23,12 @@ If you do not want to download anything, Proj4js is also hosted on [cdnjs](https
23
23
  The basic signature is:
24
24
 
25
25
  ```javascript
26
- proj4(fromProjection[, toProjection, coordinates])
26
+ proj4([fromProjection, ]toProjection[, coordinates])
27
27
  ```
28
28
 
29
29
  Projections can be proj or wkt strings.
30
30
 
31
- Coordinates may an object of the form `{x:x,y:y}` or an array of the form `[x,y]`.
31
+ Coordinates may be an object of the form `{x:x,y:y}` or an array of the form `[x,y]`.
32
32
 
33
33
  When 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.
34
34
 
@@ -36,8 +36,15 @@ When all 3 arguments are given, the result is that the coordinates are transfor
36
36
  var 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]]';
37
37
  var secondProjection = "+proj=gnom +lat_0=90 +lon_0=0 +x_0=6300000 +y_0=6300000 +ellps=WGS84 +datum=WGS84 +units=m +no_defs";
38
38
  //I'm not going to redefine those two in latter examples.
39
- proj4(firstProjection,secondProjection,[2,5]);
40
- // [-2690666.2977344505, 3662659.885459918]
39
+ proj4(firstProjection,secondProjection,[-122.305887, 58.9465872]);
40
+ // [-2690575.447893817, 36622916.8071244564]
41
+ ```
42
+
43
+ The library can also parse coordinates provided with an elevation and measure, again as an object of the form `{x:x,y:y,z:z,m:m}` or an array of the form `[x,y,z,m]`.
44
+
45
+ ```javascript
46
+ proj4(firstProjection,secondProjection,[-122.305887, 58.9465872,10]);
47
+ // [-2690575.447893817, 36622916.8071244564, 10]
41
48
  ```
42
49
 
43
50
  If only 1 projection is given then it is assumed that it is being projected *from* WGS84 (fromProjection is WGS84).
@@ -50,10 +57,10 @@ proj4(firstProjection,[-71,41]);
50
57
  If 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.
51
58
 
52
59
  ```javascript
53
- proj4(firstProjection,secondProjection).forward([2,5]);
54
- // [-2690666.2977344505, 3662659.885459918]
55
- proj4(secondProjection,firstProjection).inverse([2,5]);
56
- // [-2690666.2977344505, 3662659.885459918]
60
+ proj4(firstProjection,secondProjection).forward([-122.305887, 58.9465872]);
61
+ // [-2690575.447893817, 36622916.8071244564]
62
+ proj4(secondProjection,firstProjection).inverse([-122.305887, 58.9465872]);
63
+ // [-2690575.447893817, 36622916.8071244564]
57
64
  ```
58
65
 
59
66
  And as above if only one projection is given, it's assumed to be coming from wgs84:
@@ -62,9 +69,9 @@ And as above if only one projection is given, it's assumed to be coming from wgs
62
69
  proj4(firstProjection).forward([-71,41]);
63
70
  // [242075.00535055372, 750123.32090043]
64
71
  proj4(firstProjection).inverse([242075.00535055372, 750123.32090043]);
65
- //[-71, 40.99999999999986]
66
- //the floating points to answer your question
72
+ // [-71, 40.99999999999986]
67
73
  ```
74
+ Note: The generation of the floating point value `40.99999999999986` in this example represents the fact that some variance in precision is involved in any conversion between one coordinate reference system and another.
68
75
 
69
76
  ## Named Projections
70
77
 
@@ -151,31 +158,31 @@ $ npm install --save @types/proj4
151
158
  ## Developing
152
159
  To set up build tools make sure you have node and grunt-cli installed and then run `npm install`.
153
160
 
154
- To do the complete build and browser tests run:
161
+ To do the complete build and browser tests run
155
162
 
156
163
  ```bash
157
164
  node_modules/.bin/grunt
158
165
  ```
159
166
 
160
- To run node tests run:
167
+ To run node tests run
161
168
 
162
169
  ```bash
163
170
  npm test
164
171
  ```
165
172
 
166
- To run node tests with coverage run:
173
+ To run node tests with coverage run
167
174
 
168
175
  ```bash
169
176
  npm test --coverage
170
177
  ```
171
178
 
172
- To create a build with only default projections (latlon and Mercator) run:
179
+ To create a build with only default projections (latlon and Mercator) run
173
180
 
174
181
  ```bash
175
182
  node_modules/.bin/grunt build
176
183
  ```
177
184
 
178
- To 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.:
185
+ To 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.
179
186
 
180
187
  ```bash
181
188
  node_modules/.bin/grunt build:tmerc
package/bower.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proj4",
3
- "version": "2.7.5",
3
+ "version": "2.8.1",
4
4
  "description": "Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.",
5
5
  "homepage": "https://github.com/proj4js/proj4js",
6
6
  "main": "dist/proj4.js",
package/component.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proj4",
3
- "version": "2.7.5",
3
+ "version": "2.8.1",
4
4
  "description": "Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.",
5
5
  "repo": "proj4js/proj4js",
6
6
  "keywords": [
package/dist/proj4-src.js CHANGED
@@ -229,7 +229,7 @@
229
229
  var ENDED = -1;
230
230
  var whitespace = /\s/;
231
231
  var latin = /[A-Za-z]/;
232
- var keyword = /[A-Za-z84]/;
232
+ var keyword = /[A-Za-z84_]/;
233
233
  var endThings = /[,\]]/;
234
234
  var digets = /[\d\.E\-\+]/;
235
235
  // const ignoredChar = /[\s_\-\/\(\)]/g;
@@ -1631,7 +1631,7 @@
1631
1631
  extend(this, json); // transfer everything over from the projection because we don't know what we'll need
1632
1632
  extend(this, ourProj); // transfer all the methods from the projection
1633
1633
 
1634
- // copy the 4 things over we calulated in deriveConstants.sphere
1634
+ // copy the 4 things over we calculated in deriveConstants.sphere
1635
1635
  this.a = sphere_.a;
1636
1636
  this.b = sphere_.b;
1637
1637
  this.rf = sphere_.rf;
@@ -2172,14 +2172,25 @@
2172
2172
  }
2173
2173
 
2174
2174
  function checkNotWGS(source, dest) {
2175
- return ((source.datum.datum_type === PJD_3PARAM || source.datum.datum_type === PJD_7PARAM) && dest.datumCode !== 'WGS84') || ((dest.datum.datum_type === PJD_3PARAM || dest.datum.datum_type === PJD_7PARAM) && source.datumCode !== 'WGS84');
2175
+ return (
2176
+ (source.datum.datum_type === PJD_3PARAM || source.datum.datum_type === PJD_7PARAM || source.datum.datum_type === PJD_GRIDSHIFT) && dest.datumCode !== 'WGS84') ||
2177
+ ((dest.datum.datum_type === PJD_3PARAM || dest.datum.datum_type === PJD_7PARAM || dest.datum.datum_type === PJD_GRIDSHIFT) && source.datumCode !== 'WGS84');
2176
2178
  }
2177
2179
 
2178
2180
  function transform(source, dest, point, enforceAxis) {
2179
2181
  var wgs84;
2180
2182
  if (Array.isArray(point)) {
2181
2183
  point = toPoint(point);
2184
+ } else {
2185
+ // Clone the point object so inputs don't get modified
2186
+ point = {
2187
+ x: point.x,
2188
+ y: point.y,
2189
+ z: point.z,
2190
+ m: point.m
2191
+ };
2182
2192
  }
2193
+ var hasZ = point.z !== undefined;
2183
2194
  checkSanity(point);
2184
2195
  // Workaround for datum shifts towgs84, if either source or destination projection is not wgs84
2185
2196
  if (source.datum && dest.datum && checkNotWGS(source, dest)) {
@@ -2254,6 +2265,9 @@
2254
2265
  return adjust_axis(dest, true, point);
2255
2266
  }
2256
2267
 
2268
+ if (!hasZ) {
2269
+ delete point.z;
2270
+ }
2257
2271
  return point;
2258
2272
  }
2259
2273
 
@@ -4370,7 +4384,9 @@
4370
4384
  "Lambert_Conformal_Conic",
4371
4385
  "Lambert_Conformal_Conic_1SP",
4372
4386
  "Lambert_Conformal_Conic_2SP",
4373
- "lcc"
4387
+ "lcc",
4388
+ "Lambert Conic Conformal (1SP)",
4389
+ "Lambert Conic Conformal (2SP)"
4374
4390
  ];
4375
4391
 
4376
4392
  var lcc = {
@@ -4954,18 +4970,18 @@
4954
4970
  this.t1 = this.sin_po;
4955
4971
  this.con = this.sin_po;
4956
4972
  this.ms1 = msfnz(this.e3, this.sin_po, this.cos_po);
4957
- this.qs1 = qsfnz(this.e3, this.sin_po, this.cos_po);
4973
+ this.qs1 = qsfnz(this.e3, this.sin_po);
4958
4974
 
4959
4975
  this.sin_po = Math.sin(this.lat2);
4960
4976
  this.cos_po = Math.cos(this.lat2);
4961
4977
  this.t2 = this.sin_po;
4962
4978
  this.ms2 = msfnz(this.e3, this.sin_po, this.cos_po);
4963
- this.qs2 = qsfnz(this.e3, this.sin_po, this.cos_po);
4979
+ this.qs2 = qsfnz(this.e3, this.sin_po);
4964
4980
 
4965
4981
  this.sin_po = Math.sin(this.lat0);
4966
4982
  this.cos_po = Math.cos(this.lat0);
4967
4983
  this.t3 = this.sin_po;
4968
- this.qs0 = qsfnz(this.e3, this.sin_po, this.cos_po);
4984
+ this.qs0 = qsfnz(this.e3, this.sin_po);
4969
4985
 
4970
4986
  if (Math.abs(this.lat1 - this.lat2) > EPSLN) {
4971
4987
  this.ns0 = (this.ms1 * this.ms1 - this.ms2 * this.ms2) / (this.qs2 - this.qs1);
@@ -4987,7 +5003,7 @@
4987
5003
  this.sin_phi = Math.sin(lat);
4988
5004
  this.cos_phi = Math.cos(lat);
4989
5005
 
4990
- var qs = qsfnz(this.e3, this.sin_phi, this.cos_phi);
5006
+ var qs = qsfnz(this.e3, this.sin_phi);
4991
5007
  var rh1 = this.a * Math.sqrt(this.c - this.ns0 * qs) / this.ns0;
4992
5008
  var theta = this.ns0 * adjust_lon(lon - this.long0);
4993
5009
  var x = rh1 * Math.sin(theta) + this.x0;
@@ -7126,6 +7142,163 @@
7126
7142
  names: names$31
7127
7143
  };
7128
7144
 
7145
+ function init$31() {
7146
+ this.flip_axis = (this.sweep === 'x' ? 1 : 0);
7147
+ this.h = Number(this.h);
7148
+ this.radius_g_1 = this.h / this.a;
7149
+
7150
+ if (this.radius_g_1 <= 0 || this.radius_g_1 > 1e10) {
7151
+ throw new Error();
7152
+ }
7153
+
7154
+ this.radius_g = 1.0 + this.radius_g_1;
7155
+ this.C = this.radius_g * this.radius_g - 1.0;
7156
+
7157
+ if (this.es !== 0.0) {
7158
+ var one_es = 1.0 - this.es;
7159
+ var rone_es = 1 / one_es;
7160
+
7161
+ this.radius_p = Math.sqrt(one_es);
7162
+ this.radius_p2 = one_es;
7163
+ this.radius_p_inv2 = rone_es;
7164
+
7165
+ this.shape = 'ellipse'; // Use as a condition in the forward and inverse functions.
7166
+ } else {
7167
+ this.radius_p = 1.0;
7168
+ this.radius_p2 = 1.0;
7169
+ this.radius_p_inv2 = 1.0;
7170
+
7171
+ this.shape = 'sphere'; // Use as a condition in the forward and inverse functions.
7172
+ }
7173
+
7174
+ if (!this.title) {
7175
+ this.title = "Geostationary Satellite View";
7176
+ }
7177
+ }
7178
+
7179
+ function forward$30(p) {
7180
+ var lon = p.x;
7181
+ var lat = p.y;
7182
+ var tmp, v_x, v_y, v_z;
7183
+ lon = lon - this.long0;
7184
+
7185
+ if (this.shape === 'ellipse') {
7186
+ lat = Math.atan(this.radius_p2 * Math.tan(lat));
7187
+ var r = this.radius_p / hypot(this.radius_p * Math.cos(lat), Math.sin(lat));
7188
+
7189
+ v_x = r * Math.cos(lon) * Math.cos(lat);
7190
+ v_y = r * Math.sin(lon) * Math.cos(lat);
7191
+ v_z = r * Math.sin(lat);
7192
+
7193
+ if (((this.radius_g - v_x) * v_x - v_y * v_y - v_z * v_z * this.radius_p_inv2) < 0.0) {
7194
+ p.x = Number.NaN;
7195
+ p.y = Number.NaN;
7196
+ return p;
7197
+ }
7198
+
7199
+ tmp = this.radius_g - v_x;
7200
+ if (this.flip_axis) {
7201
+ p.x = this.radius_g_1 * Math.atan(v_y / hypot(v_z, tmp));
7202
+ p.y = this.radius_g_1 * Math.atan(v_z / tmp);
7203
+ } else {
7204
+ p.x = this.radius_g_1 * Math.atan(v_y / tmp);
7205
+ p.y = this.radius_g_1 * Math.atan(v_z / hypot(v_y, tmp));
7206
+ }
7207
+ } else if (this.shape === 'sphere') {
7208
+ tmp = Math.cos(lat);
7209
+ v_x = Math.cos(lon) * tmp;
7210
+ v_y = Math.sin(lon) * tmp;
7211
+ v_z = Math.sin(lat);
7212
+ tmp = this.radius_g - v_x;
7213
+
7214
+ if (this.flip_axis) {
7215
+ p.x = this.radius_g_1 * Math.atan(v_y / hypot(v_z, tmp));
7216
+ p.y = this.radius_g_1 * Math.atan(v_z / tmp);
7217
+ } else {
7218
+ p.x = this.radius_g_1 * Math.atan(v_y / tmp);
7219
+ p.y = this.radius_g_1 * Math.atan(v_z / hypot(v_y, tmp));
7220
+ }
7221
+ }
7222
+ p.x = p.x * this.a;
7223
+ p.y = p.y * this.a;
7224
+ return p;
7225
+ }
7226
+
7227
+ function inverse$30(p) {
7228
+ var v_x = -1.0;
7229
+ var v_y = 0.0;
7230
+ var v_z = 0.0;
7231
+ var a, b, det, k;
7232
+
7233
+ p.x = p.x / this.a;
7234
+ p.y = p.y / this.a;
7235
+
7236
+ if (this.shape === 'ellipse') {
7237
+ if (this.flip_axis) {
7238
+ v_z = Math.tan(p.y / this.radius_g_1);
7239
+ v_y = Math.tan(p.x / this.radius_g_1) * hypot(1.0, v_z);
7240
+ } else {
7241
+ v_y = Math.tan(p.x / this.radius_g_1);
7242
+ v_z = Math.tan(p.y / this.radius_g_1) * hypot(1.0, v_y);
7243
+ }
7244
+
7245
+ var v_zp = v_z / this.radius_p;
7246
+ a = v_y * v_y + v_zp * v_zp + v_x * v_x;
7247
+ b = 2 * this.radius_g * v_x;
7248
+ det = (b * b) - 4 * a * this.C;
7249
+
7250
+ if (det < 0.0) {
7251
+ p.x = Number.NaN;
7252
+ p.y = Number.NaN;
7253
+ return p;
7254
+ }
7255
+
7256
+ k = (-b - Math.sqrt(det)) / (2.0 * a);
7257
+ v_x = this.radius_g + k * v_x;
7258
+ v_y *= k;
7259
+ v_z *= k;
7260
+
7261
+ p.x = Math.atan2(v_y, v_x);
7262
+ p.y = Math.atan(v_z * Math.cos(p.x) / v_x);
7263
+ p.y = Math.atan(this.radius_p_inv2 * Math.tan(p.y));
7264
+ } else if (this.shape === 'sphere') {
7265
+ if (this.flip_axis) {
7266
+ v_z = Math.tan(p.y / this.radius_g_1);
7267
+ v_y = Math.tan(p.x / this.radius_g_1) * Math.sqrt(1.0 + v_z * v_z);
7268
+ } else {
7269
+ v_y = Math.tan(p.x / this.radius_g_1);
7270
+ v_z = Math.tan(p.y / this.radius_g_1) * Math.sqrt(1.0 + v_y * v_y);
7271
+ }
7272
+
7273
+ a = v_y * v_y + v_z * v_z + v_x * v_x;
7274
+ b = 2 * this.radius_g * v_x;
7275
+ det = (b * b) - 4 * a * this.C;
7276
+ if (det < 0.0) {
7277
+ p.x = Number.NaN;
7278
+ p.y = Number.NaN;
7279
+ return p;
7280
+ }
7281
+
7282
+ k = (-b - Math.sqrt(det)) / (2.0 * a);
7283
+ v_x = this.radius_g + k * v_x;
7284
+ v_y *= k;
7285
+ v_z *= k;
7286
+
7287
+ p.x = Math.atan2(v_y, v_x);
7288
+ p.y = Math.atan(v_z * Math.cos(p.x) / v_x);
7289
+ }
7290
+ p.x = p.x + this.long0;
7291
+ return p;
7292
+ }
7293
+
7294
+ var names$32 = ["Geostationary Satellite View", "Geostationary_Satellite", "geos"];
7295
+ var geos = {
7296
+ init: init$31,
7297
+ forward: forward$30,
7298
+ inverse: inverse$30,
7299
+ names: names$32,
7300
+ };
7301
+
7129
7302
  var includedProjections = function(proj4){
7130
7303
  proj4.Proj.projections.add(tmerc);
7131
7304
  proj4.Proj.projections.add(etmerc);
@@ -7155,6 +7328,7 @@
7155
7328
  proj4.Proj.projections.add(robin);
7156
7329
  proj4.Proj.projections.add(geocent);
7157
7330
  proj4.Proj.projections.add(tpers);
7331
+ proj4.Proj.projections.add(geos);
7158
7332
  };
7159
7333
 
7160
7334
  proj4$1.defaultDatum = 'WGS84'; //default datum
@@ -7166,7 +7340,7 @@
7166
7340
  proj4$1.nadgrid = nadgrid;
7167
7341
  proj4$1.transform = transform;
7168
7342
  proj4$1.mgrs = mgrs;
7169
- proj4$1.version = '2.7.5';
7343
+ proj4$1.version = '2.8.1';
7170
7344
  includedProjections(proj4$1);
7171
7345
 
7172
7346
  return proj4$1;