proj4 2.17.0 → 2.19.0

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 (154) hide show
  1. package/bower.json +1 -1
  2. package/component.json +1 -1
  3. package/dist/lib/Point.d.ts +24 -0
  4. package/dist/lib/Proj.d.ts +71 -0
  5. package/dist/lib/adjust_axis.d.ts +1 -0
  6. package/dist/lib/checkSanity.d.ts +1 -0
  7. package/dist/lib/common/acosh.d.ts +1 -0
  8. package/dist/lib/common/adjust_lat.d.ts +1 -0
  9. package/dist/lib/common/adjust_lon.d.ts +1 -0
  10. package/dist/lib/common/adjust_zone.d.ts +1 -0
  11. package/dist/lib/common/asinh.d.ts +1 -0
  12. package/dist/lib/common/asinhy.d.ts +1 -0
  13. package/dist/lib/common/asinz.d.ts +1 -0
  14. package/dist/lib/common/atanh.d.ts +1 -0
  15. package/dist/lib/common/clens.d.ts +1 -0
  16. package/dist/lib/common/clens_cmplx.d.ts +1 -0
  17. package/dist/lib/common/cosh.d.ts +1 -0
  18. package/dist/lib/common/e0fn.d.ts +1 -0
  19. package/dist/lib/common/e1fn.d.ts +1 -0
  20. package/dist/lib/common/e2fn.d.ts +1 -0
  21. package/dist/lib/common/e3fn.d.ts +1 -0
  22. package/dist/lib/common/fL.d.ts +1 -0
  23. package/dist/lib/common/gN.d.ts +1 -0
  24. package/dist/lib/common/gatg.d.ts +1 -0
  25. package/dist/lib/common/hypot.d.ts +1 -0
  26. package/dist/lib/common/imlfn.d.ts +1 -0
  27. package/dist/lib/common/invlatiso.d.ts +1 -0
  28. package/dist/lib/common/iqsfnz.d.ts +1 -0
  29. package/dist/lib/common/latiso.d.ts +1 -0
  30. package/dist/lib/common/log1py.d.ts +1 -0
  31. package/dist/lib/common/mlfn.d.ts +1 -0
  32. package/dist/lib/common/msfnz.d.ts +1 -0
  33. package/dist/lib/common/phi2z.d.ts +1 -0
  34. package/dist/lib/common/pj_enfn.d.ts +1 -0
  35. package/dist/lib/common/pj_inv_mlfn.d.ts +1 -0
  36. package/dist/lib/common/pj_mlfn.d.ts +1 -0
  37. package/dist/lib/common/qsfnz.d.ts +1 -0
  38. package/dist/lib/common/sign.d.ts +1 -0
  39. package/dist/lib/common/sinh.d.ts +1 -0
  40. package/dist/lib/common/srat.d.ts +1 -0
  41. package/dist/lib/common/tanh.d.ts +1 -0
  42. package/dist/lib/common/toPoint.d.ts +5 -0
  43. package/dist/lib/common/tsfnz.d.ts +1 -0
  44. package/dist/lib/common/vincenty.d.ts +35 -0
  45. package/dist/lib/constants/Datum.d.ts +1715 -0
  46. package/dist/lib/constants/Ellipsoid.d.ts +353 -0
  47. package/dist/lib/constants/PrimeMeridian.d.ts +16 -0
  48. package/dist/lib/constants/units.d.ts +63 -0
  49. package/dist/lib/constants/values.d.ts +19 -0
  50. package/dist/lib/core.d.ts +117 -0
  51. package/dist/lib/datum.d.ts +10 -0
  52. package/dist/lib/datumUtils.d.ts +28 -0
  53. package/dist/lib/datum_transform.d.ts +2 -0
  54. package/dist/lib/defs.d.ts +57 -0
  55. package/dist/lib/deriveConstants.d.ts +11 -0
  56. package/dist/lib/extend.d.ts +1 -0
  57. package/dist/lib/global.d.ts +1 -0
  58. package/dist/lib/includedProjections.d.ts +1 -0
  59. package/dist/lib/index.d.ts +24 -0
  60. package/dist/lib/match.d.ts +1 -0
  61. package/dist/lib/nadgrid.d.ts +107 -0
  62. package/dist/lib/parseCode.d.ts +6 -0
  63. package/dist/lib/projString.d.ts +5 -0
  64. package/dist/lib/projections/aea.d.ts +83 -0
  65. package/dist/lib/projections/aeqd.d.ts +32 -0
  66. package/dist/lib/projections/bonne.d.ts +27 -0
  67. package/dist/lib/projections/cass.d.ts +36 -0
  68. package/dist/lib/projections/cea.d.ts +28 -0
  69. package/dist/lib/projections/eqc.d.ts +20 -0
  70. package/dist/lib/projections/eqdc.d.ts +71 -0
  71. package/dist/lib/projections/eqearth.d.ts +15 -0
  72. package/dist/lib/projections/equi.d.ts +40 -0
  73. package/dist/lib/projections/etmerc.d.ts +45 -0
  74. package/dist/lib/projections/gauss.d.ts +38 -0
  75. package/dist/lib/projections/geocent.d.ts +22 -0
  76. package/dist/lib/projections/geos.d.ts +51 -0
  77. package/dist/lib/projections/gnom.d.ts +37 -0
  78. package/dist/lib/projections/gstmerc.d.ts +41 -0
  79. package/dist/lib/projections/krovak.d.ts +34 -0
  80. package/dist/lib/projections/laea.d.ts +70 -0
  81. package/dist/lib/projections/lcc.d.ts +36 -0
  82. package/dist/lib/projections/longlat.d.ts +11 -0
  83. package/dist/lib/projections/merc.d.ts +30 -0
  84. package/dist/lib/projections/mill.d.ts +11 -0
  85. package/dist/lib/projections/moll.d.ts +11 -0
  86. package/dist/lib/projections/nzmg.d.ts +33 -0
  87. package/dist/lib/projections/omerc.d.ts +60 -0
  88. package/dist/lib/projections/ortho.d.ts +25 -0
  89. package/dist/lib/projections/poly.d.ts +32 -0
  90. package/dist/lib/projections/qsc.d.ts +31 -0
  91. package/dist/lib/projections/robin.d.ts +24 -0
  92. package/dist/lib/projections/sinu.d.ts +37 -0
  93. package/dist/lib/projections/somerc.d.ts +35 -0
  94. package/dist/lib/projections/stere.d.ts +52 -0
  95. package/dist/lib/projections/sterea.d.ts +33 -0
  96. package/dist/lib/projections/tmerc.d.ts +38 -0
  97. package/dist/lib/projections/tpers.d.ts +45 -0
  98. package/dist/lib/projections/utm.d.ts +19 -0
  99. package/dist/lib/projections/vandg.d.ts +28 -0
  100. package/dist/lib/projections.d.ts +10 -0
  101. package/dist/lib/transform.d.ts +8 -0
  102. package/dist/proj4-src.js +847 -247
  103. package/dist/proj4.js +1 -1
  104. package/dist/projs.d.ts +1 -0
  105. package/lib/Point.js +9 -3
  106. package/lib/Proj.js +25 -1
  107. package/lib/adjust_axis.js +1 -0
  108. package/lib/common/toPoint.js +4 -0
  109. package/lib/common/vincenty.js +123 -0
  110. package/lib/constants/PrimeMeridian.js +16 -15
  111. package/lib/core.js +152 -16
  112. package/lib/defs.js +65 -5
  113. package/lib/index.js +17 -11
  114. package/lib/nadgrid.js +70 -0
  115. package/lib/parseCode.js +5 -1
  116. package/lib/projString.js +6 -0
  117. package/lib/projections/aea.js +25 -0
  118. package/lib/projections/aeqd.js +22 -26
  119. package/lib/projections/bonne.js +11 -0
  120. package/lib/projections/cass.js +11 -0
  121. package/lib/projections/cea.js +7 -1
  122. package/lib/projections/eqdc.js +29 -7
  123. package/lib/projections/equi.js +11 -2
  124. package/lib/projections/etmerc.js +12 -0
  125. package/lib/projections/gauss.js +12 -0
  126. package/lib/projections/geos.js +16 -0
  127. package/lib/projections/gnom.js +11 -2
  128. package/lib/projections/gstmerc.js +12 -0
  129. package/lib/projections/laea.js +30 -11
  130. package/lib/projections/lcc.js +10 -0
  131. package/lib/projections/merc.js +9 -0
  132. package/lib/projections/omerc.js +29 -4
  133. package/lib/projections/ortho.js +7 -0
  134. package/lib/projections/poly.js +14 -0
  135. package/lib/projections/qsc.js +11 -0
  136. package/lib/projections/sinu.js +11 -0
  137. package/lib/projections/somerc.js +10 -0
  138. package/lib/projections/stere.js +16 -2
  139. package/lib/projections/sterea.js +10 -0
  140. package/lib/projections/tmerc.js +8 -0
  141. package/lib/projections/tpers.js +24 -3
  142. package/lib/projections/utm.js +1 -0
  143. package/lib/projections/vandg.js +9 -2
  144. package/lib/transform.js +9 -0
  145. package/package.json +8 -6
  146. package/tsconfig.json +14 -0
  147. package/.github/workflows/build-and-test.yml +0 -69
  148. package/.nyc_output/6b047fc9-1bf2-4565-9e8a-9c0defc09dd7.json +0 -1
  149. package/.nyc_output/e2c5d0cc-9478-4f26-ad2f-de246d4c35de.json +0 -1
  150. package/.nyc_output/f4b0e40f-04ca-4b6d-bfeb-51d617db9841.json +0 -1
  151. package/.nyc_output/processinfo/6b047fc9-1bf2-4565-9e8a-9c0defc09dd7.json +0 -1
  152. package/.nyc_output/processinfo/e2c5d0cc-9478-4f26-ad2f-de246d4c35de.json +0 -1
  153. package/.nyc_output/processinfo/f4b0e40f-04ca-4b6d-bfeb-51d617db9841.json +0 -1
  154. package/.nyc_output/processinfo/index.json +0 -1
