proj4 2.15.0 → 2.16.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.
Files changed (127) hide show
  1. package/.github/workflows/build-and-test.yml +45 -7
  2. package/.nyc_output/6b047fc9-1bf2-4565-9e8a-9c0defc09dd7.json +1 -0
  3. package/.nyc_output/e2c5d0cc-9478-4f26-ad2f-de246d4c35de.json +1 -0
  4. package/.nyc_output/f4b0e40f-04ca-4b6d-bfeb-51d617db9841.json +1 -0
  5. package/.nyc_output/processinfo/6b047fc9-1bf2-4565-9e8a-9c0defc09dd7.json +1 -0
  6. package/.nyc_output/processinfo/e2c5d0cc-9478-4f26-ad2f-de246d4c35de.json +1 -0
  7. package/.nyc_output/processinfo/f4b0e40f-04ca-4b6d-bfeb-51d617db9841.json +1 -0
  8. package/.nyc_output/processinfo/index.json +1 -0
  9. package/Gruntfile.js +20 -84
  10. package/README.md +20 -6
  11. package/bower.json +1 -1
  12. package/component.json +1 -1
  13. package/dist/proj4-src.js +8934 -7083
  14. package/dist/proj4.js +1 -1
  15. package/eslint.config.mjs +41 -0
  16. package/lib/Point.js +4 -4
  17. package/lib/Proj.js +7 -8
  18. package/lib/adjust_axis.js +30 -33
  19. package/lib/common/acosh.js +2 -2
  20. package/lib/common/adjust_lat.js +2 -2
  21. package/lib/common/adjust_lon.js +2 -3
  22. package/lib/common/adjust_zone.js +1 -1
  23. package/lib/common/asinh.js +2 -2
  24. package/lib/common/asinhy.js +1 -1
  25. package/lib/common/asinz.js +2 -2
  26. package/lib/common/atanh.js +2 -2
  27. package/lib/common/clens.js +1 -1
  28. package/lib/common/clens_cmplx.js +1 -1
  29. package/lib/common/cosh.js +2 -2
  30. package/lib/common/e0fn.js +2 -2
  31. package/lib/common/e1fn.js +2 -2
  32. package/lib/common/e2fn.js +2 -2
  33. package/lib/common/e3fn.js +2 -2
  34. package/lib/common/fL.js +2 -2
  35. package/lib/common/gN.js +2 -2
  36. package/lib/common/gatg.js +1 -1
  37. package/lib/common/hypot.js +1 -1
  38. package/lib/common/imlfn.js +3 -3
  39. package/lib/common/invlatiso.js +2 -2
  40. package/lib/common/iqsfnz.js +5 -6
  41. package/lib/common/latiso.js +2 -2
  42. package/lib/common/log1py.js +1 -1
  43. package/lib/common/mlfn.js +2 -2
  44. package/lib/common/msfnz.js +2 -2
  45. package/lib/common/phi2z.js +3 -3
  46. package/lib/common/pj_enfn.js +2 -2
  47. package/lib/common/pj_inv_mlfn.js +6 -6
  48. package/lib/common/pj_mlfn.js +2 -2
  49. package/lib/common/qsfnz.js +3 -4
  50. package/lib/common/sign.js +3 -3
  51. package/lib/common/sinh.js +2 -2
  52. package/lib/common/srat.js +2 -2
  53. package/lib/common/tanh.js +2 -2
  54. package/lib/common/toPoint.js +4 -4
  55. package/lib/common/tsfnz.js +2 -2
  56. package/lib/constants/Datum.js +1228 -46
  57. package/lib/constants/Ellipsoid.js +225 -266
  58. package/lib/constants/PrimeMeridian.js +14 -14
  59. package/lib/constants/units.js +20 -20
  60. package/lib/constants/values.js +4 -4
  61. package/lib/core.js +2 -2
  62. package/lib/datum.js +2 -2
  63. package/lib/datumUtils.js +9 -14
  64. package/lib/datum_transform.js +26 -26
  65. package/lib/defs.js +10 -20
  66. package/lib/deriveConstants.js +4 -2
  67. package/lib/extend.js +1 -1
  68. package/lib/global.js +6 -6
  69. package/lib/includedProjections.js +25 -25
  70. package/lib/index.js +9 -9
  71. package/lib/nadgrid.js +36 -14
  72. package/lib/parseCode.js +10 -11
  73. package/lib/projString.js +41 -44
  74. package/lib/projections/aea.js +7 -12
  75. package/lib/projections/aeqd.js +51 -86
  76. package/lib/projections/bonne.js +11 -13
  77. package/lib/projections/cass.js +8 -15
  78. package/lib/projections/cea.js +7 -9
  79. package/lib/projections/eqc.js +2 -5
  80. package/lib/projections/eqdc.js +10 -16
  81. package/lib/projections/eqearth.js +17 -17
  82. package/lib/projections/equi.js +4 -6
  83. package/lib/projections/etmerc.js +9 -11
  84. package/lib/projections/gauss.js +3 -3
  85. package/lib/projections/geocent.js +13 -14
  86. package/lib/projections/geos.js +136 -137
  87. package/lib/projections/gnom.js +8 -13
  88. package/lib/projections/gstmerc.js +2 -5
  89. package/lib/projections/krovak.js +3 -3
  90. package/lib/projections/laea.js +85 -97
  91. package/lib/projections/lcc.js +28 -33
  92. package/lib/projections/longlat.js +4 -4
  93. package/lib/projections/merc.js +12 -19
  94. package/lib/projections/mill.js +6 -7
  95. package/lib/projections/moll.js +8 -9
  96. package/lib/projections/nzmg.js +2 -2
  97. package/lib/projections/omerc.js +55 -57
  98. package/lib/projections/ortho.js +9 -10
  99. package/lib/projections/poly.js +13 -21
  100. package/lib/projections/qsc.js +19 -21
  101. package/lib/projections/robin.js +118 -118
  102. package/lib/projections/sinu.js +12 -23
  103. package/lib/projections/somerc.js +3 -3
  104. package/lib/projections/stere.js +29 -41
  105. package/lib/projections/sterea.js +3 -4
  106. package/lib/projections/tmerc.js +29 -36
  107. package/lib/projections/tpers.js +14 -15
  108. package/lib/projections/utm.js +3 -4
  109. package/lib/projections/vandg.js +15 -21
  110. package/lib/projections.js +12 -4
  111. package/lib/transform.js +3 -3
  112. package/package.json +29 -22
  113. package/projs.js +2 -2
  114. package/publish.sh +2 -2
  115. package/rollup.config.mjs +29 -0
  116. package/scripts/readme.md +10 -0
  117. package/scripts/updateDatums.mjs +119 -0
  118. package/scripts/updateEllipsoids.mjs +70 -0
  119. package/test/ntv2_0_downsampled_no_error_columns.gsb +0 -0
  120. package/test/opt.html +27 -24
  121. package/test/puppeteer-tests.mjs +110 -0
  122. package/test/test-ci.mjs +10 -0
  123. package/test/test.js +197 -125
  124. package/test/testData.js +1802 -312
  125. package/.jshintrc +0 -12
  126. package/test/amd.html +0 -63
  127. package/test/package.json.js +0 -1
