@itowns/geographic 2.46.1-next.1 → 2.46.1-next.10
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.
- package/lib/Coordinates.js +6 -17
- package/lib/Crs.js +18 -1
- package/lib/Ellipsoid.js +5 -10
- package/lib/Extent.js +14 -33
- package/lib/OrientationUtils.js +26 -74
- package/package.json +2 -2
- package/src/Crs.ts +26 -1
package/lib/Coordinates.js
CHANGED
|
@@ -71,10 +71,7 @@ class Coordinates {
|
|
|
71
71
|
* @param y - y or latitude value.
|
|
72
72
|
* @param z - z or altitude value.
|
|
73
73
|
*/
|
|
74
|
-
constructor(crs) {
|
|
75
|
-
let x = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
76
|
-
let y = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
77
|
-
let z = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
74
|
+
constructor(crs, x = 0, y = 0, z = 0) {
|
|
78
75
|
this.isCoordinates = true;
|
|
79
76
|
CRS.isValid(crs);
|
|
80
77
|
this.crs = crs;
|
|
@@ -122,10 +119,7 @@ class Coordinates {
|
|
|
122
119
|
* @param y - y or latitude value.
|
|
123
120
|
* @param z - z or altitude value.
|
|
124
121
|
*/
|
|
125
|
-
setFromValues() {
|
|
126
|
-
let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
127
|
-
let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
128
|
-
let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
122
|
+
setFromValues(x = 0, y = 0, z = 0) {
|
|
129
123
|
this.x = x;
|
|
130
124
|
this.y = y;
|
|
131
125
|
this.z = z;
|
|
@@ -142,8 +136,7 @@ class Coordinates {
|
|
|
142
136
|
* @param array - The source array.
|
|
143
137
|
* @param offset - Optional offset into the array. Default is 0.
|
|
144
138
|
*/
|
|
145
|
-
setFromArray(array) {
|
|
146
|
-
let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
139
|
+
setFromArray(array, offset = 0) {
|
|
147
140
|
return this.setFromValues(array[offset], array[offset + 1], array[offset + 2]);
|
|
148
141
|
}
|
|
149
142
|
|
|
@@ -215,8 +208,7 @@ class Coordinates {
|
|
|
215
208
|
* @returns A vector `(x, y, z)`, or copies x, y and z into the provided
|
|
216
209
|
* vector.
|
|
217
210
|
*/
|
|
218
|
-
toVector3() {
|
|
219
|
-
let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Vector3();
|
|
211
|
+
toVector3(target = new Vector3()) {
|
|
220
212
|
return target.copy(this);
|
|
221
213
|
}
|
|
222
214
|
|
|
@@ -230,9 +222,7 @@ class Coordinates {
|
|
|
230
222
|
* @returns An array [x, y, z], or copies x, y and z into the provided
|
|
231
223
|
* array.
|
|
232
224
|
*/
|
|
233
|
-
toArray() {
|
|
234
|
-
let array = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
235
|
-
let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
225
|
+
toArray(array = [], offset = 0) {
|
|
236
226
|
return Vector3.prototype.toArray.call(this, array, offset);
|
|
237
227
|
}
|
|
238
228
|
|
|
@@ -312,8 +302,7 @@ class Coordinates {
|
|
|
312
302
|
* const geographicCoords = geocentricCoords.as('EPSG:4326');
|
|
313
303
|
* ```
|
|
314
304
|
*/
|
|
315
|
-
as(crs) {
|
|
316
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Coordinates(crs);
|
|
305
|
+
as(crs, target = new Coordinates(crs)) {
|
|
317
306
|
if (this.crs == crs) {
|
|
318
307
|
target.copy(this);
|
|
319
308
|
} else {
|
package/lib/Crs.js
CHANGED
|
@@ -167,4 +167,21 @@ export function axisOrder(crs) {
|
|
|
167
167
|
* @param code - Named alias of the currently defined projection.
|
|
168
168
|
* @param proj4def - Proj4 or WKT string of the defined projection.
|
|
169
169
|
*/
|
|
170
|
-
export const defs = (code, proj4def) => proj4.defs(code, proj4def);
|
|
170
|
+
export const defs = (code, proj4def) => proj4.defs(code, proj4def);
|
|
171
|
+
export function defsFromWkt(wkt) {
|
|
172
|
+
proj4.defs('unknown', wkt);
|
|
173
|
+
const proj4Defs = proj4.defs;
|
|
174
|
+
let projCS;
|
|
175
|
+
if (proj4Defs('unknown').type === 'COMPD_CS') {
|
|
176
|
+
console.warn('Compound coordinate system is not yet supported.');
|
|
177
|
+
projCS = proj4Defs('unknown').PROJCS;
|
|
178
|
+
} else {
|
|
179
|
+
projCS = proj4Defs('unknown');
|
|
180
|
+
}
|
|
181
|
+
const crsAlias = projCS.title || projCS.name || 'EPSG:XXXX';
|
|
182
|
+
if (!(crsAlias in proj4.defs)) {
|
|
183
|
+
proj4.defs(crsAlias, projCS);
|
|
184
|
+
}
|
|
185
|
+
delete proj4Defs.unknown;
|
|
186
|
+
return crsAlias;
|
|
187
|
+
}
|
package/lib/Ellipsoid.js
CHANGED
|
@@ -21,8 +21,7 @@ class Ellipsoid {
|
|
|
21
21
|
* @param size - Length of the semi-axes of the ellipsoid. Defaults to those
|
|
22
22
|
* defined by the WGS84 ellipsoid.
|
|
23
23
|
*/
|
|
24
|
-
constructor() {
|
|
25
|
-
let size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ellipsoidSizes;
|
|
24
|
+
constructor(size = ellipsoidSizes) {
|
|
26
25
|
this.size = new Vector3();
|
|
27
26
|
this._radiiSquared = new Vector3();
|
|
28
27
|
this._invRadiiSquared = new Vector3();
|
|
@@ -38,8 +37,7 @@ class Ellipsoid {
|
|
|
38
37
|
* @param target - An object to store this vector to. If this is not
|
|
39
38
|
* specified, a new vector will be created.
|
|
40
39
|
*/
|
|
41
|
-
geodeticSurfaceNormal(cartesian) {
|
|
42
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3();
|
|
40
|
+
geodeticSurfaceNormal(cartesian, target = new Vector3()) {
|
|
43
41
|
return cartesian.toVector3(target).multiply(this._invRadiiSquared).normalize();
|
|
44
42
|
}
|
|
45
43
|
|
|
@@ -51,8 +49,7 @@ class Ellipsoid {
|
|
|
51
49
|
* @param target - An object to store this vector to. If this is not
|
|
52
50
|
* specified, a new vector will be created.
|
|
53
51
|
*/
|
|
54
|
-
geodeticSurfaceNormalCartographic(coordCarto) {
|
|
55
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3();
|
|
52
|
+
geodeticSurfaceNormalCartographic(coordCarto, target = new Vector3()) {
|
|
56
53
|
const longitude = MathUtils.degToRad(coordCarto.longitude);
|
|
57
54
|
const latitude = MathUtils.degToRad(coordCarto.latitude);
|
|
58
55
|
const cosLatitude = Math.cos(latitude);
|
|
@@ -75,8 +72,7 @@ class Ellipsoid {
|
|
|
75
72
|
this.eccentricity = Math.sqrt(this._radiiSquared.x - this._radiiSquared.z) / this.size.x;
|
|
76
73
|
return this;
|
|
77
74
|
}
|
|
78
|
-
cartographicToCartesian(coordCarto) {
|
|
79
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3();
|
|
75
|
+
cartographicToCartesian(coordCarto, target = new Vector3()) {
|
|
80
76
|
normal.copy(coordCarto.geodesicNormal);
|
|
81
77
|
target.multiplyVectors(this._radiiSquared, normal);
|
|
82
78
|
const gamma = Math.sqrt(normal.dot(target));
|
|
@@ -93,8 +89,7 @@ class Ellipsoid {
|
|
|
93
89
|
* @returns an object describing the coordinates on the reference ellipsoid,
|
|
94
90
|
* angles are in degree
|
|
95
91
|
*/
|
|
96
|
-
cartesianToCartographic(position) {
|
|
97
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Coordinates('EPSG:4326', 0, 0, 0);
|
|
92
|
+
cartesianToCartographic(position, target = new Coordinates('EPSG:4326', 0, 0, 0)) {
|
|
98
93
|
// for details, see for example http://www.linz.govt.nz/data/geodetic-system/coordinate-conversion/geodetic-datum-conversions/equations-used-datum
|
|
99
94
|
// TODO the following is only valable for oblate ellipsoid of
|
|
100
95
|
// revolution. do we want to support triaxial ellipsoid?
|
package/lib/Extent.js
CHANGED
|
@@ -54,11 +54,7 @@ class Extent {
|
|
|
54
54
|
* @param south - the `south` value of this extent. Default is 0.
|
|
55
55
|
* @param north - the `north` value of this extent. Default is 0.
|
|
56
56
|
*/
|
|
57
|
-
constructor(crs) {
|
|
58
|
-
let west = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
59
|
-
let east = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
60
|
-
let south = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
61
|
-
let north = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
57
|
+
constructor(crs, west = 0, east = 0, south = 0, north = 0) {
|
|
62
58
|
if (CRS.isGeocentric(crs)) {
|
|
63
59
|
throw new Error(`Non-compatible geocentric projection ${crs} to build a geographical extent`);
|
|
64
60
|
}
|
|
@@ -85,8 +81,7 @@ class Extent {
|
|
|
85
81
|
* @param target - The target to store the projected extent. If this not
|
|
86
82
|
* provided a new extent will be created.
|
|
87
83
|
*/
|
|
88
|
-
as(crs) {
|
|
89
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Extent('EPSG:4326');
|
|
84
|
+
as(crs, target = new Extent('EPSG:4326')) {
|
|
90
85
|
CRS.isValid(crs);
|
|
91
86
|
if (this.crs != crs) {
|
|
92
87
|
// Compute min/max in x/y by projecting 8 cardinal points,
|
|
@@ -126,8 +121,7 @@ class Extent {
|
|
|
126
121
|
* @param target - The target to store the center coordinate. If this not
|
|
127
122
|
* provided a new coordinate will be created.
|
|
128
123
|
*/
|
|
129
|
-
center() {
|
|
130
|
-
let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Coordinates(this.crs);
|
|
124
|
+
center(target = new Coordinates(this.crs)) {
|
|
131
125
|
this.planarDimensions(_dim);
|
|
132
126
|
target.crs = this.crs;
|
|
133
127
|
target.setFromValues(this.west + _dim.x * 0.5, this.south + _dim.y * 0.5);
|
|
@@ -142,8 +136,7 @@ class Extent {
|
|
|
142
136
|
*
|
|
143
137
|
* @param target - optional target
|
|
144
138
|
*/
|
|
145
|
-
planarDimensions() {
|
|
146
|
-
let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Vector2();
|
|
139
|
+
planarDimensions(target = new Vector2()) {
|
|
147
140
|
// Calculte the dimensions for x and y
|
|
148
141
|
return target.set(Math.abs(this.east - this.west), Math.abs(this.north - this.south));
|
|
149
142
|
}
|
|
@@ -156,8 +149,7 @@ class Extent {
|
|
|
156
149
|
*
|
|
157
150
|
* @param target - optional target
|
|
158
151
|
*/
|
|
159
|
-
geodeticDimensions() {
|
|
160
|
-
let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Vector2();
|
|
152
|
+
geodeticDimensions(target = new Vector2()) {
|
|
161
153
|
// set 3 corners extent
|
|
162
154
|
cNorthWest.crs = this.crs;
|
|
163
155
|
cSouthWest.crs = this.crs;
|
|
@@ -177,8 +169,7 @@ class Extent {
|
|
|
177
169
|
*
|
|
178
170
|
* @param target - optional target
|
|
179
171
|
*/
|
|
180
|
-
spatialEuclideanDimensions() {
|
|
181
|
-
let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Vector2();
|
|
172
|
+
spatialEuclideanDimensions(target = new Vector2()) {
|
|
182
173
|
// set 3 corners extent
|
|
183
174
|
cNorthWest.crs = this.crs;
|
|
184
175
|
cSouthWest.crs = this.crs;
|
|
@@ -198,8 +189,7 @@ class Extent {
|
|
|
198
189
|
* @param epsilon - error margin when comparing to the coordinates.
|
|
199
190
|
* Default is 0.
|
|
200
191
|
*/
|
|
201
|
-
isPointInside(coord) {
|
|
202
|
-
let epsilon = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
192
|
+
isPointInside(coord, epsilon = 0) {
|
|
203
193
|
if (this.crs == coord.crs) {
|
|
204
194
|
_c.copy(coord);
|
|
205
195
|
} else {
|
|
@@ -216,8 +206,7 @@ class Extent {
|
|
|
216
206
|
* @param extent - the extent to check
|
|
217
207
|
* @param epsilon - error margin when comparing the extent bounds.
|
|
218
208
|
*/
|
|
219
|
-
isInside(extent) {
|
|
220
|
-
let epsilon = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : CRS.reasonableEpsilon(this.crs);
|
|
209
|
+
isInside(extent, epsilon = CRS.reasonableEpsilon(this.crs)) {
|
|
221
210
|
extent.as(this.crs, _extent);
|
|
222
211
|
return this.east - _extent.east <= epsilon && _extent.west - this.west <= epsilon && this.north - _extent.north <= epsilon && _extent.south - this.south <= epsilon;
|
|
223
212
|
}
|
|
@@ -233,8 +222,7 @@ class Extent {
|
|
|
233
222
|
* south-north, the `z` property the scale on west-east, the `w` property
|
|
234
223
|
* the scale on south-north.
|
|
235
224
|
*/
|
|
236
|
-
offsetToParent(extent) {
|
|
237
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector4();
|
|
225
|
+
offsetToParent(extent, target = new Vector4()) {
|
|
238
226
|
if (this.crs != extent.crs) {
|
|
239
227
|
throw new Error('unsupported mix');
|
|
240
228
|
}
|
|
@@ -314,8 +302,7 @@ class Extent {
|
|
|
314
302
|
* @param array - the source array
|
|
315
303
|
* @param offset - offset into the array. Default is 0.
|
|
316
304
|
*/
|
|
317
|
-
setFromArray(array) {
|
|
318
|
-
let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
305
|
+
setFromArray(array, offset = 0) {
|
|
319
306
|
this.west = array[offset];
|
|
320
307
|
this.east = array[offset + 1];
|
|
321
308
|
this.south = array[offset + 2];
|
|
@@ -439,8 +426,7 @@ class Extent {
|
|
|
439
426
|
* Return values of extent in string, separated by the separator input.
|
|
440
427
|
* @param sep - string separator
|
|
441
428
|
*/
|
|
442
|
-
toString() {
|
|
443
|
-
let sep = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
429
|
+
toString(sep = '') {
|
|
444
430
|
return `${this.east}${sep}${this.north}${sep}${this.west}${sep}${this.south}`;
|
|
445
431
|
}
|
|
446
432
|
|
|
@@ -461,8 +447,7 @@ class Extent {
|
|
|
461
447
|
* @param scheme - The scheme to subdivise.
|
|
462
448
|
* @returns subdivised extents.
|
|
463
449
|
*/
|
|
464
|
-
subdivisionByScheme() {
|
|
465
|
-
let scheme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultScheme;
|
|
450
|
+
subdivisionByScheme(scheme = defaultScheme) {
|
|
466
451
|
const subdivisedExtents = [];
|
|
467
452
|
const dimSub = this.planarDimensions(_dim).divide(scheme);
|
|
468
453
|
for (let x = scheme.x - 1; x >= 0; x--) {
|
|
@@ -509,9 +494,7 @@ class Extent {
|
|
|
509
494
|
* @param north - The max north
|
|
510
495
|
* @returns this extent
|
|
511
496
|
*/
|
|
512
|
-
clampSouthNorth() {
|
|
513
|
-
let south = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.south;
|
|
514
|
-
let north = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.north;
|
|
497
|
+
clampSouthNorth(south = this.south, north = this.north) {
|
|
515
498
|
this.south = Math.max(this.south, south);
|
|
516
499
|
this.north = Math.min(this.north, north);
|
|
517
500
|
return this;
|
|
@@ -524,9 +507,7 @@ class Extent {
|
|
|
524
507
|
* @param east - The max east
|
|
525
508
|
* @returns this extent
|
|
526
509
|
*/
|
|
527
|
-
clampWestEast() {
|
|
528
|
-
let west = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.west;
|
|
529
|
-
let east = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.east;
|
|
510
|
+
clampWestEast(west = this.west, east = this.east) {
|
|
530
511
|
this.west = Math.max(this.west, west);
|
|
531
512
|
this.east = Math.min(this.east, east);
|
|
532
513
|
return this;
|
package/lib/OrientationUtils.js
CHANGED
|
@@ -19,11 +19,7 @@ const quat = /* @__PURE__ */new Quaternion();
|
|
|
19
19
|
*
|
|
20
20
|
* @returns The target quaternion
|
|
21
21
|
*/
|
|
22
|
-
export function quaternionFromRollPitchHeading() {
|
|
23
|
-
let roll = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
24
|
-
let pitch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
25
|
-
let heading = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
26
|
-
let target = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new Quaternion();
|
|
22
|
+
export function quaternionFromRollPitchHeading(roll = 0, pitch = 0, heading = 0, target = new Quaternion()) {
|
|
27
23
|
roll *= MathUtils.DEG2RAD;
|
|
28
24
|
pitch *= MathUtils.DEG2RAD;
|
|
29
25
|
heading *= MathUtils.DEG2RAD;
|
|
@@ -53,11 +49,7 @@ export function quaternionFromRollPitchHeading() {
|
|
|
53
49
|
*
|
|
54
50
|
* @returns The target quaternion
|
|
55
51
|
*/
|
|
56
|
-
export function quaternionFromOmegaPhiKappa() {
|
|
57
|
-
let omega = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
58
|
-
let phi = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
59
|
-
let kappa = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
60
|
-
let target = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new Quaternion();
|
|
52
|
+
export function quaternionFromOmegaPhiKappa(omega = 0, phi = 0, kappa = 0, target = new Quaternion()) {
|
|
61
53
|
omega *= MathUtils.DEG2RAD;
|
|
62
54
|
phi *= MathUtils.DEG2RAD;
|
|
63
55
|
kappa *= MathUtils.DEG2RAD;
|
|
@@ -76,8 +68,7 @@ export function quaternionFromOmegaPhiKappa() {
|
|
|
76
68
|
*
|
|
77
69
|
* @returns The target quaternion
|
|
78
70
|
*/
|
|
79
|
-
export function quaternionFromAttitude(attitude) {
|
|
80
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Quaternion();
|
|
71
|
+
export function quaternionFromAttitude(attitude, target = new Quaternion()) {
|
|
81
72
|
if ('roll' in attitude || 'pitch' in attitude || 'heading' in attitude) {
|
|
82
73
|
return quaternionFromRollPitchHeading(attitude.roll, attitude.pitch, attitude.heading, target);
|
|
83
74
|
}
|
|
@@ -97,13 +88,11 @@ export function quaternionFromAttitude(attitude) {
|
|
|
97
88
|
* @returns The target quaternion if coordinates is defined. Otherwise, a
|
|
98
89
|
* function to compute it from coordinates.
|
|
99
90
|
*/
|
|
100
|
-
export function quaternionFromEnuToGeocent(coordinates) {
|
|
101
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Quaternion();
|
|
91
|
+
export function quaternionFromEnuToGeocent(coordinates, target = new Quaternion()) {
|
|
102
92
|
if (coordinates) {
|
|
103
93
|
return quaternionFromEnuToGeocent()(coordinates, target);
|
|
104
94
|
}
|
|
105
|
-
return
|
|
106
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Quaternion();
|
|
95
|
+
return (coordinates, target = new Quaternion()) => {
|
|
107
96
|
const up = coordinates.geodesicNormal;
|
|
108
97
|
if (up.x == 0 && up.y == 0) {
|
|
109
98
|
return target.set(0, 0, 0, 1);
|
|
@@ -127,16 +116,12 @@ export function quaternionFromEnuToGeocent(coordinates) {
|
|
|
127
116
|
* @returns The target quaternion if coordinates is defined. Otherwise, a
|
|
128
117
|
* function to compute it from coordinates.
|
|
129
118
|
*/
|
|
130
|
-
export function quaternionFromGeocentToEnu(coordinates) {
|
|
131
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Quaternion();
|
|
119
|
+
export function quaternionFromGeocentToEnu(coordinates, target = new Quaternion()) {
|
|
132
120
|
if (coordinates) {
|
|
133
121
|
return quaternionFromGeocentToEnu()(coordinates, target);
|
|
134
122
|
}
|
|
135
123
|
const toGeocent = quaternionFromEnuToGeocent();
|
|
136
|
-
return
|
|
137
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Quaternion();
|
|
138
|
-
return toGeocent(coordinates, target).conjugate();
|
|
139
|
-
};
|
|
124
|
+
return (coordinates, target = new Quaternion()) => toGeocent(coordinates, target).conjugate();
|
|
140
125
|
}
|
|
141
126
|
/**
|
|
142
127
|
* Computes the rotation from a Lambert Conformal Conic (LCC) frame to the local
|
|
@@ -152,14 +137,12 @@ export function quaternionFromGeocentToEnu(coordinates) {
|
|
|
152
137
|
* @returns The target quaternion if coordinates is defined. Otherwise, a
|
|
153
138
|
* function to compute it from coordinates.
|
|
154
139
|
*/
|
|
155
|
-
export function quaternionFromLCCToEnu(proj, coordinates) {
|
|
156
|
-
let target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Quaternion();
|
|
140
|
+
export function quaternionFromLCCToEnu(proj, coordinates, target = new Quaternion()) {
|
|
157
141
|
if (coordinates) {
|
|
158
142
|
return quaternionFromLCCToEnu(proj)(coordinates, target);
|
|
159
143
|
}
|
|
160
144
|
const sinlat0 = Math.sin(proj.lat0);
|
|
161
|
-
return
|
|
162
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Quaternion();
|
|
145
|
+
return (coordinates, target = new Quaternion()) => {
|
|
163
146
|
const long = coordinates.as(coord.crs, coord).longitude * MathUtils.DEG2RAD;
|
|
164
147
|
return target.setFromAxisAngle(axis, sinlat0 * (proj.long0 - long));
|
|
165
148
|
};
|
|
@@ -177,16 +160,12 @@ export function quaternionFromLCCToEnu(proj, coordinates) {
|
|
|
177
160
|
* @returns The target quaternion if coordinates is defined. Otherwise, a
|
|
178
161
|
* function to compute it from coordinates.
|
|
179
162
|
*/
|
|
180
|
-
export function quaternionFromEnuToLCC(proj, coordinates) {
|
|
181
|
-
let target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Quaternion();
|
|
163
|
+
export function quaternionFromEnuToLCC(proj, coordinates, target = new Quaternion()) {
|
|
182
164
|
if (coordinates) {
|
|
183
165
|
return quaternionFromEnuToLCC(proj)(coordinates, target);
|
|
184
166
|
}
|
|
185
167
|
const fromLCC = quaternionFromLCCToEnu(proj);
|
|
186
|
-
return
|
|
187
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Quaternion();
|
|
188
|
-
return fromLCC(coordinates, target).conjugate();
|
|
189
|
-
};
|
|
168
|
+
return (coordinates, target = new Quaternion()) => fromLCC(coordinates, target).conjugate();
|
|
190
169
|
}
|
|
191
170
|
/**
|
|
192
171
|
* Computes the rotation from a Transverse Mercator frame (TMerc) to the
|
|
@@ -201,8 +180,7 @@ export function quaternionFromEnuToLCC(proj, coordinates) {
|
|
|
201
180
|
* @returns The target quaternion if coordinates is defined. Otherwise, a
|
|
202
181
|
* function to compute it from coordinates.
|
|
203
182
|
*/
|
|
204
|
-
export function quaternionFromTMercToEnu(proj, coordinates) {
|
|
205
|
-
let target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Quaternion();
|
|
183
|
+
export function quaternionFromTMercToEnu(proj, coordinates, target = new Quaternion()) {
|
|
206
184
|
if (coordinates) {
|
|
207
185
|
return quaternionFromTMercToEnu(proj)(coordinates, target);
|
|
208
186
|
}
|
|
@@ -215,8 +193,7 @@ export function quaternionFromTMercToEnu(proj, coordinates) {
|
|
|
215
193
|
const e2 = proj.e * proj.e;
|
|
216
194
|
eta0 = e2 / (1 - e2);
|
|
217
195
|
}
|
|
218
|
-
return
|
|
219
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Quaternion();
|
|
196
|
+
return (coordinates, target = new Quaternion()) => {
|
|
220
197
|
coordinates.as(coord.crs, coord);
|
|
221
198
|
const long = coord.longitude * MathUtils.DEG2RAD;
|
|
222
199
|
const lat = coord.latitude * MathUtils.DEG2RAD;
|
|
@@ -244,16 +221,12 @@ export function quaternionFromTMercToEnu(proj, coordinates) {
|
|
|
244
221
|
* @returns The target quaternion if coordinates is defined. Otherwise, a
|
|
245
222
|
* function to compute it from coordinates.
|
|
246
223
|
*/
|
|
247
|
-
export function quaternionFromEnuToTMerc(proj, coordinates) {
|
|
248
|
-
let target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Quaternion();
|
|
224
|
+
export function quaternionFromEnuToTMerc(proj, coordinates, target = new Quaternion()) {
|
|
249
225
|
if (coordinates) {
|
|
250
226
|
return quaternionFromEnuToTMerc(proj)(coordinates, target);
|
|
251
227
|
}
|
|
252
228
|
const fromTMerc = quaternionFromTMercToEnu(proj);
|
|
253
|
-
return
|
|
254
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Quaternion();
|
|
255
|
-
return fromTMerc(coordinates, target).conjugate();
|
|
256
|
-
};
|
|
229
|
+
return (coordinates, target = new Quaternion()) => fromTMerc(coordinates, target).conjugate();
|
|
257
230
|
}
|
|
258
231
|
/**
|
|
259
232
|
* Computes the rotation from a LongLat frame to the local East North Up
|
|
@@ -266,12 +239,8 @@ export function quaternionFromEnuToTMerc(proj, coordinates) {
|
|
|
266
239
|
* @returns The target quaternion if coordinates is defined, otherwise, a
|
|
267
240
|
* function to compute it from coordinates.
|
|
268
241
|
*/
|
|
269
|
-
export function quaternionFromLongLatToEnu(coordinates) {
|
|
270
|
-
|
|
271
|
-
return coordinates ? target.set(0, 0, 0, 1) : function (coordinates) {
|
|
272
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Quaternion();
|
|
273
|
-
return quaternionFromLongLatToEnu(coordinates, target);
|
|
274
|
-
};
|
|
242
|
+
export function quaternionFromLongLatToEnu(coordinates, target = new Quaternion()) {
|
|
243
|
+
return coordinates ? target.set(0, 0, 0, 1) : (coordinates, target = new Quaternion()) => quaternionFromLongLatToEnu(coordinates, target);
|
|
275
244
|
}
|
|
276
245
|
/**
|
|
277
246
|
* Computes the rotation from the local East North Up (ENU) frame to a
|
|
@@ -283,12 +252,8 @@ export function quaternionFromLongLatToEnu(coordinates) {
|
|
|
283
252
|
* @returns The target quaternion if coordinates is defined, otherwise, a
|
|
284
253
|
* function to compute it from coordinates.
|
|
285
254
|
*/
|
|
286
|
-
export function quaternionFromEnuToLongLat(coordinates) {
|
|
287
|
-
|
|
288
|
-
return coordinates ? target.set(0, 0, 0, 1) : function (coordinates) {
|
|
289
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Quaternion();
|
|
290
|
-
return quaternionFromEnuToLongLat(coordinates, target);
|
|
291
|
-
};
|
|
255
|
+
export function quaternionFromEnuToLongLat(coordinates, target = new Quaternion()) {
|
|
256
|
+
return coordinates ? target.set(0, 0, 0, 1) : (coordinates, target = new Quaternion()) => quaternionFromEnuToLongLat(coordinates, target);
|
|
292
257
|
}
|
|
293
258
|
/**
|
|
294
259
|
* Warns for an unimplemented projection, sets the quaternion to the
|
|
@@ -300,13 +265,9 @@ export function quaternionFromEnuToLongLat(coordinates) {
|
|
|
300
265
|
* @returns The target quaternion if coordinates is defined, otherwise, a
|
|
301
266
|
* function to compute it from coordinates.
|
|
302
267
|
*/
|
|
303
|
-
export function quaternionUnimplemented(proj, coordinates) {
|
|
304
|
-
let target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Quaternion();
|
|
268
|
+
export function quaternionUnimplemented(proj, coordinates, target = new Quaternion()) {
|
|
305
269
|
console.warn('This quaternion function is not implemented for projections of type', proj.projName);
|
|
306
|
-
return coordinates ? target.set(0, 0, 0, 1) :
|
|
307
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Quaternion();
|
|
308
|
-
return quaternionUnimplemented(proj, coordinates, target);
|
|
309
|
-
};
|
|
270
|
+
return coordinates ? target.set(0, 0, 0, 1) : (coordinates, target = new Quaternion()) => quaternionUnimplemented(proj, coordinates, target);
|
|
310
271
|
}
|
|
311
272
|
/**
|
|
312
273
|
* Compute the quaternion that models the rotation from the local East North
|
|
@@ -319,8 +280,7 @@ export function quaternionUnimplemented(proj, coordinates) {
|
|
|
319
280
|
* @returns The target quaternion if coordinates is defined, otherwise, a
|
|
320
281
|
* function to compute it from coordinates.
|
|
321
282
|
*/
|
|
322
|
-
export function quaternionFromEnuToCRS(crsOrProj, coordinates) {
|
|
323
|
-
let target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Quaternion();
|
|
283
|
+
export function quaternionFromEnuToCRS(crsOrProj, coordinates, target = new Quaternion()) {
|
|
324
284
|
if (coordinates) {
|
|
325
285
|
return quaternionFromEnuToCRS(crsOrProj)(coordinates, target);
|
|
326
286
|
}
|
|
@@ -350,8 +310,7 @@ export function quaternionFromEnuToCRS(crsOrProj, coordinates) {
|
|
|
350
310
|
* @returns The target quaternion if coordinates is defined, otherwise, a
|
|
351
311
|
* function to compute it from coordinates.
|
|
352
312
|
*/
|
|
353
|
-
export function quaternionFromCRSToEnu(crsOrProj, coordinates) {
|
|
354
|
-
let target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Quaternion();
|
|
313
|
+
export function quaternionFromCRSToEnu(crsOrProj, coordinates, target = new Quaternion()) {
|
|
355
314
|
if (coordinates) {
|
|
356
315
|
return quaternionFromCRSToEnu(crsOrProj)(coordinates, target);
|
|
357
316
|
}
|
|
@@ -381,23 +340,16 @@ export function quaternionFromCRSToEnu(crsOrProj, coordinates) {
|
|
|
381
340
|
* @returns The target quaternion if coordinates is defined, otherwise, a
|
|
382
341
|
* function to compute it from coordinates.
|
|
383
342
|
*/
|
|
384
|
-
export function quaternionFromCRSToCRS(crsIn, crsOut, coordinates) {
|
|
385
|
-
let target = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new Quaternion();
|
|
343
|
+
export function quaternionFromCRSToCRS(crsIn, crsOut, coordinates, target = new Quaternion()) {
|
|
386
344
|
if (coordinates) {
|
|
387
345
|
return quaternionFromCRSToCRS(crsIn, crsOut)(coordinates, target);
|
|
388
346
|
}
|
|
389
347
|
if (crsIn == crsOut) {
|
|
390
|
-
return
|
|
391
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Quaternion();
|
|
392
|
-
return target.set(0, 0, 0, 1);
|
|
393
|
-
};
|
|
348
|
+
return (origin, target = new Quaternion()) => target.set(0, 0, 0, 1);
|
|
394
349
|
}
|
|
395
350
|
|
|
396
351
|
// get rotations from the local East/North/Up (ENU) frame to both CRS.
|
|
397
352
|
const fromCrs = quaternionFromCRSToEnu(crsIn);
|
|
398
353
|
const toCrs = quaternionFromEnuToCRS(crsOut);
|
|
399
|
-
return
|
|
400
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Quaternion();
|
|
401
|
-
return toCrs(origin, target).multiply(fromCrs(origin, quat));
|
|
402
|
-
};
|
|
354
|
+
return (origin, target = new Quaternion()) => toCrs(origin, target).multiply(fromCrs(origin, quat));
|
|
403
355
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itowns/geographic",
|
|
3
|
-
"version": "2.46.1-next.
|
|
3
|
+
"version": "2.46.1-next.10",
|
|
4
4
|
"description": "Geodesy",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"lint": "eslint \"src/**/*.{js,ts,tsx}\" \"test/**/*.js\"",
|
|
15
15
|
"transpile": "tsc && cross-env BABEL_DISABLE_CACHE=1 babel src --out-dir lib --extensions .js,.ts",
|
|
16
16
|
"test-unit": "npm run base-test-unit test/unit",
|
|
17
|
-
"base-test-unit": "cross-env BABEL_DISABLE_CACHE=1 mocha --import=../../config/babel-register/register.mjs",
|
|
17
|
+
"base-test-unit": "cross-env BABEL_DISABLE_CACHE=1 NODE_OPTIONS=--no-experimental-strip-types mocha --import=../../config/babel-register/register.mjs",
|
|
18
18
|
"test-with-coverage": "c8 -n src -r html cross-env npm run test-unit",
|
|
19
19
|
"test-with-coverage_lcov": "c8 -n src --reporter=lcov cross-env npm run test-unit",
|
|
20
20
|
"watch": "npm run transpile -- --watch",
|
package/src/Crs.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import proj4 from 'proj4';
|
|
2
|
-
|
|
3
2
|
import type { ProjectionDefinition } from 'proj4/dist/lib/defs';
|
|
4
3
|
|
|
4
|
+
type proj4Def = {
|
|
5
|
+
type: string,
|
|
6
|
+
PROJCS: proj4Def,
|
|
7
|
+
unknown?: string,
|
|
8
|
+
(alias: string): proj4Def & { name: string },
|
|
9
|
+
title: string,
|
|
10
|
+
}
|
|
11
|
+
|
|
5
12
|
proj4.defs('EPSG:4978', '+proj=geocent +datum=WGS84 +units=m +no_defs');
|
|
6
13
|
|
|
7
14
|
// Redefining proj4 global projections to match epsg.org database axis order.
|
|
@@ -174,3 +181,21 @@ export function axisOrder(crs: ProjectionLike) {
|
|
|
174
181
|
* @param proj4def - Proj4 or WKT string of the defined projection.
|
|
175
182
|
*/
|
|
176
183
|
export const defs = (code: string, proj4def: string) => proj4.defs(code, proj4def);
|
|
184
|
+
|
|
185
|
+
export function defsFromWkt(wkt: string) {
|
|
186
|
+
proj4.defs('unknown', wkt);
|
|
187
|
+
const proj4Defs = proj4.defs as unknown as proj4Def;
|
|
188
|
+
let projCS;
|
|
189
|
+
if (proj4Defs('unknown').type === 'COMPD_CS') {
|
|
190
|
+
console.warn('Compound coordinate system is not yet supported.');
|
|
191
|
+
projCS = proj4Defs('unknown').PROJCS;
|
|
192
|
+
} else {
|
|
193
|
+
projCS = proj4Defs('unknown');
|
|
194
|
+
}
|
|
195
|
+
const crsAlias = projCS.title || projCS.name || 'EPSG:XXXX';
|
|
196
|
+
if (!(crsAlias in proj4.defs)) {
|
|
197
|
+
proj4.defs(crsAlias, projCS);
|
|
198
|
+
}
|
|
199
|
+
delete proj4Defs.unknown;
|
|
200
|
+
return crsAlias;
|
|
201
|
+
}
|