@@ -0,0 +1 @@
1
+ export default function _default(proj4: any): void;
package/lib/Point.js CHANGED
@@ -1,5 +1,11 @@
1
1
  import { toPoint, forward } from 'mgrs';
2
2
 
3
+ /**
4
+ * @deprecated v3.0.0 - use proj4.toPoint instead
5
+ * @param {number | import('./core').TemplateCoordinates | string} x
6
+ * @param {number} [y]
7
+ * @param {number} [z]
8
+ */
3
9
  function Point(x, y, z) {
4
10
  if (!(this instanceof Point)) {
5
11
  return new Point(x, y, z);
@@ -14,9 +20,9 @@ function Point(x, y, z) {
14
20
  this.z = x.z || 0.0;
15
21
  } else if (typeof x === 'string' && typeof y === 'undefined') {
16
22
  var coords = x.split(',');
17
- this.x = parseFloat(coords[0], 10);
18
- this.y = parseFloat(coords[1], 10);
19
- this.z = parseFloat(coords[2], 10) || 0.0;
23
+ this.x = parseFloat(coords[0]);
24
+ this.y = parseFloat(coords[1]);
25
+ this.z = parseFloat(coords[2]) || 0.0;
20
26
  } else {
21
27
  this.x = x;
22
28
  this.y = y;
package/lib/Proj.js CHANGED
@@ -7,10 +7,31 @@ import datum from './datum';
7
7
  import match from './match';
8
8
  import { getNadgrids } from './nadgrid';
9
9
 
10
+ /**
11
+ * @typedef {Object} DatumDefinition
12
+ * @property {number} datum_type - The type of datum.
13
+ * @property {number} a - Semi-major axis of the ellipsoid.
14
+ * @property {number} b - Semi-minor axis of the ellipsoid.
15
+ * @property {number} es - Eccentricity squared of the ellipsoid.
16
+ * @property {number} ep2 - Second eccentricity squared of the ellipsoid.
17
+ */
18
+
19
+ /**
20
+ * @param {string | import('./core').PROJJSONDefinition | import('./defs').ProjectionDefinition} srsCode
21
+ * @param {(errorMessage?: string, instance?: Projection) => void} [callback]
22
+ */
10
23
  function Projection(srsCode, callback) {
11
24
  if (!(this instanceof Projection)) {
12
25
  return new Projection(srsCode);
13
26
  }
27
+ /** @type {<T extends import('./core').TemplateCoordinates>(coordinates: T, enforceAxis?: boolean) => T} */
28
+ this.forward = null;
29
+ /** @type {<T extends import('./core').TemplateCoordinates>(coordinates: T, enforceAxis?: boolean) => T} */
30
+ this.inverse = null;
31
+ /** @type {string} */
32
+ this.name;
33
+ /** @type {string} */
34
+ this.title;
14
35
  callback = callback || function (error) {
15
36
  if (error) {
16
37
  throw error;
@@ -42,6 +63,7 @@ function Projection(srsCode, callback) {
42
63
  var sphere_ = dc_sphere(json.a, json.b, json.rf, json.ellps, json.sphere);
43
64
  var ecc = dc_eccentricity(sphere_.a, sphere_.b, sphere_.rf, json.R_A);
44
65
  var nadgrids = getNadgrids(json.nadgrids);
66
+ /** @type {DatumDefinition} */
45
67
  var datumObj = json.datum || datum(json.datumCode, json.datum_params, sphere_.a, sphere_.b, ecc.es, ecc.ep2,
46
68
  nadgrids);
47
69
 
@@ -63,7 +85,9 @@ function Projection(srsCode, callback) {
63
85
  this.datum = datumObj;
64
86
 
65
87
  // init the projection
66
- this.init();
88
+ if ('init' in this && typeof this.init === 'function') {
89
+ this.init();
90
+ }
67
91
 
68
92
  // legecy callback from back in the day when it went to spatialreference.org
69
93
  callback(null, this);
@@ -3,6 +3,7 @@ export default function (crs, denorm, point) {
3
3
  yin = point.y,
4
4
  zin = point.z || 0.0;
5
5
  var v, t, i;
6
+ /** @type {import("./core").InterfaceCoordinates} */
6
7
  var out = {};
7
8
  for (i = 0; i < 3; i++) {
8
9
  if (denorm && i === 2 && point.z === undefined) {
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @param {Array<number>} array
3
+ * @returns {import("../core").InterfaceCoordinates}
4
+ */
1
5
  export default function (array) {
2
6
  var out = {
3
7
  x: array[0],
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Calculates the inverse geodesic problem using Vincenty's formulae.
3
+ * Computes the forward azimuth and ellipsoidal distance between two points
4
+ * specified by latitude and longitude on the surface of an ellipsoid.
5
+ *
6
+ * @param {number} lat1 Latitude of the first point in radians.
7
+ * @param {number} lon1 Longitude of the first point in radians.
8
+ * @param {number} lat2 Latitude of the second point in radians.
9
+ * @param {number} lon2 Longitude of the second point in radians.
10
+ * @param {number} a Semi-major axis of the ellipsoid (meters).
11
+ * @param {number} f Flattening of the ellipsoid.
12
+ * @returns {{ azi1: number, s12: number }} An object containing:
13
+ * - azi1: Forward azimuth from the first point to the second point (radians).
14
+ * - s12: Ellipsoidal distance between the two points (meters).
15
+ */
16
+ export function vincentyInverse(lat1, lon1, lat2, lon2, a, f) {
17
+ const L = lon2 - lon1;
18
+ const U1 = Math.atan((1 - f) * Math.tan(lat1));
19
+ const U2 = Math.atan((1 - f) * Math.tan(lat2));
20
+ const sinU1 = Math.sin(U1), cosU1 = Math.cos(U1);
21
+ const sinU2 = Math.sin(U2), cosU2 = Math.cos(U2);
22
+
23
+ let lambda = L, lambdaP, iterLimit = 100;
24
+ let sinLambda, cosLambda, sinSigma, cosSigma, sigma, sinAlpha, cos2Alpha, cos2SigmaM, C;
25
+ let uSq, A, B, deltaSigma, s;
26
+
27
+ do {
28
+ sinLambda = Math.sin(lambda);
29
+ cosLambda = Math.cos(lambda);
30
+ sinSigma = Math.sqrt(
31
+ (cosU2 * sinLambda) * (cosU2 * sinLambda)
32
+ + (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda)
33
+ * (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda)
34
+ );
35
+ if (sinSigma === 0) {
36
+ return { azi1: 0, s12: 0 }; // coincident points
37
+ }
38
+ cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda;
39
+ sigma = Math.atan2(sinSigma, cosSigma);
40
+ sinAlpha = cosU1 * cosU2 * sinLambda / sinSigma;
41
+ cos2Alpha = 1 - sinAlpha * sinAlpha;
42
+ cos2SigmaM = (cos2Alpha !== 0) ? (cosSigma - 2 * sinU1 * sinU2 / cos2Alpha) : 0;
43
+ C = f / 16 * cos2Alpha * (4 + f * (4 - 3 * cos2Alpha));
44
+ lambdaP = lambda;
45
+ lambda = L + (1 - C) * f * sinAlpha
46
+ * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)));
47
+ } while (Math.abs(lambda - lambdaP) > 1e-12 && --iterLimit > 0);
48
+
49
+ if (iterLimit === 0) {
50
+ return { azi1: NaN, s12: NaN }; // formula failed to converge
51
+ }
52
+
53
+ uSq = cos2Alpha * (a * a - (a * (1 - f)) * (a * (1 - f))) / ((a * (1 - f)) * (a * (1 - f)));
54
+ A = 1 + uSq / 16384 * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)));
55
+ B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)));
56
+ deltaSigma = B * sinSigma * (cos2SigmaM + B / 4 * (cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)
57
+ - B / 6 * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM)));
58
+
59
+ s = (a * (1 - f)) * A * (sigma - deltaSigma);
60
+
61
+ // Forward azimuth
62
+ const azi1 = Math.atan2(cosU2 * sinLambda, cosU1 * sinU2 - sinU1 * cosU2 * cosLambda);
63
+
64
+ return { azi1, s12: s };
65
+ }
66
+
67
+ /**
68
+ * Solves the direct geodetic problem using Vincenty's formulae.
69
+ * Given a starting point, initial azimuth, and distance, computes the destination point on the ellipsoid.
70
+ *
71
+ * @param {number} lat1 Latitude of the starting point in radians.
72
+ * @param {number} lon1 Longitude of the starting point in radians.
73
+ * @param {number} azi1 Initial azimuth (forward azimuth) in radians.
74
+ * @param {number} s12 Distance to travel from the starting point in meters.
75
+ * @param {number} a Semi-major axis of the ellipsoid in meters.
76
+ * @param {number} f Flattening of the ellipsoid.
77
+ * @returns {{lat2: number, lon2: number}} The latitude and longitude (in radians) of the destination point.
78
+ */
79
+ export function vincentyDirect(lat1, lon1, azi1, s12, a, f) {
80
+ const U1 = Math.atan((1 - f) * Math.tan(lat1));
81
+ const sinU1 = Math.sin(U1), cosU1 = Math.cos(U1);
82
+ const sinAlpha1 = Math.sin(azi1), cosAlpha1 = Math.cos(azi1);
83
+
84
+ const sigma1 = Math.atan2(sinU1, cosU1 * cosAlpha1);
85
+ const sinAlpha = cosU1 * sinAlpha1;
86
+ const cos2Alpha = 1 - sinAlpha * sinAlpha;
87
+ const uSq = cos2Alpha * (a * a - (a * (1 - f)) * (a * (1 - f))) / ((a * (1 - f)) * (a * (1 - f)));
88
+ const A = 1 + uSq / 16384 * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)));
89
+ const B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)));
90
+
91
+ let sigma = s12 / ((a * (1 - f)) * A), sigmaP, iterLimit = 100;
92
+ let cos2SigmaM, sinSigma, cosSigma, deltaSigma;
93
+
94
+ do {
95
+ cos2SigmaM = Math.cos(2 * sigma1 + sigma);
96
+ sinSigma = Math.sin(sigma);
97
+ cosSigma = Math.cos(sigma);
98
+ deltaSigma = B * sinSigma * (cos2SigmaM + B / 4 * (cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)
99
+ - B / 6 * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM)));
100
+ sigmaP = sigma;
101
+ sigma = s12 / ((a * (1 - f)) * A) + deltaSigma;
102
+ } while (Math.abs(sigma - sigmaP) > 1e-12 && --iterLimit > 0);
103
+
104
+ if (iterLimit === 0) {
105
+ return { lat2: NaN, lon2: NaN };
106
+ }
107
+
108
+ const tmp = sinU1 * sinSigma - cosU1 * cosSigma * cosAlpha1;
109
+ const lat2 = Math.atan2(
110
+ sinU1 * cosSigma + cosU1 * sinSigma * cosAlpha1,
111
+ (1 - f) * Math.sqrt(sinAlpha * sinAlpha + tmp * tmp)
112
+ );
113
+ const lambda = Math.atan2(
114
+ sinSigma * sinAlpha1,
115
+ cosU1 * cosSigma - sinU1 * sinSigma * cosAlpha1
116
+ );
117
+ const C = f / 16 * cos2Alpha * (4 + f * (4 - 3 * cos2Alpha));
118
+ const L = lambda - (1 - C) * f * sinAlpha
119
+ * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)));
120
+ const lon2 = lon1 + L;
121
+
122
+ return { lat2, lon2 };
123
+ }
@@ -1,16 +1,17 @@
1
- var exports = {};
2
- export { exports as default };
1
+ var primeMeridian = {};
3
2
 