@@ -6,7 +6,7 @@ import pj_mlfn from '../common/pj_mlfn';
6
6
  import pj_inv_mlfn from '../common/pj_inv_mlfn';
7
7
  import adjust_lon from '../common/adjust_lon';
8
8
 
9
- import {EPSLN, HALF_PI} from '../constants/values';
9
+ import { EPSLN, HALF_PI } from '../constants/values';
10
10
  import sign from '../common/sign';
11
11
 
12
12
  export function init() {
@@ -40,8 +40,7 @@ export function forward(p) {
40
40
 
41
41
  if ((Math.abs(Math.abs(b) - 1)) < EPSLN) {
42
42
  return (93);
43
- }
44
- else {
43
+ } else {
45
44
  x = 0.5 * this.a * this.k0 * Math.log((1 + b) / (1 - b)) + this.x0;
46
45
  y = cos_phi * Math.cos(delta_lon) / Math.sqrt(1 - Math.pow(b, 2));
47
46
  b = Math.abs(y);
@@ -49,12 +48,10 @@ export function forward(p) {
49
48
  if (b >= 1) {
50
49
  if ((b - 1) > EPSLN) {
51
50
  return (93);
52
- }
53
- else {
51
+ } else {
54
52
  y = 0;
55
53
  }
56
- }
57
- else {
54
+ } else {
58
55
  y = Math.acos(y);
59
56
  }
60
57
 
@@ -64,8 +61,7 @@ export function forward(p) {
64
61
 
65
62
  y = this.a * this.k0 * (y - this.lat0) + this.y0;
66
63
  }
67
- }
68
- else {
64
+ } else {
69
65
  var al = cos_phi * delta_lon;
70
66
  var als = Math.pow(al, 2);
71
67
  var c = this.ep2 * Math.pow(cos_phi, 2);
@@ -77,18 +73,18 @@ export function forward(p) {
77
73
  al = al / Math.sqrt(con);
78
74
  var ml = pj_mlfn(lat, sin_phi, cos_phi, this.en);
79
75
 
80
- x = this.a * (this.k0 * al * (1 +
81
- als / 6 * (1 - t + c +
82
- als / 20 * (5 - 18 * t + ts + 14 * c - 58 * t * c +
83
- als / 42 * (61 + 179 * ts - ts * t - 479 * t))))) +
84
- this.x0;
85
-
86
- y = this.a * (this.k0 * (ml - this.ml0 +
87
- sin_phi * delta_lon * al / 2 * (1 +
88
- als / 12 * (5 - t + 9 * c + 4 * cs +
89
- als / 30 * (61 + ts - 58 * t + 270 * c - 330 * t * c +
90
- als / 56 * (1385 + 543 * ts - ts * t - 3111 * t)))))) +
91
- this.y0;
76
+ x = this.a * (this.k0 * al * (1
77
+ + als / 6 * (1 - t + c
78
+ + als / 20 * (5 - 18 * t + ts + 14 * c - 58 * t * c
79
+ + als / 42 * (61 + 179 * ts - ts * t - 479 * t)))))
80
+ + this.x0;
81
+
82
+ y = this.a * (this.k0 * (ml - this.ml0
83
+ + sin_phi * delta_lon * al / 2 * (1
84
+ + als / 12 * (5 - t + 9 * c + 4 * cs
85
+ + als / 30 * (61 + ts - 58 * t + 270 * c - 330 * t * c
86
+ + als / 56 * (1385 + 543 * ts - ts * t - 3111 * t))))))
87
+ + this.y0;
92
88
  }
93
89
 
94
90
  p.x = x;
@@ -120,12 +116,10 @@ export function inverse(p) {
120
116
 
121
117
  if ((g === 0) && (h === 0)) {
122
118
  lon = 0;
123
- }
124
- else {
119
+ } else {
125
120
  lon = adjust_lon(Math.atan2(g, h) + this.long0);
126
121
  }
127
- }
128
- else { // ellipsoidal form
122
+ } else { // ellipsoidal form
129
123
  con = this.ml0 + y / this.k0;
130
124
  phi = pj_inv_mlfn(con, this.es, this.en);
131
125
 
@@ -142,17 +136,16 @@ export function inverse(p) {
142
136
  var ds = Math.pow(d, 2);
143
137
  con = con * tan_phi;
144
138
 
145
- lat = phi - (con * ds / (1 - this.es)) * 0.5 * (1 -
146
- ds / 12 * (5 + 3 * t - 9 * c * t + c - 4 * cs -
147
- ds / 30 * (61 + 90 * t - 252 * c * t + 45 * ts + 46 * c -
148
- ds / 56 * (1385 + 3633 * t + 4095 * ts + 1574 * ts * t))));
139
+ lat = phi - (con * ds / (1 - this.es)) * 0.5 * (1
140
+ - ds / 12 * (5 + 3 * t - 9 * c * t + c - 4 * cs
141
+ - ds / 30 * (61 + 90 * t - 252 * c * t + 45 * ts + 46 * c
142
+ - ds / 56 * (1385 + 3633 * t + 4095 * ts + 1574 * ts * t))));
149
143
 
150
- lon = adjust_lon(this.long0 + (d * (1 -
151
- ds / 6 * (1 + 2 * t + c -
152
- ds / 20 * (5 + 28 * t + 24 * ts + 8 * c * t + 6 * c -
153
- ds / 42 * (61 + 662 * t + 1320 * ts + 720 * ts * t)))) / cos_phi));
154
- }
155
- else {
144
+ lon = adjust_lon(this.long0 + (d * (1
145
+ - ds / 6 * (1 + 2 * t + c
146
+ - ds / 20 * (5 + 28 * t + 24 * ts + 8 * c * t + 6 * c
147
+ - ds / 42 * (61 + 662 * t + 1320 * ts + 720 * ts * t)))) / cos_phi));
148
+ } else {
156
149
  lat = HALF_PI * sign(y);
157
150
  lon = 0;
158
151
  }
@@ -164,7 +157,7 @@ export function inverse(p) {
164
157
  return p;
165
158
  }
166
159
 
167
- export var names = ["Fast_Transverse_Mercator", "Fast Transverse Mercator"];
160
+ export var names = ['Fast_Transverse_Mercator', 'Fast Transverse Mercator'];
168
161
  export default {
169
162
  init: init,
170
163
  forward: forward,
@@ -1,4 +1,3 @@
1
-
2
1
  var mode = {
3
2
  N_POLE: 0,
4
3
  S_POLE: 1,
@@ -6,23 +5,23 @@ var mode = {
6
5
  OBLIQ: 3
7
6
  };
8
7
 
9
- import { D2R, HALF_PI, EPSLN } from "../constants/values";
10
- import hypot from "../common/hypot";
8
+ import { D2R, HALF_PI, EPSLN } from '../constants/values';
9
+ import hypot from '../common/hypot';
11
10
 
12
11
  var params = {
13
- h: { def: 100000, num: true }, // default is Karman line, no default in PROJ.7
14
- azi: { def: 0, num: true, degrees: true }, // default is North
15
- tilt: { def: 0, num: true, degrees: true }, // default is Nadir
16
- long0: { def: 0, num: true }, // default is Greenwich, conversion to rad is automatic
17
- lat0: { def: 0, num: true } // default is Equator, conversion to rad is automatic
12
+ h: { def: 100000, num: true }, // default is Karman line, no default in PROJ.7
13
+ azi: { def: 0, num: true, degrees: true }, // default is North
14
+ tilt: { def: 0, num: true, degrees: true }, // default is Nadir
15
+ long0: { def: 0, num: true }, // default is Greenwich, conversion to rad is automatic
16
+ lat0: { def: 0, num: true } // default is Equator, conversion to rad is automatic
18
17
  };
19
18
 
20
19
  export function init() {
21
20
  Object.keys(params).forEach(function (p) {
22
- if (typeof this[p] === "undefined") {
21
+ if (typeof this[p] === 'undefined') {
23
22
  this[p] = params[p].def;
24
23
  } else if (params[p].num && isNaN(this[p])) {
25
- throw new Error("Invalid parameter value, must be numeric " + p + " = " + this[p]);
24
+ throw new Error('Invalid parameter value, must be numeric ' + p + ' = ' + this[p]);
26
25
  } else if (params[p].num) {
27
26
  this[p] = parseFloat(this[p]);
28
27
  }
@@ -41,12 +40,12 @@ export function init() {
41
40
  this.cosph0 = Math.cos(this.lat0);
42
41
  }
43
42
 
44
- this.pn1 = this.h / this.a; // Normalize relative to the Earth's radius
43
+ this.pn1 = this.h / this.a; // Normalize relative to the Earth's radius
45
44
 
46
45
  if (this.pn1 <= 0 || this.pn1 > 1e10) {
47
- throw new Error("Invalid height");
46
+ throw new Error('Invalid height');
48
47
  }
49
-
48
+
50
49
  this.p = 1 + this.pn1;
51
50
  this.rp = 1 / this.p;
52
51
  this.h1 = 1 / this.pn1;
@@ -99,7 +98,7 @@ export function forward(p) {
99
98
  break;
100
99
  }
101
100
 
102
- // Tilt
101
+ // Tilt
103
102
  var yt, ba;
104
103
  yt = y * this.cg + x * this.sg;
105
104
  ba = 1 / (yt * this.sw * this.h1 + this.cw);
@@ -160,7 +159,7 @@ export function inverse(p) {
160
159
  return p;
161
160
  }
162
161
 
163
- export var names = ["Tilted_Perspective", "tpers"];
162
+ export var names = ['Tilted_Perspective', 'tpers'];
164
163
  export default {
165
164
  init: init,
166
165
  forward: forward,
@@ -1,8 +1,7 @@
1
1
  import adjust_zone from '../common/adjust_zone';
2
2
  import etmerc from './etmerc';
3
3
  export var dependsOn = 'etmerc';
4
- import {D2R} from '../constants/values';
5
-
4
+ import { D2R } from '../constants/values';
6
5
 
7
6
  export function init() {
8
7
  var zone = adjust_zone(this.zone, this.long0);
@@ -10,7 +9,7 @@ export function init() {
10
9
  throw new Error('unknown utm zone');
11
10
  }
12
11
  this.lat0 = 0;
13
- this.long0 = ((6 * Math.abs(zone)) - 183) * D2R;
12
+ this.long0 = ((6 * Math.abs(zone)) - 183) * D2R;
14
13
  this.x0 = 500000;
15
14
  this.y0 = this.utmSouth ? 10000000 : 0;
16
15
  this.k0 = 0.9996;
@@ -20,7 +19,7 @@ export function init() {
20
19
  this.inverse = etmerc.inverse;
21
20
  }
22
21
 
23
- export var names = ["Universal Transverse Mercator System", "utm"];
22
+ export var names = ['Universal Transverse Mercator System', 'utm'];
24
23
  export default {
25
24
  init: init,
26
25
  names: names,
@@ -1,23 +1,22 @@
1
1
  import adjust_lon from '../common/adjust_lon';
2
2
 
3
- import {HALF_PI, EPSLN} from '../constants/values';
3
+ import { HALF_PI, EPSLN } from '../constants/values';
4
4
 
5
5
  import asinz from '../common/asinz';
6
6
 
7
7
  /* Initialize the Van Der Grinten projection
8
- ----------------------------------------*/
8
+ ---------------------------------------- */
9
9
  export function init() {
10
- //this.R = 6370997; //Radius of earth
10
+ // this.R = 6370997; //Radius of earth
11
11
  this.R = this.a;
12
12
  }
13
13
 
14
14
  export function forward(p) {
15
-
16
15
  var lon = p.x;
17
16
  var lat = p.y;
18
17
 
19
18
  /* Forward equations
20
- -----------------*/
19
+ ----------------- */
21
20
  var dlon = adjust_lon(lon - this.long0);
22
21
  var x, y;
23
22
 
@@ -30,8 +29,7 @@ export function forward(p) {
30
29
  x = this.x0;
31
30
  if (lat >= 0) {
32
31
  y = this.y0 + Math.PI * this.R * Math.tan(0.5 * theta);
33
- }
34
- else {
32
+ } else {
35
33
  y = this.y0 + Math.PI * this.R * -Math.tan(0.5 * theta);
36
34
  }
37
35
  // return(OK);
@@ -50,15 +48,14 @@ export function forward(p) {
50
48
  con = -con;
51
49
  }
52
50
  x = this.x0 + con;
53
- //con = Math.abs(con / (Math.PI * this.R));
51
+ // con = Math.abs(con / (Math.PI * this.R));
54
52
  var q = asq + g;
55
53
  con = Math.PI * this.R * (m * q - al * Math.sqrt((msq + asq) * (asq + 1) - q * q)) / (msq + asq);
56
54
  if (lat >= 0) {
57
- //y = this.y0 + Math.PI * this.R * Math.sqrt(1 - con * con - 2 * al * con);
55
+ // y = this.y0 + Math.PI * this.R * Math.sqrt(1 - con * con - 2 * al * con);
58
56
  y = this.y0 + con;
59
- }
60
- else {
61
- //y = this.y0 - Math.PI * this.R * Math.sqrt(1 - con * con - 2 * al * con);
57
+ } else {
58
+ // y = this.y0 - Math.PI * this.R * Math.sqrt(1 - con * con - 2 * al * con);
62
59
  y = this.y0 - con;
63
60
  }
64
61
  p.x = x;
@@ -67,7 +64,7 @@ export function forward(p) {
67
64
  }
68
65
 
69
66
  /* Van Der Grinten inverse equations--mapping x,y to lat/long
70
- ---------------------------------------------------------*/
67
+ --------------------------------------------------------- */
71
68
  export function inverse(p) {
72
69
  var lon, lat;
73
70
  var xx, yy, xys, c1, c2, c3;
@@ -78,7 +75,7 @@ export function inverse(p) {
78
75
  var d;
79
76
 
80
77
  /* inverse equations
81
- -----------------*/
78
+ ----------------- */
82
79
  p.x -= this.x0;
83
80
  p.y -= this.y0;
84
81
  con = Math.PI * this.R;
@@ -95,23 +92,20 @@ export function inverse(p) {
95
92
  if (Math.abs(con) > 1) {
96
93
  if (con >= 0) {
97
94
  con = 1;
98
- }
99
- else {
95
+ } else {
100
96
  con = -1;
101
97
  }
102
98
  }
103
99
  th1 = Math.acos(con) / 3;
104
100
  if (p.y >= 0) {
105
101
  lat = (-m1 * Math.cos(th1 + Math.PI / 3) - c2 / 3 / c3) * Math.PI;
106
- }
107
- else {
102
+ } else {
108
103
  lat = -(-m1 * Math.cos(th1 + Math.PI / 3) - c2 / 3 / c3) * Math.PI;
109
104
  }
110
105
 
111
106
  if (Math.abs(xx) < EPSLN) {
112
107
  lon = this.long0;
113
- }
114
- else {
108
+ } else {
115
109
  lon = adjust_lon(this.long0 + Math.PI * (xys - 1 + Math.sqrt(1 + 2 * (xx * xx - yy * yy) + xys * xys)) / 2 / xx);
116
110
  }
117
111
 
@@ -120,7 +114,7 @@ export function inverse(p) {
120
114
  return p;
121
115
  }
122
116
 
123
- export var names = ["Van_der_Grinten_I", "VanDerGrinten", "vandg"];
117
+ export var names = ['Van_der_Grinten_I', 'VanDerGrinten', 'Van_der_Grinten', 'vandg'];
124
118
  export default {
125
119
  init: init,
126
120
  forward: forward,
@@ -1,5 +1,5 @@
1
- import merc from "./projections/merc";
2
- import longlat from "./projections/longlat";
1
+ import merc from './projections/merc';
2
+ import longlat from './projections/longlat';
3
3
  var projs = [merc, longlat];
4
4
  var names = {};
5
5
  var projStore = [];
@@ -11,13 +11,17 @@ function add(proj, i) {
11
11
  return true;
12
12
  }
13
13
  projStore[len] = proj;
14
- proj.names.forEach(function(n) {
14
+ proj.names.forEach(function (n) {
15
15
  names[n.toLowerCase()] = len;
16
16
  });
17
17
  return this;
18
18
  }
19
19
 
20
- export {add};
20
+ export { add };
21
+
22
+ export function getNormalizedProjName(n) {
23
+ return n.replace(/[-\(\)\s]+/g, ' ').trim().replace(/ /g, '_');
24
+ }
21
25
 
22
26
  export function get(name) {
23
27
  if (!name) {
@@ -27,6 +31,10 @@ export function get(name) {
27
31
  if (typeof names[n] !== 'undefined' && projStore[names[n]]) {
28
32
  return projStore[names[n]];
29
33
  }
34
+ n = getNormalizedProjName(n);
35
+ if (n in names && projStore[names[n]]) {
36
+ return projStore[names[n]];
37
+ }
30
38
  }
31
39
 
32
40
  export function start() {
package/lib/transform.js CHANGED
@@ -1,4 +1,4 @@
1
- import {D2R, R2D, PJD_3PARAM, PJD_7PARAM, PJD_GRIDSHIFT} from './constants/values';
1
+ import { D2R, R2D, PJD_3PARAM, PJD_7PARAM, PJD_GRIDSHIFT } from './constants/values';
2
2
  import datum_transform from './datum_transform';
3
3
  import adjust_axis from './adjust_axis';
4
4
  import proj from './Proj';
@@ -7,8 +7,8 @@ import checkSanity from './checkSanity';
7
7
 
8
8
  function checkNotWGS(source, dest) {
9
9
  return (
10
- (source.datum.datum_type === PJD_3PARAM || source.datum.datum_type === PJD_7PARAM || source.datum.datum_type === PJD_GRIDSHIFT) && dest.datumCode !== 'WGS84') ||
11
- ((dest.datum.datum_type === PJD_3PARAM || dest.datum.datum_type === PJD_7PARAM || dest.datum.datum_type === PJD_GRIDSHIFT) && source.datumCode !== 'WGS84');
10
+ (source.datum.datum_type === PJD_3PARAM || source.datum.datum_type === PJD_7PARAM || source.datum.datum_type === PJD_GRIDSHIFT) && dest.datumCode !== 'WGS84')
11
+ || ((dest.datum.datum_type === PJD_3PARAM || dest.datum.datum_type === PJD_7PARAM || dest.datum.datum_type === PJD_GRIDSHIFT) && source.datumCode !== 'WGS84');
12
12
  }
13
13
 
14
14
  export default function transform(source, dest, point, enforceAxis) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proj4",
3
- "version": "2.15.0",
3
+ "version": "2.16.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://proj4js.github.io/proj4js/",
6
6
  "main": "dist/proj4-src.js",
@@ -10,10 +10,18 @@
10
10
  "doc": "docs"
11
11
  },
12
12
  "scripts": {
13
- "prepare": "grunt",
14
- "build": "grunt",
15
- "build:tmerc": "grunt build:tmerc",
16
- "test": "npm run build && istanbul test node_modules/mocha/bin/_mocha test/test.js"
13
+ "prepare": "npm run build && npm run test:all",
14
+ "build": "grunt && npm run rollup",
15
+ "build:tmerc": "grunt build:tmerc && npm run rollup",
16
+ "rollup": "rollup -c",
17
+ "pretest": "npm run lint",
18
+ "lint": "eslint *.js *.mjs scripts lib test",
19
+ "format": "npm run lint -- --fix",
20
+ "test": "npm run build && npm run test:all",
21
+ "test:coverage": "nyc npm run test:ci",
22
+ "test:all": "npm run test:ci && npm run test:browser",
23
+ "test:browser": "node test/puppeteer-tests.mjs",
24
+ "test:ci": "npx -y mocha test/test-ci.mjs --reporter dot"
17
25
  },
18
26
  "repository": {
19
27
  "type": "git",
@@ -22,25 +30,24 @@
22
30
  "author": "",
23
31
  "license": "MIT",
24
32
  "devDependencies": {
25
- "chai": "~4.1.2",
26
- "curl-amd": "^0.8.12",
27
- "grunt": "^1.0.1",
28
- "grunt-cli": "~1.2.0",
29
- "grunt-contrib-connect": "~1.0.2",
30
- "grunt-contrib-jshint": "~3.2.0",
31
- "grunt-contrib-uglify": "~3.1.0",
32
- "grunt-mocha-phantomjs": "~4.0.0",
33
- "grunt-rollup": "^6.0.0",
34
- "istanbul": "~0.4.5",
35
- "mocha": "~4.0.0",
36
- "rollup": "^0.50.0",
37
- "rollup-plugin-json": "^2.3.0",
38
- "rollup-plugin-node-resolve": "^3.0.0",
39
- "rollup-plugin-replace": "^2.0.0",
40
- "tin": "~0.5.0"
33
+ "@rollup/plugin-commonjs": "^28.0.3",
34
+ "@rollup/plugin-json": "^6.1.0",
35
+ "@rollup/plugin-node-resolve": "^15.2.3",
36
+ "@rollup/plugin-replace": "^5.0.5",
37
+ "@rollup/plugin-terser": "^0.4.4",
38
+ "@stylistic/eslint-plugin": "^4.2.0",
39
+ "chai": "^5.0.0",
40
+ "eslint": "^9.25.1",
41
+ "grunt": "^1.6.1",
42
+ "grunt-cli": "^1.4.3",
43
+ "mocha": "^10.2.0",
44
+ "nyc": "^17.1.0",
45
+ "puppeteer": "^24.2.0",
46
+ "rollup": "^4.9.6"
41
47
  },
42
48
  "dependencies": {
49
+ "geographiclib-geodesic": "^2.1.1",
43
50
  "mgrs": "1.0.0",
44
- "wkt-parser": "^1.4.0"
51
+ "wkt-parser": "^1.5.0"
45
52
  }
46
53
  }
package/projs.js CHANGED
@@ -29,7 +29,7 @@ import tpers from './lib/projections/tpers';
29
29
  import geos from './lib/projections/geos';
30
30
  import eqearth from './lib/projections/eqearth';
31
31
  import bonne from './lib/projections/bonne';
32
- export default function(proj4){
32
+ export default function (proj4) {
33
33
  proj4.Proj.projections.add(tmerc);
34
34
  proj4.Proj.projections.add(etmerc);
35
35
  proj4.Proj.projections.add(utm);
@@ -61,4 +61,4 @@ export default function(proj4){
61
61
  proj4.Proj.projections.add(geos);
62
62
  proj4.Proj.projections.add(eqearth);
63
63
  proj4.Proj.projections.add(bonne);
64
- }
64
+ }
package/publish.sh CHANGED
@@ -5,13 +5,13 @@ VERSION=$(node -e "console.log(require('./package.json').version)")
5
5
 
6
6
  # Build
7
7
  git checkout -b build
8
- node_modules/.bin/grunt
8
+ npm run build
9
9
  git add dist -f
10
10
  git commit -m "build $VERSION"
11
11
 
12
12
  # Tag and push
13
13
  git tag -f v$VERSION -m "$VERSION"
14
- git push --tags git@github.com:proj4js/proj4js.git $VERSION
14
+ git push --tags git@github.com:proj4js/proj4js.git v$VERSION
15
15
 
16
16
  # Publish
17
17
  npm publish
@@ -0,0 +1,29 @@
1
+ import json from '@rollup/plugin-json';
2
+ import nodeResolve from '@rollup/plugin-node-resolve';
3
+ import terser from '@rollup/plugin-terser';
4
+ import replace from '@rollup/plugin-replace';
5
+ import commonjs from '@rollup/plugin-commonjs';
6
+
7
+ export default {
8
+ input: './lib/index.js',
9
+ output: [{
10
+ file: './dist/proj4-src.js',
11
+ format: 'umd',
12
+ name: 'proj4'
13
+ },
14
+ {
15
+ file: './dist/proj4.js',
16
+ format: 'umd',
17
+ name: 'proj4',
18
+ plugins: [terser()]
19
+ }],
20
+ plugins: [
21
+ replace({
22
+ preventAssignment: true,
23
+ __VERSION__: process.env.npm_package_version
24
+ }),
25
+ json(),
26
+ nodeResolve(),
27
+ commonjs()
28
+ ]
29
+ };
@@ -0,0 +1,10 @@
1
+ The script in this directory can be used to update `lib/constants/Datum.js` with data from a [`proj.db`](https://proj.org/en/stable/resource_files.html#proj-db) file placed in the root of the repository.
2
+
3
+ After running the script, the formatting needs to be fixed.
4
+
5
+ A complete command sequence (issued from the root of the repository) would look like this:
6
+
7
+ npm install sqlite3
8
+ node scripts/updateDatums.mjs
9
+ npm uninstall sqlite3
10
+ npm run format
@@ -0,0 +1,119 @@
1
+ import sqlite3 from 'sqlite3';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import { fileURLToPath } from 'url';
5
+ import datums from '../lib/constants/Datum.js'; // Import the datums object directly
6
+
7
+ const DATUM_OVERRIDES = {
8
+ EPSG_4149: {
9
+ towgs84: '674.374,15.056,405.346'
10
+ },
11
+ EPSG_4267: {
12
+ towgs84: '-8.0,160.0,176.0'
13
+ },
14
+ EPSG_4818: {
15
+ towgs84: '589,76,480'
16
+ }
17
+ };
18
+
19
+ // Get the current file's directory
20
+ const __filename = fileURLToPath(import.meta.url);
21
+ const __dirname = path.dirname(__filename);
22
+
23
+ // Open proj.db
24
+ const dbPath = path.resolve(__dirname, '../proj.db');
25
+ const db = new sqlite3.Database(dbPath);
26
+
27
+ for (const key in datums) {
28
+ if (key === datums[key].datumName && datums[datums[key].datumName] === datums[key]) {
29
+ delete datums[key];
30
+ }
31
+ }
32
+
33
+ const databaseDatumNames = new Set();
34
+
35
+ // Query proj.db for Helmert transforms with method_code = 9606
36
+ db.all(
37
+ `SELECT ht.source_crs_auth_name,
38
+ ht.source_crs_code,
39
+ ht.tx, ht.ty, ht.tz,
40
+ ht.rx, ht.ry, ht.rz,
41
+ ht.scale_difference,
42
+ ht.accuracy,
43
+ gd.name AS datum_name,
44
+ cv.name AS datum_code,
45
+ e.name AS ellipse_name,
46
+ ht.method_code
47
+ FROM helmert_transformation ht
48
+ JOIN crs_view cv
49
+ ON ht.source_crs_auth_name = cv.auth_name
50
+ AND ht.source_crs_code = cv.code
51
+ JOIN geodetic_crs gcrs
52
+ ON cv.table_name = 'geodetic_crs'
53
+ AND cv.auth_name = gcrs.auth_name
54
+ AND cv.code = gcrs.code
55
+ JOIN geodetic_datum gd
56
+ ON gcrs.datum_auth_name = gd.auth_name
57
+ AND gcrs.datum_code = gd.code
58
+ JOIN ellipsoid e
59
+ ON gd.ellipsoid_auth_name = e.auth_name
60
+ AND gd.ellipsoid_code = e.code
61
+ WHERE ht.deprecated = 0
62
+ AND ht.method_code IN (9606, 9607, 9603)
63
+ AND (ht.target_crs_auth_name = 'EPSG' AND ht.target_crs_code IN ('4326', '7019', '4258')) -- WGS84, GRS80, ETRS89
64
+ AND cv.type != 'vertical' -- Exclude vertical datums
65
+ ORDER BY
66
+ ht.accuracy ASC,
67
+ CASE ht.method_code
68
+ WHEN 9606 THEN 1
69
+ WHEN 9607 THEN 2
70
+ WHEN 9603 THEN 3
71
+ ELSE 4
72
+ END ASC`, // Sort by method_code (9606 first, then 9607), then by accuracy`, // Assuming lower accuracy values are better
73
+ (err, rows) => {
74
+ if (err) {
75
+ console.error('Error querying proj.db:', err);
76
+ return;
77
+ }
78
+
79
+ rows.forEach((row) => {
80
+ const normalizedDatumName = row.datum_name.toLowerCase();
81
+
82
+ // Skip if the datumName already exists (case-insensitive)
83
+ if (databaseDatumNames.has(normalizedDatumName)) {
84
+ return;
85
+ }
86
+
87
+ if (row.method_code === 9607 && row.rx) {
88
+ row.rx = -row.rx;
89
+ row.ry = -row.ry;
90
+ row.rz = -row.rz;
91
+ }
92
+
93
+ // Construct the towgs84 string from tx, ty, tz, rx, ry, rz, and scale_difference
94
+ const towgs84 = row.rx ? `${row.tx},${row.ty},${row.tz},${row.rx},${row.ry},${row.rz},${row.scale_difference}` : `${row.tx},${row.ty},${row.tz}`;
95
+
96
+ datums[`${row.source_crs_auth_name}_${row.source_crs_code}`] = {
97
+ towgs84
98
+ };
99
+
100
+ databaseDatumNames.add(normalizedDatumName);
101
+ });
102
+
103
+ Object.assign(datums, DATUM_OVERRIDES);
104
+
105
+ // Write updated datums back to Datum.js
106
+ const datumFilePath = path.resolve(__dirname, '../lib/constants/Datum.js');
107
+ const updatedContent = `var datums = ${JSON.stringify(datums, null, 2)};\n\n`
108
+ + `for (var key in datums) {\n`
109
+ + ` var datum = datums[key];\n`
110
+ + ` if (!datum.datumName) {\n`
111
+ + ` continue;\n`
112
+ + ` }\n`
113
+ + ` datums[datum.datumName] = datum;\n`
114
+ + `}\n\n`
115
+ + `export default datums;`;
116
+ fs.writeFileSync(datumFilePath, updatedContent, 'utf-8');
117
+ console.log('Datum.js updated successfully!');
118
+ }
119
+ );