@loaders.gl/tile-converter 3.1.0-beta.2 → 3.1.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/dist/bundle.js +2413 -1590
- package/dist/converter.min.js +20 -20
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +429 -189
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +306 -209
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +8 -4
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +13 -13
- package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js +51 -32
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -1
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/deps-installer/deps-installer.js +61 -17
- package/dist/es5/deps-installer/deps-installer.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js +55 -16
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +33 -9
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js +103 -93
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-converter.d.ts +5 -1
- package/dist/es5/i3s-converter/helpers/geometry-converter.js +547 -336
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-debug.js +27 -31
- package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-pages.js +209 -101
- package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/es5/i3s-converter/i3s-converter.js +1645 -700
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/layers.js +213 -177
- package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/metadata.js +24 -20
- package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/node.js +92 -74
- package/dist/es5/i3s-converter/json-templates/node.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/scene-server.js +34 -28
- package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/shared-resources.js +162 -107
- package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/store.js +4 -2
- package/dist/es5/i3s-converter/json-templates/store.js.map +1 -1
- package/dist/es5/i3s-converter/types.js +2 -0
- package/dist/es5/i3s-converter/types.js.map +1 -0
- package/dist/es5/i3s-server/app.js +6 -6
- package/dist/es5/i3s-server/app.js.map +1 -1
- package/dist/es5/i3s-server/controllers/index-controller.js +60 -20
- package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
- package/dist/es5/i3s-server/routes/index.js +41 -14
- package/dist/es5/i3s-server/routes/index.js.map +1 -1
- package/dist/es5/index.js +4 -4
- package/dist/es5/lib/utils/{compress-utils.d.ts → compress-util.d.ts} +0 -0
- package/dist/es5/lib/utils/compress-util.js +345 -123
- package/dist/es5/lib/utils/compress-util.js.map +1 -1
- package/dist/es5/lib/utils/file-utils.js +98 -20
- package/dist/es5/lib/utils/file-utils.js.map +1 -1
- package/dist/es5/lib/utils/lod-conversion-utils.js +9 -9
- package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
- package/dist/es5/lib/utils/statistic-utills.js +152 -41
- package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
- package/dist/es5/pgm-loader.js +31 -4
- package/dist/es5/pgm-loader.js.map +1 -1
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +7 -6
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +7 -0
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
- package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js +1 -1
- package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
- package/dist/esm/3d-tiles-converter/json-templates/tileset.js +12 -9
- package/dist/esm/3d-tiles-converter/json-templates/tileset.js.map +1 -1
- package/dist/esm/deps-installer/deps-installer.js +2 -6
- package/dist/esm/deps-installer/deps-installer.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/coordinate-converter.js +35 -3
- package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/create-scene-server-path.js +2 -2
- package/dist/esm/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-converter.d.ts +5 -1
- package/dist/esm/i3s-converter/helpers/geometry-converter.js +50 -16
- package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/node-debug.js +2 -4
- package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/node-pages.js +15 -4
- package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/esm/i3s-converter/i3s-converter.js +147 -62
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/layers.js +37 -27
- package/dist/esm/i3s-converter/json-templates/layers.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/metadata.js +2 -2
- package/dist/esm/i3s-converter/json-templates/metadata.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/node.js +16 -12
- package/dist/esm/i3s-converter/json-templates/node.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/scene-server.js +2 -2
- package/dist/esm/i3s-converter/json-templates/scene-server.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/shared-resources.js +19 -14
- package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/store.js.map +1 -1
- package/dist/esm/i3s-converter/types.js +2 -0
- package/dist/esm/i3s-converter/types.js.map +1 -0
- package/dist/esm/lib/utils/{compress-utils.d.ts → compress-util.d.ts} +0 -0
- package/dist/esm/pgm-loader.js +3 -3
- package/dist/esm/pgm-loader.js.map +1 -1
- package/package.json +16 -14
- package/src/3d-tiles-converter/3d-tiles-converter.ts +21 -20
- package/src/3d-tiles-converter/helpers/{b3dm-converter.js → b3dm-converter.ts} +19 -2
- package/src/3d-tiles-converter/helpers/{i3s-obb-to-3d-tiles-obb.js → i3s-obb-to-3d-tiles-obb.ts} +16 -1
- package/src/3d-tiles-converter/helpers/texture-atlas.ts +4 -4
- package/src/3d-tiles-converter/json-templates/{tileset.js → tileset.ts} +9 -9
- package/src/deps-installer/deps-installer.js +2 -2
- package/src/i3s-converter/helpers/coordinate-converter.ts +62 -9
- package/src/i3s-converter/helpers/{create-scene-server-path.js → create-scene-server-path.ts} +2 -2
- package/src/i3s-converter/helpers/{geometry-attributes.js → geometry-attributes.ts} +4 -4
- package/src/i3s-converter/helpers/geometry-converter.d.ts +5 -1
- package/src/i3s-converter/helpers/geometry-converter.js +63 -13
- package/src/i3s-converter/helpers/{node-debug.js → node-debug.ts} +3 -2
- package/src/i3s-converter/helpers/{node-pages.js → node-pages.ts} +41 -26
- package/src/i3s-converter/i3s-converter.ts +204 -133
- package/src/i3s-converter/json-templates/{layers.js → layers.ts} +29 -27
- package/src/i3s-converter/json-templates/{metadata.js → metadata.ts} +2 -2
- package/src/i3s-converter/json-templates/{node.js → node.ts} +12 -12
- package/src/i3s-converter/json-templates/{scene-server.js → scene-server.ts} +2 -2
- package/src/i3s-converter/json-templates/{shared-resources.js → shared-resources.ts} +14 -14
- package/src/i3s-converter/json-templates/{store.js → store.ts} +0 -0
- package/src/i3s-converter/types.ts +14 -0
- package/src/lib/utils/{compress-utils.d.ts → compress-util.d.ts} +0 -0
- package/src/pgm-loader.ts +2 -2
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -23
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -16
- package/dist/es5/i3s-converter/helpers/node-pages.d.ts +0 -144
- package/dist/es5/lib/geoid-height-model.d.ts +0 -41
- package/dist/es5/lib/geoid-height-model.js +0 -149
- package/dist/es5/lib/geoid-height-model.js.map +0 -1
- package/dist/es5/lib/pgm-parser.d.ts +0 -14
- package/dist/es5/lib/pgm-parser.js +0 -192
- package/dist/es5/lib/pgm-parser.js.map +0 -1
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -23
- package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -16
- package/dist/esm/i3s-converter/helpers/node-pages.d.ts +0 -144
- package/dist/esm/lib/geoid-height-model.d.ts +0 -41
- package/dist/esm/lib/geoid-height-model.js +0 -140
- package/dist/esm/lib/geoid-height-model.js.map +0 -1
- package/dist/esm/lib/pgm-parser.d.ts +0 -14
- package/dist/esm/lib/pgm-parser.js +0 -183
- package/dist/esm/lib/pgm-parser.js.map +0 -1
- package/src/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -23
- package/src/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -16
- package/src/i3s-converter/helpers/node-pages.d.ts +0 -144
- package/src/lib/geoid-height-model.d.ts +0 -41
- package/src/lib/geoid-height-model.js +0 -239
- package/src/lib/pgm-parser.d.ts +0 -14
- package/src/lib/pgm-parser.js +0 -179
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Code is ported from GeographicLib-1.50.1
|
|
3
|
-
* https://geographiclib.sourceforge.io/html/index.html
|
|
4
|
-
* Location: /GeographicLib-1.50.1/src/Geoid.cpp
|
|
5
|
-
* /GeographicLib-1.50.1/include/GeographicLib/Geoid.hpp
|
|
6
|
-
* /GeographicLib-1.50.1/src/Math.cpp
|
|
7
|
-
*
|
|
8
|
-
* File header:
|
|
9
|
-
* * \file Geoid.cpp (Geoid.hpp)
|
|
10
|
-
* * \brief Implementation for GeographicLib::Geoid class
|
|
11
|
-
* *
|
|
12
|
-
* * Copyright (c) Charles Karney (2009-2018) <charles@karney.com> and licensed
|
|
13
|
-
* * under the MIT/X11 License. For more information, see
|
|
14
|
-
* * https://geographiclib.sourceforge.io/
|
|
15
|
-
**********************************************************************/
|
|
16
|
-
|
|
17
|
-
const c0_ = 240;
|
|
18
|
-
|
|
19
|
-
// prettier-ignore
|
|
20
|
-
const c3_ = [
|
|
21
|
-
9, -18, -88, 0, 96, 90, 0, 0, -60, -20,
|
|
22
|
-
-9, 18, 8, 0, -96, 30, 0, 0, 60, -20,
|
|
23
|
-
9, -88, -18, 90, 96, 0, -20, -60, 0, 0,
|
|
24
|
-
186, -42, -42, -150, -96, -150, 60, 60, 60, 60,
|
|
25
|
-
54, 162, -78, 30, -24, -90, -60, 60, -60, 60,
|
|
26
|
-
-9, -32, 18, 30, 24, 0, 20, -60, 0, 0,
|
|
27
|
-
-9, 8, 18, 30, -96, 0, -20, 60, 0, 0,
|
|
28
|
-
54, -78, 162, -90, -24, 30, 60, -60, 60, -60,
|
|
29
|
-
-54, 78, 78, 90, 144, 90, -60, -60, -60, -60,
|
|
30
|
-
9, -8, -18, -30, -24, 0, 20, 60, 0, 0,
|
|
31
|
-
-9, 18, -32, 0, 24, 30, 0, 0, -60, 20,
|
|
32
|
-
9, -18, -8, 0, -24, -30, 0, 0, 60, 20
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
const c0n_ = 372;
|
|
36
|
-
|
|
37
|
-
// prettier-ignore
|
|
38
|
-
const c3n_ = [
|
|
39
|
-
0, 0, -131, 0, 138, 144, 0, 0, -102, -31,
|
|
40
|
-
0, 0, 7, 0, -138, 42, 0, 0, 102, -31,
|
|
41
|
-
62, 0, -31, 0, 0, -62, 0, 0, 0, 31,
|
|
42
|
-
124, 0, -62, 0, 0, -124, 0, 0, 0, 62,
|
|
43
|
-
124, 0, -62, 0, 0, -124, 0, 0, 0, 62,
|
|
44
|
-
62, 0, -31, 0, 0, -62, 0, 0, 0, 31,
|
|
45
|
-
0, 0, 45, 0, -183, -9, 0, 93, 18, 0,
|
|
46
|
-
0, 0, 216, 0, 33, 87, 0, -93, 12, -93,
|
|
47
|
-
0, 0, 156, 0, 153, 99, 0, -93, -12, -93,
|
|
48
|
-
0, 0, -45, 0, -3, 9, 0, 93, -18, 0,
|
|
49
|
-
0, 0, -55, 0, 48, 42, 0, 0, -84, 31,
|
|
50
|
-
0, 0, -7, 0, -48, -42, 0, 0, 84, 31,
|
|
51
|
-
];
|
|
52
|
-
|
|
53
|
-
const c0s_ = 372;
|
|
54
|
-
|
|
55
|
-
// prettier-ignore
|
|
56
|
-
const c3s_ = [
|
|
57
|
-
18, -36, -122, 0, 120, 135, 0, 0, -84, -31,
|
|
58
|
-
-18, 36, -2, 0, -120, 51, 0, 0, 84, -31,
|
|
59
|
-
36, -165, -27, 93, 147, -9, 0, -93, 18, 0,
|
|
60
|
-
210, 45, -111, -93, -57, -192, 0, 93, 12, 93,
|
|
61
|
-
162, 141, -75, -93, -129, -180, 0, 93, -12, 93,
|
|
62
|
-
-36, -21, 27, 93, 39, 9, 0, -93, -18, 0,
|
|
63
|
-
0, 0, 62, 0, 0, 31, 0, 0, 0, -31,
|
|
64
|
-
0, 0, 124, 0, 0, 62, 0, 0, 0, -62,
|
|
65
|
-
0, 0, 124, 0, 0, 62, 0, 0, 0, -62,
|
|
66
|
-
0, 0, 62, 0, 0, 31, 0, 0, 0, -31,
|
|
67
|
-
-18, 36, -64, 0, 66, 51, 0, 0, -102, 31,
|
|
68
|
-
18, -36, 2, 0, -66, -51, 0, 0, 102, 31,
|
|
69
|
-
];
|
|
70
|
-
const stencilsize_ = 12;
|
|
71
|
-
const nterms_ = ((3 + 1) * (3 + 2)) / 2; // for a cubic fit
|
|
72
|
-
const PIXEL_SIZE = 2;
|
|
73
|
-
|
|
74
|
-
export class GeoidHeightModel {
|
|
75
|
-
constructor(options) {
|
|
76
|
-
this.options = options;
|
|
77
|
-
this._v00 = 0;
|
|
78
|
-
this._v01 = 0;
|
|
79
|
-
this._v10 = 0;
|
|
80
|
-
this._v11 = 0;
|
|
81
|
-
this._t = [];
|
|
82
|
-
|
|
83
|
-
this._ix = this.options._width;
|
|
84
|
-
this._iy = this.options._height;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// eslint-disable-next-line max-statements, complexity
|
|
88
|
-
getHeight(lat, lon) {
|
|
89
|
-
// C++: Math::LatFix(lat)
|
|
90
|
-
lat = Math.abs(lat) > 90 ? NaN : lat;
|
|
91
|
-
|
|
92
|
-
if (isNaN(lat) || isNaN(lon)) {
|
|
93
|
-
return NaN;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// C++: Math::AngNormalize(lon)
|
|
97
|
-
const rem = _remainder(lon, 360);
|
|
98
|
-
lon = rem !== -180 ? rem : 180;
|
|
99
|
-
|
|
100
|
-
let fx = lon * this.options._rlonres;
|
|
101
|
-
let fy = -lat * this.options._rlatres;
|
|
102
|
-
let ix = Math.floor(fx);
|
|
103
|
-
let iy = Math.min(Math.round((this.options._height - 1) / 2 - 1), Math.floor(fy));
|
|
104
|
-
fx -= ix;
|
|
105
|
-
fy -= iy;
|
|
106
|
-
iy += (this.options._height - 1) / 2;
|
|
107
|
-
ix += ix < 0 ? this.options._width : ix >= this.options._width ? -this.options._width : 0;
|
|
108
|
-
let v00 = 0;
|
|
109
|
-
let v01 = 0;
|
|
110
|
-
let v10 = 0;
|
|
111
|
-
let v11 = 0;
|
|
112
|
-
let t = new Array(nterms_);
|
|
113
|
-
if (!(ix === this._ix && iy === this._iy)) {
|
|
114
|
-
if (!this.options.cubic) {
|
|
115
|
-
v00 = this._rawval(ix, iy);
|
|
116
|
-
v01 = this._rawval(ix + 1, iy);
|
|
117
|
-
v10 = this._rawval(ix, iy + 1);
|
|
118
|
-
v11 = this._rawval(ix + 1, iy + 1);
|
|
119
|
-
} else {
|
|
120
|
-
const v = [
|
|
121
|
-
this._rawval(ix, iy - 1),
|
|
122
|
-
this._rawval(ix + 1, iy - 1),
|
|
123
|
-
this._rawval(ix - 1, iy),
|
|
124
|
-
this._rawval(ix, iy),
|
|
125
|
-
this._rawval(ix + 1, iy),
|
|
126
|
-
this._rawval(ix + 2, iy),
|
|
127
|
-
this._rawval(ix - 1, iy + 1),
|
|
128
|
-
this._rawval(ix, iy + 1),
|
|
129
|
-
this._rawval(ix + 1, iy + 1),
|
|
130
|
-
this._rawval(ix + 2, iy + 1),
|
|
131
|
-
this._rawval(ix, iy + 2),
|
|
132
|
-
this._rawval(ix + 1, iy + 2)
|
|
133
|
-
];
|
|
134
|
-
|
|
135
|
-
let c3x = c3n_;
|
|
136
|
-
if (iy !== 0) {
|
|
137
|
-
c3x = iy === this.options._height - 2 ? c3s_ : c3_;
|
|
138
|
-
}
|
|
139
|
-
let c0x = c0n_;
|
|
140
|
-
if (iy !== 0) {
|
|
141
|
-
c0x = iy === this.options._height - 2 ? c0s_ : c0_;
|
|
142
|
-
}
|
|
143
|
-
for (let i = 0; i < nterms_; ++i) {
|
|
144
|
-
t[i] = 0;
|
|
145
|
-
// eslint-disable-next-line max-depth
|
|
146
|
-
for (let j = 0; j < stencilsize_; ++j) {
|
|
147
|
-
t[i] += v[j] * c3x[nterms_ * j + i];
|
|
148
|
-
}
|
|
149
|
-
t[i] /= c0x;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
} else if (!this.options.cubic) {
|
|
153
|
-
// same cell; used cached coefficients
|
|
154
|
-
v00 = this._v00;
|
|
155
|
-
v01 = this._v01;
|
|
156
|
-
v10 = this._v10;
|
|
157
|
-
v11 = this._v11;
|
|
158
|
-
} else {
|
|
159
|
-
t = this._t;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (!this.options.cubic) {
|
|
163
|
-
const a = (1 - fx) * v00 + fx * v01;
|
|
164
|
-
const b = (1 - fx) * v10 + fx * v11;
|
|
165
|
-
const c = (1 - fy) * a + fy * b;
|
|
166
|
-
const h = this.options._offset + this.options._scale * c;
|
|
167
|
-
this._ix = ix;
|
|
168
|
-
this._iy = iy;
|
|
169
|
-
this._v00 = v00;
|
|
170
|
-
this._v01 = v01;
|
|
171
|
-
this._v10 = v10;
|
|
172
|
-
this._v11 = v11;
|
|
173
|
-
return h;
|
|
174
|
-
}
|
|
175
|
-
let h =
|
|
176
|
-
t[0] +
|
|
177
|
-
fx * (t[1] + fx * (t[3] + fx * t[6])) +
|
|
178
|
-
fy * (t[2] + fx * (t[4] + fx * t[7]) + fy * (t[5] + fx * t[8] + fy * t[9]));
|
|
179
|
-
h = this.options._offset + this.options._scale * h;
|
|
180
|
-
this._ix = ix;
|
|
181
|
-
this._iy = iy;
|
|
182
|
-
this._t = t;
|
|
183
|
-
return h;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Method seeks for particular data in th pgm buffer
|
|
188
|
-
* Code is ported from corresponding method
|
|
189
|
-
* in /GeographicLib-1.50.1/include/GeographicLib/Geoid.hpp
|
|
190
|
-
* @param {number} ix - longituge parameter
|
|
191
|
-
* @param {number} iy - latitude parameter
|
|
192
|
-
* @returns {number} data from pgm binary buffer
|
|
193
|
-
*/
|
|
194
|
-
_rawval(ix, iy) {
|
|
195
|
-
if (ix < 0) {
|
|
196
|
-
ix += this.options._width;
|
|
197
|
-
} else if (ix >= this.options._width) {
|
|
198
|
-
ix -= this.options._width;
|
|
199
|
-
}
|
|
200
|
-
if (iy < 0 || iy >= this.options._height) {
|
|
201
|
-
iy = iy < 0 ? -iy : 2 * (this.options._height - 1) - iy;
|
|
202
|
-
ix += ((ix < this.options._width / 2 ? 1 : -1) * this.options._width) / 2;
|
|
203
|
-
}
|
|
204
|
-
const bufferPosition = this.options._datastart + PIXEL_SIZE * (iy * this.options._swidth + ix);
|
|
205
|
-
// initial values to suppress warnings in case get fails
|
|
206
|
-
const a = this.options.data[bufferPosition];
|
|
207
|
-
const b = this.options.data[bufferPosition + 1];
|
|
208
|
-
const r = (a << 8) | b;
|
|
209
|
-
return r;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Method calculates remainder of float numbers division
|
|
215
|
-
* Code is ported from corresponding method
|
|
216
|
-
* in /GeographicLib-1.50.1/src/Math.cpp
|
|
217
|
-
* Math::remainder(T x, T y)
|
|
218
|
-
* @param {number} x - numerator
|
|
219
|
-
* @param {number} y - denominator
|
|
220
|
-
* @returns {number} - remainder
|
|
221
|
-
*/
|
|
222
|
-
function _remainder(x, y) {
|
|
223
|
-
y = Math.abs(y); // The result doesn't depend on the sign of y
|
|
224
|
-
let z = _fmod(x, y);
|
|
225
|
-
if (2 * Math.abs(z) === y) z -= _fmod(x, 2 * y) - z;
|
|
226
|
-
// Implement ties to even
|
|
227
|
-
else if (2 * Math.abs(z) > y) z += z < 0 ? y : -y; // Fold remaining cases to (-y/2, y/2)
|
|
228
|
-
return z;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Computes the floating-point remainder of the division operation x/y
|
|
233
|
-
* @param {number} x - numerator
|
|
234
|
-
* @param {number} y - denominator
|
|
235
|
-
* @returns {number} - remainder
|
|
236
|
-
*/
|
|
237
|
-
function _fmod(x, y) {
|
|
238
|
-
return x - Math.floor(x / y) * y;
|
|
239
|
-
}
|
package/src/lib/pgm-parser.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parse header of "Earth Gravity Model" *.pgm file
|
|
3
|
-
* The implementation is ported from GeographicLib-1.50.1
|
|
4
|
-
* https://geographiclib.sourceforge.io/html/index.html
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Parse "Earth Gravity Model" loaded from a *.pgm file
|
|
9
|
-
* https://geographiclib.sourceforge.io/html/geoid.html
|
|
10
|
-
* @param {Uint8Array} data - binary buffer of pgm file
|
|
11
|
-
* @param {Object} options - loader options
|
|
12
|
-
* @returns {GeoidHeightModel} - instance of GeoidHeightModel class
|
|
13
|
-
*/
|
|
14
|
-
export function parsePgm(data, options);
|
package/src/lib/pgm-parser.js
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parsing code is ported from GeographicLib-1.50.1
|
|
3
|
-
* https://geographiclib.sourceforge.io/html/index.html
|
|
4
|
-
* Location: /GeographicLib-1.50.1/src/Geoid.cpp
|
|
5
|
-
*
|
|
6
|
-
* File header:
|
|
7
|
-
* * \file Geoid.cpp
|
|
8
|
-
* * \brief Implementation for GeographicLib::Geoid class
|
|
9
|
-
* *
|
|
10
|
-
* * Copyright (c) Charles Karney (2009-2018) <charles@karney.com> and licensed
|
|
11
|
-
* * under the MIT/X11 License. For more information, see
|
|
12
|
-
* * https://geographiclib.sourceforge.io/
|
|
13
|
-
**********************************************************************/
|
|
14
|
-
|
|
15
|
-
import {GeoidHeightModel} from './geoid-height-model';
|
|
16
|
-
|
|
17
|
-
const ENDL = 10;
|
|
18
|
-
const PIXEL_MAX = 65535;
|
|
19
|
-
|
|
20
|
-
// eslint-disable-next-line
|
|
21
|
-
export function parsePgm(data, options) {
|
|
22
|
-
const getline = _getLineGenerator(data);
|
|
23
|
-
let currentLine = getline.next();
|
|
24
|
-
if (currentLine.done || currentLine.value.line !== 'P5') {
|
|
25
|
-
throw new Error('Geoid model file: File not in PGM format');
|
|
26
|
-
}
|
|
27
|
-
let _offset = Number.MAX_VALUE;
|
|
28
|
-
let _scale = 0;
|
|
29
|
-
let _maxerror = -1;
|
|
30
|
-
let _rmserror = -1;
|
|
31
|
-
let _description = 'NONE';
|
|
32
|
-
let _datetime = 'UNKNOWN';
|
|
33
|
-
let _width = 0;
|
|
34
|
-
let _height = 0;
|
|
35
|
-
let _datastart = null;
|
|
36
|
-
let _swidth = null;
|
|
37
|
-
do {
|
|
38
|
-
currentLine = getline.next();
|
|
39
|
-
const s = currentLine.value.line;
|
|
40
|
-
if (!s.length) {
|
|
41
|
-
continue; // eslint-disable-line no-continue
|
|
42
|
-
}
|
|
43
|
-
if (s[0] === '#') {
|
|
44
|
-
const sArr = s.split(' ');
|
|
45
|
-
const commentId = sArr[0];
|
|
46
|
-
const key = sArr[1];
|
|
47
|
-
if (commentId !== '#' || !key) {
|
|
48
|
-
continue; // eslint-disable-line no-continue
|
|
49
|
-
}
|
|
50
|
-
const infoArr = sArr.length > 2 ? sArr.slice(2) : [];
|
|
51
|
-
if (key === 'Description') {
|
|
52
|
-
_description = infoArr.join(' ');
|
|
53
|
-
} else if (key === 'DateTime') {
|
|
54
|
-
_datetime = infoArr.join(' ');
|
|
55
|
-
} else if (key === 'Offset') {
|
|
56
|
-
// eslint-disable-next-line max-depth
|
|
57
|
-
if (!sArr[2]) {
|
|
58
|
-
throw new Error('Geoid model file: Error reading offset');
|
|
59
|
-
}
|
|
60
|
-
_offset = parseInt(sArr[2], 10);
|
|
61
|
-
} else if (key === 'Scale') {
|
|
62
|
-
// eslint-disable-next-line max-depth
|
|
63
|
-
if (!sArr[2]) {
|
|
64
|
-
throw new Error('Geoid model file: Error reading scale');
|
|
65
|
-
}
|
|
66
|
-
_scale = parseFloat(sArr[2]);
|
|
67
|
-
} else if (key === (options.cubic ? 'MaxCubicError' : 'MaxBilinearError')) {
|
|
68
|
-
// It's not an error if the error can't be read
|
|
69
|
-
// eslint-disable-next-line max-depth
|
|
70
|
-
if (isFinite(parseFloat(sArr[2]))) {
|
|
71
|
-
_maxerror = parseFloat(sArr[2]);
|
|
72
|
-
}
|
|
73
|
-
} else if (key === (options.cubic ? 'RMSCubicError' : 'RMSBilinearError')) {
|
|
74
|
-
// It's not an error if the error can't be read
|
|
75
|
-
// eslint-disable-next-line max-depth
|
|
76
|
-
if (isFinite(parseFloat(sArr[2]))) {
|
|
77
|
-
_rmserror = parseFloat(sArr[2]);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
} else {
|
|
81
|
-
let sArr = s.split(' ');
|
|
82
|
-
sArr = sArr.filter((testString) => testString !== '');
|
|
83
|
-
_width = parseInt(sArr[0], 10);
|
|
84
|
-
_height = parseInt(sArr[1], 10);
|
|
85
|
-
if (!(_width && _height)) {
|
|
86
|
-
throw new Error('Geoid model file: Error reading raster size');
|
|
87
|
-
}
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
} while (!currentLine.done);
|
|
91
|
-
|
|
92
|
-
currentLine = getline.next();
|
|
93
|
-
const maxval = parseInt(currentLine.value.line, 10);
|
|
94
|
-
if (currentLine.done) {
|
|
95
|
-
throw new Error('Geoid model file: Error reading maxval');
|
|
96
|
-
}
|
|
97
|
-
if (maxval !== PIXEL_MAX) {
|
|
98
|
-
throw new Error('Geoid model file: Incorrect value of maxval');
|
|
99
|
-
}
|
|
100
|
-
// Add 1 for whitespace after maxval
|
|
101
|
-
_datastart = currentLine.value.offset;
|
|
102
|
-
_swidth = _width;
|
|
103
|
-
|
|
104
|
-
if (_offset === Number.MAX_VALUE) {
|
|
105
|
-
throw new Error('Geoid model file: Offset not set');
|
|
106
|
-
}
|
|
107
|
-
if (_scale === 0) {
|
|
108
|
-
throw new Error('Geoid model file: Scale not set');
|
|
109
|
-
}
|
|
110
|
-
if (_scale < 0) {
|
|
111
|
-
throw new Error('Geoid model file: Scale must be positive');
|
|
112
|
-
}
|
|
113
|
-
if (_height < 2 || _width < 2) {
|
|
114
|
-
// Coarsest grid spacing is 180deg.
|
|
115
|
-
throw new Error('Geoid model file: Raster size too small');
|
|
116
|
-
}
|
|
117
|
-
if (_width & 1) {
|
|
118
|
-
// This is so that longitude grids can be extended thru the poles.
|
|
119
|
-
throw new Error('Geoid model file: Raster width is odd');
|
|
120
|
-
}
|
|
121
|
-
if (!(_height & 1)) {
|
|
122
|
-
// This is so that latitude grid includes the equator.
|
|
123
|
-
throw new Error('Geoid model file: Raster height is even');
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const _rlonres = _width / 360;
|
|
127
|
-
const _rlatres = (_height - 1) / 180;
|
|
128
|
-
return new GeoidHeightModel({
|
|
129
|
-
cubic: options.cubic,
|
|
130
|
-
_width,
|
|
131
|
-
_height,
|
|
132
|
-
_rlonres,
|
|
133
|
-
_rlatres,
|
|
134
|
-
_offset,
|
|
135
|
-
_scale,
|
|
136
|
-
_swidth,
|
|
137
|
-
_datastart,
|
|
138
|
-
_maxerror,
|
|
139
|
-
_rmserror,
|
|
140
|
-
_description,
|
|
141
|
-
_datetime,
|
|
142
|
-
data
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Yields strings from pgm file (splitted by 10 - new line symbol)
|
|
148
|
-
* @param {Uint8Array} data - binary buffer of pgm file
|
|
149
|
-
* @returns {Generator}
|
|
150
|
-
*/
|
|
151
|
-
function* _getLineGenerator(data) {
|
|
152
|
-
let offset = 0;
|
|
153
|
-
do {
|
|
154
|
-
const endLineIndex = data.indexOf(ENDL, offset);
|
|
155
|
-
if (endLineIndex !== -1) {
|
|
156
|
-
const line = data.subarray(offset, endLineIndex);
|
|
157
|
-
offset = endLineIndex + 1;
|
|
158
|
-
yield {offset, line: _getStringFromCharArray(line)};
|
|
159
|
-
} else {
|
|
160
|
-
const line = data.subarray(offset, data.length);
|
|
161
|
-
offset = data.length;
|
|
162
|
-
yield {offset, line: _getStringFromCharArray(line)};
|
|
163
|
-
}
|
|
164
|
-
} while (offset < data.length);
|
|
165
|
-
return {offset, line: ''};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Converts Uint8Array of char-codes to string
|
|
170
|
-
* @param {Uint8Array} array - binary buffer of pgm file
|
|
171
|
-
* @returns {string}
|
|
172
|
-
*/
|
|
173
|
-
function _getStringFromCharArray(array) {
|
|
174
|
-
let s = '';
|
|
175
|
-
for (const char of array) {
|
|
176
|
-
s += String.fromCharCode(char);
|
|
177
|
-
}
|
|
178
|
-
return s;
|
|
179
|
-
}
|