4
- exports.greenwich = 0.0; // "0dE",
5
- exports.lisbon = -9.131906111111; // "9d07'54.862\"W",
6
- exports.paris = 2.337229166667; // "2d20'14.025\"E",
7
- exports.bogota = -74.080916666667; // "74d04'51.3\"W",
8
- exports.madrid = -3.687938888889; // "3d41'16.58\"W",
9
- exports.rome = 12.452333333333; // "12d27'8.4\"E",
10
- exports.bern = 7.439583333333; // "7d26'22.5\"E",
11
- exports.jakarta = 106.807719444444; // "106d48'27.79\"E",
12
- exports.ferro = -17.666666666667; // "17d40'W",
13
- exports.brussels = 4.367975; // "4d22'4.71\"E",
14
- exports.stockholm = 18.058277777778; // "18d3'29.8\"E",
15
- exports.athens = 23.7163375; // "23d42'58.815\"E",
16
- exports.oslo = 10.722916666667; // "10d43'22.5\"E"
3
+ primeMeridian.greenwich = 0.0; // "0dE",
4
+ primeMeridian.lisbon = -9.131906111111; // "9d07'54.862\"W",
5
+ primeMeridian.paris = 2.337229166667; // "2d20'14.025\"E",
6
+ primeMeridian.bogota = -74.080916666667; // "74d04'51.3\"W",
7
+ primeMeridian.madrid = -3.687938888889; // "3d41'16.58\"W",
8
+ primeMeridian.rome = 12.452333333333; // "12d27'8.4\"E",
9
+ primeMeridian.bern = 7.439583333333; // "7d26'22.5\"E",
10
+ primeMeridian.jakarta = 106.807719444444; // "106d48'27.79\"E",
11
+ primeMeridian.ferro = -17.666666666667; // "17d40'W",
12
+ primeMeridian.brussels = 4.367975; // "4d22'4.71\"E",
13
+ primeMeridian.stockholm = 18.058277777778; // "18d3'29.8\"E",
14
+ primeMeridian.athens = 23.7163375; // "23d42'58.815\"E",
15
+ primeMeridian.oslo = 10.722916666667; // "10d43'22.5\"E"
16
+
17
+ export default primeMeridian;
package/lib/core.js CHANGED
@@ -2,6 +2,85 @@ import proj from './Proj';
2
2
  import transform from './transform';
