@itowns/geographic 2.45.1-next.0 → 2.45.1-next.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.
- package/lib/CoordStars.d.ts +13 -0
- package/lib/CoordStars.js +89 -0
- package/lib/Coordinates.d.ts +196 -0
- package/lib/Coordinates.js +331 -0
- package/lib/Crs.d.ts +93 -0
- package/lib/Crs.js +170 -0
- package/lib/Ellipsoid.d.ts +74 -0
- package/lib/Ellipsoid.js +186 -0
- package/lib/Extent.d.ts +246 -0
- package/lib/Extent.js +550 -0
- package/lib/Main.d.ts +6 -0
- package/lib/Main.js +7 -0
- package/lib/OrientationUtils.d.ts +105 -0
- package/lib/OrientationUtils.js +402 -0
- package/package.json +1 -1
package/lib/Extent.js
ADDED
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import Coordinates from "./Coordinates.js";
|
|
3
|
+
import * as CRS from "./Crs.js";
|
|
4
|
+
const _dim = new THREE.Vector2();
|
|
5
|
+
const _dim2 = new THREE.Vector2();
|
|
6
|
+
const _box = new THREE.Box3();
|
|
7
|
+
const defaultScheme = new THREE.Vector2(2, 2);
|
|
8
|
+
const cNorthWest = new Coordinates('EPSG:4326', 0, 0, 0);
|
|
9
|
+
const cSouthWest = new Coordinates('EPSG:4326', 0, 0, 0);
|
|
10
|
+
const cNorthEast = new Coordinates('EPSG:4326', 0, 0, 0);
|
|
11
|
+
const southWest = new THREE.Vector3();
|
|
12
|
+
const northEast = new THREE.Vector3();
|
|
13
|
+
let _extent;
|
|
14
|
+
const cardinals = new Array(8);
|
|
15
|
+
for (let i = cardinals.length - 1; i >= 0; i--) {
|
|
16
|
+
cardinals[i] = new Coordinates('EPSG:4326', 0, 0, 0);
|
|
17
|
+
}
|
|
18
|
+
const _c = new Coordinates('EPSG:4326', 0, 0);
|
|
19
|
+
/**
|
|
20
|
+
* A class representing a geographical extent.
|
|
21
|
+
*
|
|
22
|
+
* An extent is a geographical bounding rectangle defined by 4 limits: west,
|
|
23
|
+
* east, south and north.
|
|
24
|
+
*
|
|
25
|
+
* **Warning**: Using a geocentric projection is not suitable for representing a
|
|
26
|
+
* geographical extent. Please use a geographic projection.
|
|
27
|
+
*/
|
|
28
|
+
class Extent {
|
|
29
|
+
/**
|
|
30
|
+
* Read-only flag to check if a given object is of type `Extent`.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A default or user-defined CRS (see {@link ProjectionLike}).
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* West longitude bound of this extent.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* East longitude bound of this extent.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* South latitude bound of this extent.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* North latitude bound of this extent.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @param crs - A default or user-defined CRS (see {@link ProjectionLike}).
|
|
55
|
+
* @param west - the `west` value of this extent. Default is 0.
|
|
56
|
+
* @param east - the `east` value of this extent. Default is 0.
|
|
57
|
+
* @param south - the `south` value of this extent. Default is 0.
|
|
58
|
+
* @param north - the `north` value of this extent. Default is 0.
|
|
59
|
+
*/
|
|
60
|
+
constructor(crs) {
|
|
61
|
+
let west = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
62
|
+
let east = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
63
|
+
let south = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
64
|
+
let north = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
65
|
+
if (CRS.isGeocentric(crs)) {
|
|
66
|
+
throw new Error(`Non-compatible geocentric projection ${crs} to build a geographical extent`);
|
|
67
|
+
}
|
|
68
|
+
this.isExtent = true;
|
|
69
|
+
this.crs = crs;
|
|
70
|
+
this.west = 0;
|
|
71
|
+
this.east = 0;
|
|
72
|
+
this.south = 0;
|
|
73
|
+
this.north = 0;
|
|
74
|
+
this.set(west, east, south, north);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Returns a new extent with the same bounds and crs as this one.
|
|
79
|
+
*/
|
|
80
|
+
clone() {
|
|
81
|
+
return new Extent(this.crs, this.west, this.east, this.south, this.north);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Projects this extent to the specified projection.
|
|
86
|
+
*
|
|
87
|
+
* @param crs - target's projection.
|
|
88
|
+
* @param target - The target to store the projected extent. If this not
|
|
89
|
+
* provided a new extent will be created.
|
|
90
|
+
*/
|
|
91
|
+
as(crs) {
|
|
92
|
+
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Extent('EPSG:4326');
|
|
93
|
+
CRS.isValid(crs);
|
|
94
|
+
if (this.crs != crs) {
|
|
95
|
+
// Compute min/max in x/y by projecting 8 cardinal points,
|
|
96
|
+
// and then taking the min/max of each coordinates.
|
|
97
|
+
const center = this.center(_c);
|
|
98
|
+
cardinals[0].setFromValues(this.west, this.north);
|
|
99
|
+
cardinals[1].setFromValues(center.x, this.north);
|
|
100
|
+
cardinals[2].setFromValues(this.east, this.north);
|
|
101
|
+
cardinals[3].setFromValues(this.east, center.y);
|
|
102
|
+
cardinals[4].setFromValues(this.east, this.south);
|
|
103
|
+
cardinals[5].setFromValues(center.x, this.south);
|
|
104
|
+
cardinals[6].setFromValues(this.west, this.south);
|
|
105
|
+
cardinals[7].setFromValues(this.west, center.y);
|
|
106
|
+
target.set(Infinity, -Infinity, Infinity, -Infinity);
|
|
107
|
+
|
|
108
|
+
// loop over the coordinates
|
|
109
|
+
for (let i = 0; i < cardinals.length; i++) {
|
|
110
|
+
// convert the coordinate.
|
|
111
|
+
cardinals[i].crs = this.crs;
|
|
112
|
+
cardinals[i].as(crs, _c);
|
|
113
|
+
target.north = Math.max(target.north, _c.y);
|
|
114
|
+
target.south = Math.min(target.south, _c.y);
|
|
115
|
+
target.east = Math.max(target.east, _c.x);
|
|
116
|
+
target.west = Math.min(target.west, _c.x);
|
|
117
|
+
}
|
|
118
|
+
target.crs = crs;
|
|
119
|
+
return target;
|
|
120
|
+
}
|
|
121
|
+
target.crs = crs;
|
|
122
|
+
target.set(this.west, this.east, this.south, this.north);
|
|
123
|
+
return target;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Returns the center of the extent.
|
|
128
|
+
*
|
|
129
|
+
* @param target - The target to store the center coordinate. If this not
|
|
130
|
+
* provided a new coordinate will be created.
|
|
131
|
+
*/
|
|
132
|
+
center() {
|
|
133
|
+
let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Coordinates(this.crs);
|
|
134
|
+
this.planarDimensions(_dim);
|
|
135
|
+
target.crs = this.crs;
|
|
136
|
+
target.setFromValues(this.west + _dim.x * 0.5, this.south + _dim.y * 0.5);
|
|
137
|
+
return target;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Returns the planar dimensions as two-vector planar distances west/east
|
|
142
|
+
* and south/north.
|
|
143
|
+
* The planar distance is a straight-line Euclidean distance calculated in a
|
|
144
|
+
* 2D Cartesian coordinate system.
|
|
145
|
+
*
|
|
146
|
+
* @param target - optional target
|
|
147
|
+
*/
|
|
148
|
+
planarDimensions() {
|
|
149
|
+
let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new THREE.Vector2();
|
|
150
|
+
// Calculte the dimensions for x and y
|
|
151
|
+
return target.set(Math.abs(this.east - this.west), Math.abs(this.north - this.south));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Returns the geodetic dimensions as two-vector planar distances west/east
|
|
156
|
+
* and south/north.
|
|
157
|
+
* Geodetic distance is calculated in an ellispoid space as the distance
|
|
158
|
+
* across the curved surface of the ellipsoid.
|
|
159
|
+
*
|
|
160
|
+
* @param target - optional target
|
|
161
|
+
*/
|
|
162
|
+
geodeticDimensions() {
|
|
163
|
+
let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new THREE.Vector2();
|
|
164
|
+
// set 3 corners extent
|
|
165
|
+
cNorthWest.crs = this.crs;
|
|
166
|
+
cSouthWest.crs = this.crs;
|
|
167
|
+
cNorthEast.crs = this.crs;
|
|
168
|
+
cNorthWest.setFromValues(this.west, this.north, 0);
|
|
169
|
+
cSouthWest.setFromValues(this.west, this.south, 0);
|
|
170
|
+
cNorthEast.setFromValues(this.east, this.north, 0);
|
|
171
|
+
|
|
172
|
+
// calcul geodetic distance northWest/northEast and northWest/southWest
|
|
173
|
+
return target.set(cNorthWest.geodeticDistanceTo(cNorthEast), cNorthWest.geodeticDistanceTo(cSouthWest));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Returns the spatial euclidean dimensions as a two-vector spatial
|
|
178
|
+
* euclidean distances between west/east corner and south/north corner.
|
|
179
|
+
* Spatial euclidean distance chord is calculated in an ellispoid space.
|
|
180
|
+
*
|
|
181
|
+
* @param target - optional target
|
|
182
|
+
*/
|
|
183
|
+
spatialEuclideanDimensions() {
|
|
184
|
+
let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new THREE.Vector2();
|
|
185
|
+
// set 3 corners extent
|
|
186
|
+
cNorthWest.crs = this.crs;
|
|
187
|
+
cSouthWest.crs = this.crs;
|
|
188
|
+
cNorthEast.crs = this.crs;
|
|
189
|
+
cNorthWest.setFromValues(this.west, this.north, 0);
|
|
190
|
+
cSouthWest.setFromValues(this.west, this.south, 0);
|
|
191
|
+
cNorthEast.setFromValues(this.east, this.north, 0);
|
|
192
|
+
|
|
193
|
+
// calcul chord distance northWest/northEast and northWest/southWest
|
|
194
|
+
return target.set(cNorthWest.spatialEuclideanDistanceTo(cNorthEast), cNorthWest.spatialEuclideanDistanceTo(cSouthWest));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Checks whether a coordinates is inside the extent.
|
|
199
|
+
*
|
|
200
|
+
* @param coord - the given coordinates.
|
|
201
|
+
* @param epsilon - error margin when comparing to the coordinates.
|
|
202
|
+
* Default is 0.
|
|
203
|
+
*/
|
|
204
|
+
isPointInside(coord) {
|
|
205
|
+
let epsilon = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
206
|
+
if (this.crs == coord.crs) {
|
|
207
|
+
_c.copy(coord);
|
|
208
|
+
} else {
|
|
209
|
+
coord.as(this.crs, _c);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// TODO this ignores altitude
|
|
213
|
+
return _c.x <= this.east + epsilon && _c.x >= this.west - epsilon && _c.y <= this.north + epsilon && _c.y >= this.south - epsilon;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Checks whether another extent is inside the extent.
|
|
218
|
+
*
|
|
219
|
+
* @param extent - the extent to check
|
|
220
|
+
* @param epsilon - error margin when comparing the extent bounds.
|
|
221
|
+
*/
|
|
222
|
+
isInside(extent) {
|
|
223
|
+
let epsilon = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : CRS.reasonableEpsilon(this.crs);
|
|
224
|
+
extent.as(this.crs, _extent);
|
|
225
|
+
return this.east - _extent.east <= epsilon && _extent.west - this.west <= epsilon && this.north - _extent.north <= epsilon && _extent.south - this.south <= epsilon;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Return the translation and scale to transform this extent to the input
|
|
230
|
+
* extent.
|
|
231
|
+
*
|
|
232
|
+
* @param extent - input extent
|
|
233
|
+
* @param target - copy the result to target.
|
|
234
|
+
* @returns A {@link THREE.Vector4} where the `x` property encodes the
|
|
235
|
+
* translation on west-east, the `y` property the translation on
|
|
236
|
+
* south-north, the `z` property the scale on west-east, the `w` property
|
|
237
|
+
* the scale on south-north.
|
|
238
|
+
*/
|
|
239
|
+
offsetToParent(extent) {
|
|
240
|
+
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new THREE.Vector4();
|
|
241
|
+
if (this.crs != extent.crs) {
|
|
242
|
+
throw new Error('unsupported mix');
|
|
243
|
+
}
|
|
244
|
+
extent.planarDimensions(_dim);
|
|
245
|
+
this.planarDimensions(_dim2);
|
|
246
|
+
const originX = (this.west - extent.west) / _dim.x;
|
|
247
|
+
const originY = (extent.north - this.north) / _dim.y;
|
|
248
|
+
const scaleX = _dim2.x / _dim.x;
|
|
249
|
+
const scaleY = _dim2.y / _dim.y;
|
|
250
|
+
return target.set(originX, originY, scaleX, scaleY);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Checks wheter this bounding box intersects with the given extent
|
|
255
|
+
* parameter.
|
|
256
|
+
* @param extent - the provided extent
|
|
257
|
+
*/
|
|
258
|
+
intersectsExtent(extent) {
|
|
259
|
+
return Extent.intersectsExtent(this, extent);
|
|
260
|
+
}
|
|
261
|
+
static intersectsExtent(extentA, extentB) {
|
|
262
|
+
// TODO don't work when is on limit
|
|
263
|
+
const other = extentB.crs == extentA.crs ? extentB : extentB.as(extentA.crs, _extent);
|
|
264
|
+
return !(extentA.west >= other.east || extentA.east <= other.west || extentA.south >= other.north || extentA.north <= other.south);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Returns the intersection of this extent with another one.
|
|
269
|
+
* @param extent - extent to intersect
|
|
270
|
+
*/
|
|
271
|
+
intersect(extent) {
|
|
272
|
+
if (!this.intersectsExtent(extent)) {
|
|
273
|
+
return new Extent(this.crs);
|
|
274
|
+
}
|
|
275
|
+
if (extent.crs != this.crs) {
|
|
276
|
+
extent = extent.as(this.crs, _extent);
|
|
277
|
+
}
|
|
278
|
+
return new Extent(this.crs, Math.max(this.west, extent.west), Math.min(this.east, extent.east), Math.max(this.south, extent.south), Math.min(this.north, extent.north));
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Set west, east, south and north values.
|
|
283
|
+
*
|
|
284
|
+
* @param v0 - the `west` value of this extent. Default is 0.
|
|
285
|
+
* @param v1 - the `east` value of this extent. Default is 0.
|
|
286
|
+
* @param v2 - the `south` value of this extent. Default is 0.
|
|
287
|
+
* @param v3 - the `north` value of this extent. Default is 0.
|
|
288
|
+
*/
|
|
289
|
+
set(v0, v1, v2, v3) {
|
|
290
|
+
if (v0 == undefined) {
|
|
291
|
+
throw new Error('No values to set in the extent');
|
|
292
|
+
}
|
|
293
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
294
|
+
if (v0.west !== undefined) {
|
|
295
|
+
console.warn('Deprecated Extent#constructor(string, Extent) and Extent#set(Extent),', 'use new Extent(string).setFromExtent(Extent) instead.');
|
|
296
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
297
|
+
this.setFromExtent(v0);
|
|
298
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
299
|
+
} else if (v0.length == 4) {
|
|
300
|
+
// deepscan-disable-line
|
|
301
|
+
console.warn('Deprecated Extent#constructor(string, number[]) and Extent#set(number[]),', 'use new Extent(string).setFromArray(number[]) instead.');
|
|
302
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
303
|
+
this.setFromArray(v0);
|
|
304
|
+
} else if (v3 !== undefined) {
|
|
305
|
+
this.west = v0;
|
|
306
|
+
this.east = v1;
|
|
307
|
+
this.south = v2;
|
|
308
|
+
this.north = v3;
|
|
309
|
+
}
|
|
310
|
+
return this;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Sets this extent `west` property to `array[offset + 0]`, `east` property
|
|
315
|
+
* to `array[offset + 1]`, `south` property to `array[offset + 2]` and
|
|
316
|
+
* `north` property to `array[offset + 3]`.
|
|
317
|
+
* @param array - the source array
|
|
318
|
+
* @param offset - offset into the array. Default is 0.
|
|
319
|
+
*/
|
|
320
|
+
setFromArray(array) {
|
|
321
|
+
let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
322
|
+
this.west = array[offset];
|
|
323
|
+
this.east = array[offset + 1];
|
|
324
|
+
this.south = array[offset + 2];
|
|
325
|
+
this.north = array[offset + 3];
|
|
326
|
+
return this;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Sets this extent `west`, `east`, `south` and `north` properties from an
|
|
331
|
+
* `extent` bounds.
|
|
332
|
+
* @param extent - the source extent
|
|
333
|
+
*/
|
|
334
|
+
setFromExtent(extent) {
|
|
335
|
+
this.west = extent.west;
|
|
336
|
+
this.east = extent.east;
|
|
337
|
+
this.south = extent.south;
|
|
338
|
+
this.north = extent.north;
|
|
339
|
+
return this;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Copies the passed extent to this extent.
|
|
344
|
+
* @param extent - extent to copy.
|
|
345
|
+
*/
|
|
346
|
+
copy(extent) {
|
|
347
|
+
this.crs = extent.crs;
|
|
348
|
+
return this.setFromExtent(extent);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Union this extent with the input extent.
|
|
353
|
+
* @param extent - the extent to union.
|
|
354
|
+
*/
|
|
355
|
+
union(extent) {
|
|
356
|
+
if (extent.crs != this.crs) {
|
|
357
|
+
throw new Error('unsupported union between 2 diff crs');
|
|
358
|
+
}
|
|
359
|
+
if (this.west === Infinity) {
|
|
360
|
+
this.copy(extent);
|
|
361
|
+
} else {
|
|
362
|
+
const west = extent.west;
|
|
363
|
+
if (west < this.west) {
|
|
364
|
+
this.west = west;
|
|
365
|
+
}
|
|
366
|
+
const east = extent.east;
|
|
367
|
+
if (east > this.east) {
|
|
368
|
+
this.east = east;
|
|
369
|
+
}
|
|
370
|
+
const south = extent.south;
|
|
371
|
+
if (south < this.south) {
|
|
372
|
+
this.south = south;
|
|
373
|
+
}
|
|
374
|
+
const north = extent.north;
|
|
375
|
+
if (north > this.north) {
|
|
376
|
+
this.north = north;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* expandByCoordinates perfoms the minimal extension
|
|
383
|
+
* for the coordinates to belong to this Extent object
|
|
384
|
+
* @param coordinates - The coordinates to belong
|
|
385
|
+
*/
|
|
386
|
+
expandByCoordinates(coordinates) {
|
|
387
|
+
const coords = coordinates.crs == this.crs ? coordinates : coordinates.as(this.crs, _c);
|
|
388
|
+
this.expandByValuesCoordinates(coords.x, coords.y);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* expandByValuesCoordinates perfoms the minimal extension
|
|
393
|
+
* for the coordinates values to belong to this Extent object
|
|
394
|
+
* @param we - The coordinate on west-east
|
|
395
|
+
* @param sn - The coordinate on south-north
|
|
396
|
+
*
|
|
397
|
+
*/
|
|
398
|
+
expandByValuesCoordinates(we, sn) {
|
|
399
|
+
if (we < this.west) {
|
|
400
|
+
this.west = we;
|
|
401
|
+
}
|
|
402
|
+
if (we > this.east) {
|
|
403
|
+
this.east = we;
|
|
404
|
+
}
|
|
405
|
+
if (sn < this.south) {
|
|
406
|
+
this.south = sn;
|
|
407
|
+
}
|
|
408
|
+
if (sn > this.north) {
|
|
409
|
+
this.north = sn;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Instance Extent with THREE.Box3.
|
|
415
|
+
*
|
|
416
|
+
* If crs is a geocentric projection, the `box3.min` and `box3.max`
|
|
417
|
+
* should be the geocentric coordinates of `min` and `max` of a `box3`
|
|
418
|
+
* in local tangent plane.
|
|
419
|
+
*
|
|
420
|
+
* @param crs - Projection of extent to instancied.
|
|
421
|
+
* @param box - Bounding-box
|
|
422
|
+
*/
|
|
423
|
+
static fromBox3(crs, box) {
|
|
424
|
+
if (CRS.isGeocentric(crs)) {
|
|
425
|
+
// if geocentric reproject box on 'EPSG:4326'
|
|
426
|
+
crs = 'EPSG:4326';
|
|
427
|
+
box = _box.copy(box);
|
|
428
|
+
cSouthWest.crs = crs;
|
|
429
|
+
cSouthWest.setFromVector3(box.min).as(crs, cSouthWest).toVector3(box.min);
|
|
430
|
+
cNorthEast.crs = crs;
|
|
431
|
+
cNorthEast.setFromVector3(box.max).as(crs, cNorthEast).toVector3(box.max);
|
|
432
|
+
}
|
|
433
|
+
return new Extent(crs).setFromExtent({
|
|
434
|
+
west: box.min.x,
|
|
435
|
+
east: box.max.x,
|
|
436
|
+
south: box.min.y,
|
|
437
|
+
north: box.max.y
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Return values of extent in string, separated by the separator input.
|
|
443
|
+
* @param sep - string separator
|
|
444
|
+
*/
|
|
445
|
+
toString() {
|
|
446
|
+
let sep = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
447
|
+
return `${this.east}${sep}${this.north}${sep}${this.west}${sep}${this.south}`;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Subdivide equally an extent from its center to return four extents:
|
|
452
|
+
* north-west, north-east, south-west and south-east.
|
|
453
|
+
*
|
|
454
|
+
* @returns An array containing the four sections of the extent. The order
|
|
455
|
+
* of the sections is [NW, NE, SW, SE].
|
|
456
|
+
*/
|
|
457
|
+
subdivision() {
|
|
458
|
+
return this.subdivisionByScheme();
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* subdivise extent by scheme.x on west-east and scheme.y on south-north.
|
|
463
|
+
*
|
|
464
|
+
* @param scheme - The scheme to subdivise.
|
|
465
|
+
* @returns subdivised extents.
|
|
466
|
+
*/
|
|
467
|
+
subdivisionByScheme() {
|
|
468
|
+
let scheme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultScheme;
|
|
469
|
+
const subdivisedExtents = [];
|
|
470
|
+
const dimSub = this.planarDimensions(_dim).divide(scheme);
|
|
471
|
+
for (let x = scheme.x - 1; x >= 0; x--) {
|
|
472
|
+
for (let y = scheme.y - 1; y >= 0; y--) {
|
|
473
|
+
const west = this.west + x * dimSub.x;
|
|
474
|
+
const south = this.south + y * dimSub.y;
|
|
475
|
+
subdivisedExtents.push(new Extent(this.crs, west, west + dimSub.x, south, south + dimSub.y));
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
return subdivisedExtents;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Multiplies all extent `coordinates` (with an implicit 1 in the 4th
|
|
483
|
+
* dimension) and `matrix`.
|
|
484
|
+
*
|
|
485
|
+
* @param matrix - The matrix
|
|
486
|
+
* @returns return this extent instance.
|
|
487
|
+
*/
|
|
488
|
+
applyMatrix4(matrix) {
|
|
489
|
+
southWest.set(this.west, this.south, 0).applyMatrix4(matrix);
|
|
490
|
+
northEast.set(this.east, this.north, 0).applyMatrix4(matrix);
|
|
491
|
+
this.west = southWest.x;
|
|
492
|
+
this.east = northEast.x;
|
|
493
|
+
this.south = southWest.y;
|
|
494
|
+
this.north = northEast.y;
|
|
495
|
+
if (this.west > this.east) {
|
|
496
|
+
const temp = this.west;
|
|
497
|
+
this.west = this.east;
|
|
498
|
+
this.east = temp;
|
|
499
|
+
}
|
|
500
|
+
if (this.south > this.north) {
|
|
501
|
+
const temp = this.south;
|
|
502
|
+
this.south = this.north;
|
|
503
|
+
this.north = temp;
|
|
504
|
+
}
|
|
505
|
+
return this;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* clamp south and north values
|
|
510
|
+
*
|
|
511
|
+
* @param south - The min south
|
|
512
|
+
* @param north - The max north
|
|
513
|
+
* @returns this extent
|
|
514
|
+
*/
|
|
515
|
+
clampSouthNorth() {
|
|
516
|
+
let south = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.south;
|
|
517
|
+
let north = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.north;
|
|
518
|
+
this.south = Math.max(this.south, south);
|
|
519
|
+
this.north = Math.min(this.north, north);
|
|
520
|
+
return this;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* clamp west and east values
|
|
525
|
+
*
|
|
526
|
+
* @param west - The min west
|
|
527
|
+
* @param east - The max east
|
|
528
|
+
* @returns this extent
|
|
529
|
+
*/
|
|
530
|
+
clampWestEast() {
|
|
531
|
+
let west = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.west;
|
|
532
|
+
let east = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.east;
|
|
533
|
+
this.west = Math.max(this.west, west);
|
|
534
|
+
this.east = Math.min(this.east, east);
|
|
535
|
+
return this;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* clamp this extent by passed extent
|
|
540
|
+
*
|
|
541
|
+
* @param extent - The maximum extent.
|
|
542
|
+
* @returns this extent.
|
|
543
|
+
*/
|
|
544
|
+
clampByExtent(extent) {
|
|
545
|
+
this.clampSouthNorth(extent.south, extent.north);
|
|
546
|
+
return this.clampWestEast(extent.west, extent.east);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
_extent = new Extent('EPSG:4326');
|
|
550
|
+
export default Extent;
|
package/lib/Main.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as Extent } from './Extent';
|
|
2
|
+
export { default as Coordinates } from './Coordinates';
|
|
3
|
+
export * as CRS from './Crs';
|
|
4
|
+
export { default as CoordStars } from './CoordStars';
|
|
5
|
+
export * as OrientationUtils from './OrientationUtils';
|
|
6
|
+
export { default as Ellipsoid, ellipsoidSizes } from './Ellipsoid';
|
package/lib/Main.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Geodesic tools
|
|
2
|
+
export { default as Extent } from "./Extent.js";
|
|
3
|
+
export { default as Coordinates } from "./Coordinates.js";
|
|
4
|
+
export * as CRS from "./Crs.js";
|
|
5
|
+
export { default as CoordStars } from "./CoordStars.js";
|
|
6
|
+
export * as OrientationUtils from "./OrientationUtils.js";
|
|
7
|
+
export { default as Ellipsoid, ellipsoidSizes } from "./Ellipsoid.js";
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Quaternion } from 'three';
|
|
2
|
+
import type { ProjectionDefinition } from 'proj4';
|
|
3
|
+
import Coordinates from './Coordinates';
|
|
4
|
+
interface EulerAngles {
|
|
5
|
+
/** angle in degrees */
|
|
6
|
+
roll: number;
|
|
7
|
+
/** angle in degrees */
|
|
8
|
+
pitch: number;
|
|
9
|
+
/** angle in degrees */
|
|
10
|
+
heading: number;
|
|
11
|
+
}
|
|
12
|
+
interface PhotogrammetryAngles {
|
|
13
|
+
/** angle in degrees */
|
|
14
|
+
omega: number;
|
|
15
|
+
/** angle in degrees */
|
|
16
|
+
phi: number;
|
|
17
|
+
/** angle in degrees */
|
|
18
|
+
kappa: number;
|
|
19
|
+
}
|
|
20
|
+
type Attitude = Partial<EulerAngles> | Partial<PhotogrammetryAngles>;
|
|
21
|
+
type QuaternionFunction = (coords: Coordinates, target?: Quaternion) => Quaternion;
|
|
22
|
+
type ProjectionLike = ProjectionDefinition | string;
|
|
23
|
+
type LCCProjection = {
|
|
24
|
+
long0: number;
|
|
25
|
+
lat0: number;
|
|
26
|
+
};
|
|
27
|
+
type TMercProjection = {
|
|
28
|
+
a: number;
|
|
29
|
+
b: number;
|
|
30
|
+
e?: number;
|
|
31
|
+
long0: number;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The transform from the platform frame to the local East, North, Up (ENU)
|
|
35
|
+
* frame is `RotationZ(heading).RotationX(pitch).RotationY(roll)`.
|
|
36
|
+
*
|
|
37
|
+
* @param roll - angle in degrees. Default is 0.
|
|
38
|
+
* @param pitch - angle in degrees. Default is 0.
|
|
39
|
+
* @param heading - angle in degrees. Default is 0
|
|
40
|
+
* @param target - output Quaternion
|
|
41
|
+
*
|
|
42
|
+
* @returns The target quaternion
|
|
43
|
+
*/
|
|
44
|
+
export declare function quaternionFromRollPitchHeading(roll?: number, pitch?: number, heading?: number, target?: Quaternion): Quaternion;
|
|
45
|
+
/**
|
|
46
|
+
* From
|
|
47
|
+
* [DocMicMac](https://github.com/micmacIGN/Documentation/raw/master/DocMicMac.pdf),
|
|
48
|
+
* the transform from the platform frame to the local East, North, Up (ENU)
|
|
49
|
+
* frame is:
|
|
50
|
+
*
|
|
51
|
+
* ```
|
|
52
|
+
* RotationX(omega).RotationY(phi).RotationZ(kappa).RotationX(PI)
|
|
53
|
+
* Converts between the 2 conventions for the camera local frame:
|
|
54
|
+
* RotationX(PI) <=> Quaternion(1,0,0,0)
|
|
55
|
+
* X right, Y bottom, Z front : convention in photogrammetry and computer vision
|
|
56
|
+
* X right, Y top, Z back : convention in webGL, threejs
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @param omega - angle in degrees. Default is 0.
|
|
60
|
+
* @param phi - angle in degrees. Default is 0.
|
|
61
|
+
* @param kappa - angle in degrees. Default is 0.
|
|
62
|
+
* @param target - output quaternion
|
|
63
|
+
*
|
|
64
|
+
* @returns The target quaternion
|
|
65
|
+
*/
|
|
66
|
+
export declare function quaternionFromOmegaPhiKappa(omega?: number, phi?: number, kappa?: number, target?: Quaternion): Quaternion;
|
|
67
|
+
/**
|
|
68
|
+
* Sets the quaternion according to the rotation from the platform frame to the
|
|
69
|
+
* local frame.
|
|
70
|
+
*
|
|
71
|
+
* @param attitude - either euler angles or photogrammetry angles
|
|
72
|
+
* @param target - output Quaternion
|
|
73
|
+
*
|
|
74
|
+
* @returns The target quaternion
|
|
75
|
+
*/
|
|
76
|
+
export declare function quaternionFromAttitude(attitude: Attitude, target?: Quaternion): Quaternion;
|
|
77
|
+
export declare function quaternionFromEnuToGeocent(): QuaternionFunction;
|
|
78
|
+
export declare function quaternionFromEnuToGeocent(coords: Coordinates, target?: Quaternion): Quaternion;
|
|
79
|
+
export declare function quaternionFromGeocentToEnu(): QuaternionFunction;
|
|
80
|
+
export declare function quaternionFromGeocentToEnu(coords: Coordinates, target?: Quaternion): Quaternion;
|
|
81
|
+
export declare function quaternionFromLCCToEnu(proj: LCCProjection): QuaternionFunction;
|
|
82
|
+
export declare function quaternionFromLCCToEnu(proj: LCCProjection, coords: Coordinates, target?: Quaternion): Quaternion;
|
|
83
|
+
export declare function quaternionFromEnuToLCC(proj: LCCProjection): QuaternionFunction;
|
|
84
|
+
export declare function quaternionFromEnuToLCC(proj: LCCProjection, coords: Coordinates, target?: Quaternion): Quaternion;
|
|
85
|
+
export declare function quaternionFromTMercToEnu(proj: TMercProjection): QuaternionFunction;
|
|
86
|
+
export declare function quaternionFromTMercToEnu(proj: TMercProjection, coords: Coordinates, target?: Quaternion): Quaternion;
|
|
87
|
+
export declare function quaternionFromEnuToTMerc(proj: TMercProjection): QuaternionFunction;
|
|
88
|
+
export declare function quaternionFromEnuToTMerc(proj: TMercProjection, coords: Coordinates, target?: Quaternion): Quaternion;
|
|
89
|
+
export declare function quaternionFromLongLatToEnu(): QuaternionFunction;
|
|
90
|
+
export declare function quaternionFromLongLatToEnu(coords: Coordinates, target?: Quaternion): Quaternion;
|
|
91
|
+
export declare function quaternionFromEnuToLongLat(): QuaternionFunction;
|
|
92
|
+
export declare function quaternionFromEnuToLongLat(coords: Coordinates, target?: Quaternion): Quaternion;
|
|
93
|
+
export declare function quaternionUnimplemented(proj: {
|
|
94
|
+
projName?: string;
|
|
95
|
+
}): QuaternionFunction;
|
|
96
|
+
export declare function quaternionUnimplemented(proj: {
|
|
97
|
+
projName?: string;
|
|
98
|
+
}, coords: Coordinates, target?: Quaternion): Quaternion;
|
|
99
|
+
export declare function quaternionFromEnuToCRS(proj: ProjectionLike): QuaternionFunction;
|
|
100
|
+
export declare function quaternionFromEnuToCRS(proj: ProjectionLike, coords: Coordinates, target?: Quaternion): Quaternion;
|
|
101
|
+
export declare function quaternionFromCRSToEnu(proj: ProjectionLike): QuaternionFunction;
|
|
102
|
+
export declare function quaternionFromCRSToEnu(proj: ProjectionLike, coords: Coordinates, target?: Quaternion): Quaternion;
|
|
103
|
+
export declare function quaternionFromCRSToCRS(crsIn: ProjectionLike, crsOut: ProjectionLike): QuaternionFunction;
|
|
104
|
+
export declare function quaternionFromCRSToCRS(crsIn: ProjectionLike, crsOut: ProjectionLike, coords: Coordinates, target?: Quaternion): Quaternion;
|
|
105
|
+
export {};
|