3
3
  var wgs84 = proj('WGS84');
4
4
 
5
+ /**
6
+ * @typedef {{x: number, y: number, z?: number, m?: number}} InterfaceCoordinates
7
+ */
8
+
9
+ /**
10
+ * @typedef {Array<number> | InterfaceCoordinates} TemplateCoordinates
11
+ */
12
+
13
+ /**
14
+ * @typedef {Object} Converter
15
+ * @property {<T extends TemplateCoordinates>(coordinates: T, enforceAxis?: boolean) => T} forward
16
+ * @property {<T extends TemplateCoordinates>(coordinates: T, enforceAxis?: boolean) => T} inverse
17
+ * @property {proj} [oProj]
18
+ */
19
+
20
+ /**
21
+ * @typedef {Object} PROJJSONDefinition
22
+ * @property {string} [$schema]
23
+ * @property {string} type
24
+ * @property {string} [name]
25
+ * @property {{authority: string, code: number}} [id]
26
+ * @property {string} [scope]
27
+ * @property {string} [area]
28
+ * @property {{south_latitude: number, west_longitude: number, north_latitude: number, east_longitude: number}} [bbox]
29
+ * @property {PROJJSONDefinition[]} [components]
30
+ * @property {{type: string, name: string}} [datum]
31
+ * @property {{
32
+ * name: string,
33
+ * members: Array<{
34
+ * name: string,
35
+ * id?: {authority: string, code: number}
36
+ * }>,
37
+ * ellipsoid?: {
38
+ * name: string,
39
+ * semi_major_axis: number,
40
+ * inverse_flattening?: number
41
+ * },
42
+ * accuracy?: string,
43
+ * id?: {authority: string, code: number}
44
+ * }} [datum_ensemble]
45
+ * @property {{
46
+ * subtype: string,
47
+ * axis: Array<{
48
+ * name: string,
49
+ * abbreviation?: string,
50
+ * direction: string,
51
+ * unit: string
52
+ * }>
53
+ * }} [coordinate_system]
54
+ * @property {{
55
+ * name: string,
56
+ * method: {name: string},
57
+ * parameters: Array<{
58
+ * name: string,
59
+ * value: number,
60
+ * unit?: string
61
+ * }>
62
+ * }} [conversion]
63
+ * @property {{
64
+ * name: string,
65
+ * method: {name: string},
66
+ * parameters: Array<{
67
+ * name: string,
68
+ * value: number,
69
+ * unit?: string,
70
+ * type?: string,
71
+ * file_name?: string
72
+ * }>
73
+ * }} [transformation]
74
+ */
75
+
76
+ /**
77
+ * @template {TemplateCoordinates} T
78
+ * @param {proj} from
79
+ * @param {proj} to
80
+ * @param {T} coords
81
+ * @param {boolean} [enforceAxis]
82
+ * @returns {T}
83
+ */
5
84
  function transformer(from, to, coords, enforceAxis) {
6
85
  var transformedArray, out, keys;
7
86
  if (Array.isArray(coords)) {
@@ -9,21 +88,21 @@ function transformer(from, to, coords, enforceAxis) {
9
88
  if (coords.length > 2) {
10
89
  if ((typeof from.name !== 'undefined' && from.name === 'geocent') || (typeof to.name !== 'undefined' && to.name === 'geocent')) {
11
90
  if (typeof transformedArray.z === 'number') {
12
- return [transformedArray.x, transformedArray.y, transformedArray.z].concat(coords.slice(3));
91
+ return /** @type {T} */ ([transformedArray.x, transformedArray.y, transformedArray.z].concat(coords.slice(3)));
13
92
  } else {
14
- return [transformedArray.x, transformedArray.y, coords[2]].concat(coords.slice(3));
93
+ return /** @type {T} */ ([transformedArray.x, transformedArray.y, coords[2]].concat(coords.slice(3)));
15
94
  }
16
95
  } else {
17
- return [transformedArray.x, transformedArray.y].concat(coords.slice(2));
96
+ return /** @type {T} */ ([transformedArray.x, transformedArray.y].concat(coords.slice(2)));
18
97
  }
19
98
  } else {
20
- return [transformedArray.x, transformedArray.y];
99
+ return /** @type {T} */ ([transformedArray.x, transformedArray.y]);
21
100
  }
22
101
  } else {
23
102
  out = transform(from, to, coords, enforceAxis);
24
103
  keys = Object.keys(coords);
25
104
  if (keys.length === 2) {
26
- return out;
105
+ return /** @type {T} */ (out);
27
106
  }
28
107
  keys.forEach(function (key) {
29
108
  if ((typeof from.name !== 'undefined' && from.name === 'geocent') || (typeof to.name !== 'undefined' && to.name === 'geocent')) {
@@ -37,42 +116,98 @@ function transformer(from, to, coords, enforceAxis) {
37
116
  }
38
117
  out[key] = coords[key];
39
118
  });
40
- return out;
119
+ return /** @type {T} */ (out);
41
120
  }
42
121
  }
43
122
 
123
+ /**
124
+ * @param {proj | string | PROJJSONDefinition | Converter} item
125
+ * @returns {import('./Proj').default}
126
+ */
44
127
  function checkProj(item) {
45
128
  if (item instanceof proj) {
46
129
  return item;
47
130
  }
48
- if (item.oProj) {
131
+ if (typeof item === 'object' && 'oProj' in item) {
49
132
  return item.oProj;
50
133
  }
51
- return proj(item);
134
+ return proj(/** @type {string | PROJJSONDefinition} */ (item));
52
135
  }
53
136
 
54
- function proj4(fromProj, toProj, coord) {
55
- fromProj = checkProj(fromProj);
137
+ /**
138
+ * @overload
139
+ * @param {string | PROJJSONDefinition | proj} toProj
140
+ * @returns {Converter}
141
+ */
142
+ /**
143
+ * @overload
144
+ * @param {string | PROJJSONDefinition | proj} fromProj
145
+ * @param {string | PROJJSONDefinition | proj} toProj
146
+ * @returns {Converter}
147
+ */
148
+ /**
149
+ * @overload
150
+ * @param {string | PROJJSONDefinition | proj} toProj
151
+ * @param {T} coord
152
+ * @returns {T}
153
+ */
154
+ /**
155
+ * @overload
156
+ * @param {string | PROJJSONDefinition | proj} fromProj
157
+ * @param {string | PROJJSONDefinition | proj} toProj
158
+ * @param {T} coord
159
+ * @returns {T}
160
+ */
161
+ /**
162
+ * @template {TemplateCoordinates} T
163
+ * @param {string | PROJJSONDefinition | proj} fromProjOrToProj
164
+ * @param {string | PROJJSONDefinition | proj | TemplateCoordinates} [toProjOrCoord]
165
+ * @param {T} [coord]
166
+ * @returns {T|Converter}
167
+ */
168
+ function proj4(fromProjOrToProj, toProjOrCoord, coord) {
169
+ /** @type {proj} */
170
+ var fromProj;
171
+ /** @type {proj} */
172
+ var toProj;
56
173
  var single = false;
174
+ /** @type {Converter} */
57
175
  var obj;
58
- if (typeof toProj === 'undefined') {
59
- toProj = fromProj;
176
+ if (typeof toProjOrCoord === 'undefined') {
177
+ toProj = checkProj(fromProjOrToProj);
60
178
  fromProj = wgs84;
61
179
  single = true;
62
- } else if (typeof toProj.x !== 'undefined' || Array.isArray(toProj)) {
63
- coord = toProj;
64
- toProj = fromProj;
180
+ } else if (typeof /** @type {?} */ (toProjOrCoord).x !== 'undefined' || Array.isArray(toProjOrCoord)) {
181
+ coord = /** @type {T} */ (/** @type {?} */ (toProjOrCoord));
182
+ toProj = checkProj(fromProjOrToProj);
65
183
  fromProj = wgs84;
66
184
  single = true;
67
185
  }
68
- toProj = checkProj(toProj);
186
+ if (!fromProj) {
187
+ fromProj = checkProj(fromProjOrToProj);
188
+ }
189
+ if (!toProj) {
190
+ toProj = checkProj(/** @type {string | PROJJSONDefinition | proj } */ (toProjOrCoord));
191
+ }
69
192
  if (coord) {
70
193
  return transformer(fromProj, toProj, coord);
71
194
  } else {
72
195
  obj = {
196
+ /**
197
+ * @template {TemplateCoordinates} T
198
+ * @param {T} coords
199
+ * @param {boolean=} enforceAxis
200
+ * @returns {T}
201
+ */
73
202
  forward: function (coords, enforceAxis) {
74
203
  return transformer(fromProj, toProj, coords, enforceAxis);
75
204
  },
205
+ /**
206
+ * @template {TemplateCoordinates} T
207
+ * @param {T} coords
208
+ * @param {boolean=} enforceAxis
209
+ * @returns {T}
210
+ */
76
211
  inverse: function (coords, enforceAxis) {
77
212
  return transformer(toProj, fromProj, coords, enforceAxis);
78
213
  }
@@ -83,4 +218,5 @@ function proj4(fromProj, toProj, coord) {
83
218
  return obj;
84
219
  }
85
220
  }
221
+
86
222
  export default proj4;
package/lib/defs.js CHANGED
@@ -2,6 +2,66 @@ import globals from './global';
2
2
  import parseProj from './projString';
3
3
  import wkt from 'wkt-parser';
4
4
 
5
+ /**
6
+ * @typedef {Object} ProjectionDefinition
7
+ * @property {string} title
8
+ * @property {string} [projName]
9
+ * @property {string} [ellps]
10
+ * @property {import('./Proj.js').DatumDefinition} [datum]
11
+ * @property {string} [datumName]
12
+ * @property {number} [rf]
13
+ * @property {number} [lat0]
14
+ * @property {number} [lat1]
15
+ * @property {number} [lat2]
16
+ * @property {number} [lat_ts]
17
+ * @property {number} [long0]
18
+ * @property {number} [long1]
19
+ * @property {number} [long2]
20
+ * @property {number} [alpha]
21
+ * @property {number} [longc]
22
+ * @property {number} [x0]
23
+ * @property {number} [y0]
24
+ * @property {number} [k0]
25
+ * @property {number} [a]
26
+ * @property {number} [b]
27
+ * @property {true} [R_A]
28
+ * @property {number} [zone]
29
+ * @property {true} [utmSouth]
30
+ * @property {string|Array<number>} [datum_params]
31
+ * @property {number} [to_meter]
32
+ * @property {string} [units]
33
+ * @property {number} [from_greenwich]
34
+ * @property {string} [datumCode]
35
+ * @property {string} [nadgrids]
36
+ * @property {string} [axis]
37
+ * @property {boolean} [sphere]
38
+ * @property {number} [rectified_grid_angle]
39
+ * @property {boolean} [approx]
40
+ * @property {<T extends import('./core').TemplateCoordinates>(coordinates: T, enforceAxis?: boolean) => T} inverse
41
+ * @property {<T extends import('./core').TemplateCoordinates>(coordinates: T, enforceAxis?: boolean) => T} forward
42
+ */
43
+
44
+ /**
45
+ * @overload
46
+ * @param {string} name
47
+ * @param {string|ProjectionDefinition|import('./core.js').PROJJSONDefinition} projection
48
+ * @returns {void}
49
+ */
50
+ /**
51
+ * @overload
52
+ * @param {Array<string, string>} name
53
+ * @returns {Array<ProjectionDefinition|undefined>}
54
+ */
55
+ /**
56
+ * @overload
57
+ * @param {string} name
58
+ * @returns {ProjectionDefinition}
59
+ */
60
+
61
+ /**
62
+ * @param {string | Array<Array<string>> | Partial<Record<'EPSG'|'ESRI'|'IAU2000', ProjectionDefinition>>} name
63
+ * @returns {ProjectionDefinition | Array<ProjectionDefinition|undefined> | void}
64
+ */
5
65
  function defs(name) {
6
66
  /* global console */
7
67
  var that = this;
@@ -9,20 +69,20 @@ function defs(name) {
9
69
  var def = arguments[1];
10
70
  if (typeof def === 'string') {
11
71
  if (def.charAt(0) === '+') {
12
- defs[name] = parseProj(arguments[1]);
72
+ defs[/** @type {string} */ (name)] = parseProj(arguments[1]);
13
73
  } else {
14
- defs[name] = wkt(arguments[1]);
74
+ defs[/** @type {string} */ (name)] = wkt(arguments[1]);
15
75
  }
16
76
  } else {
17
- defs[name] = def;
77
+ defs[/** @type {string} */ (name)] = def;
18
78
  }
19
79
  } else if (arguments.length === 1) {
20
80
  if (Array.isArray(name)) {
21
81
  return name.map(function (v) {
22
82
  if (Array.isArray(v)) {
23
- defs.apply(that, v);
83
+ return defs.apply(that, v);
24
84
  } else {
25
- defs(v);
85
+ return defs(v);
26
86
  }
27
87
  });
28
88
  } else if (typeof name === 'string') {
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import proj4 from './core';
1
+ import core from './core';
2
2
  import Proj from './Proj';
3
3
  import Point from './Point';
4
4
  import common from './common/toPoint';
@@ -8,15 +8,21 @@ import transform from './transform';
8
8
  import mgrs from 'mgrs';
9
9
  import includedProjections from '../projs';
10
10
 
11
- proj4.defaultDatum = 'WGS84'; // default datum
12
- proj4.Proj = Proj;
13
- proj4.WGS84 = new proj4.Proj('WGS84');
14
- proj4.Point = Point;
15
- proj4.toPoint = common;
16
- proj4.defs = defs;
17
- proj4.nadgrid = nadgrid;
18
- proj4.transform = transform;
19
- proj4.mgrs = mgrs;
20
- proj4.version = '__VERSION__';
11
+ /**
12
+ * @template {import('./core').TemplateCoordinates} T
13
+ * @type {core<T> & {defaultDatum: string, Proj: typeof Proj, WGS84: Proj, Point: typeof Point, toPoint: typeof common, defs: typeof defs, nadgrid: typeof nadgrid, transform: typeof transform, mgrs: typeof mgrs, version: string}}
14
+ */
15
+ const proj4 = Object.assign(core, {
16
+ defaultDatum: 'WGS84',
17
+ Proj,
18
+ WGS84: new Proj('WGS84'),
19
+ Point,
20
+ toPoint: common,
21
+ defs,
22
+ nadgrid,
23
+ transform,
24
+ mgrs,
25
+ version: '__VERSION__'
26
+ });
21
27
  includedProjections(proj4);
22
28
  export default proj4;