@math.gl/earth 0.0.0-stage → 5.0.0-alpha.19

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 (269) hide show
  1. package/README.md +14 -2
  2. package/dist/geoid/create-geoid-from-grid.d.ts +15 -0
  3. package/dist/geoid/create-geoid-from-grid.d.ts.map +1 -0
  4. package/dist/geoid/create-geoid-from-grid.js +38 -0
  5. package/dist/geoid/create-geoid-from-grid.js.map +1 -0
  6. package/dist/geoid/geoid.d.ts +60 -0
  7. package/dist/geoid/geoid.d.ts.map +1 -0
  8. package/dist/geoid/geoid.js +261 -0
  9. package/dist/geoid/geoid.js.map +1 -0
  10. package/dist/geoid/index.cjs +727 -0
  11. package/dist/geoid/index.cjs.map +6 -0
  12. package/dist/geoid/index.d.ts +5 -0
  13. package/dist/geoid/index.d.ts.map +1 -0
  14. package/dist/geoid/index.js +7 -0
  15. package/dist/geoid/index.js.map +1 -0
  16. package/dist/geoid/parse-pgm.d.ts +12 -0
  17. package/dist/geoid/parse-pgm.d.ts.map +1 -0
  18. package/dist/geoid/parse-pgm.js +183 -0
  19. package/dist/geoid/parse-pgm.js.map +1 -0
  20. package/dist/index.cjs +2646 -0
  21. package/dist/index.cjs.map +6 -0
  22. package/dist/index.d.ts +4 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +7 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/sun/astronomy.cjs +1729 -0
  27. package/dist/sun/astronomy.cjs.map +6 -0
  28. package/dist/sun/astronomy.d.ts +359 -0
  29. package/dist/sun/astronomy.d.ts.map +1 -0
  30. package/dist/sun/astronomy.js +181 -0
  31. package/dist/sun/astronomy.js.map +1 -0
  32. package/dist/sun/celestial.d.ts +4 -0
  33. package/dist/sun/celestial.d.ts.map +1 -0
  34. package/dist/sun/celestial.js +18 -0
  35. package/dist/sun/celestial.js.map +1 -0
  36. package/dist/sun/cloud-lighting.d.ts +49 -0
  37. package/dist/sun/cloud-lighting.d.ts.map +1 -0
  38. package/dist/sun/cloud-lighting.js +121 -0
  39. package/dist/sun/cloud-lighting.js.map +1 -0
  40. package/dist/sun/cloud-spectral.d.ts +3 -0
  41. package/dist/sun/cloud-spectral.d.ts.map +1 -0
  42. package/dist/sun/cloud-spectral.js +45 -0
  43. package/dist/sun/cloud-spectral.js.map +1 -0
  44. package/dist/sun/data/bright-stars.d.ts +3 -0
  45. package/dist/sun/data/bright-stars.d.ts.map +1 -0
  46. package/dist/sun/data/bright-stars.js +7015 -0
  47. package/dist/sun/data/bright-stars.js.map +1 -0
  48. package/dist/sun/data/sunlight.d.ts +2 -0
  49. package/dist/sun/data/sunlight.d.ts.map +1 -0
  50. package/dist/sun/data/sunlight.js +970 -0
  51. package/dist/sun/data/sunlight.js.map +1 -0
  52. package/dist/sun/index.cjs +1744 -0
  53. package/dist/sun/index.cjs.map +6 -0
  54. package/dist/sun/index.d.ts +23 -0
  55. package/dist/sun/index.d.ts.map +1 -0
  56. package/dist/sun/index.js +17 -0
  57. package/dist/sun/index.js.map +1 -0
  58. package/dist/sun/moon-appearance.d.ts +25 -0
  59. package/dist/sun/moon-appearance.d.ts.map +1 -0
  60. package/dist/sun/moon-appearance.js +50 -0
  61. package/dist/sun/moon-appearance.js.map +1 -0
  62. package/dist/sun/moon-sky-brightness.d.ts +7 -0
  63. package/dist/sun/moon-sky-brightness.d.ts.map +1 -0
  64. package/dist/sun/moon-sky-brightness.js +50 -0
  65. package/dist/sun/moon-sky-brightness.js.map +1 -0
  66. package/dist/sun/moon.d.ts +26 -0
  67. package/dist/sun/moon.d.ts.map +1 -0
  68. package/dist/sun/moon.js +74 -0
  69. package/dist/sun/moon.js.map +1 -0
  70. package/dist/sun/moonlight.d.ts +23 -0
  71. package/dist/sun/moonlight.d.ts.map +1 -0
  72. package/dist/sun/moonlight.js +48 -0
  73. package/dist/sun/moonlight.js.map +1 -0
  74. package/dist/sun/planet-position.d.ts +63 -0
  75. package/dist/sun/planet-position.d.ts.map +1 -0
  76. package/dist/sun/planet-position.js +189 -0
  77. package/dist/sun/planet-position.js.map +1 -0
  78. package/dist/sun/planet-times.d.ts +41 -0
  79. package/dist/sun/planet-times.d.ts.map +1 -0
  80. package/dist/sun/planet-times.js +86 -0
  81. package/dist/sun/planet-times.js.map +1 -0
  82. package/dist/sun/planet-visibility.d.ts +39 -0
  83. package/dist/sun/planet-visibility.d.ts.map +1 -0
  84. package/dist/sun/planet-visibility.js +82 -0
  85. package/dist/sun/planet-visibility.js.map +1 -0
  86. package/dist/sun/planets.cjs +411 -0
  87. package/dist/sun/planets.cjs.map +6 -0
  88. package/dist/sun/planets.d.ts +7 -0
  89. package/dist/sun/planets.d.ts.map +1 -0
  90. package/dist/sun/planets.js +7 -0
  91. package/dist/sun/planets.js.map +1 -0
  92. package/dist/sun/sky-brightness.d.ts +32 -0
  93. package/dist/sun/sky-brightness.d.ts.map +1 -0
  94. package/dist/sun/sky-brightness.js +108 -0
  95. package/dist/sun/sky-brightness.js.map +1 -0
  96. package/dist/sun/sky-events.d.ts +16 -0
  97. package/dist/sun/sky-events.d.ts.map +1 -0
  98. package/dist/sun/sky-events.js +60 -0
  99. package/dist/sun/sky-events.js.map +1 -0
  100. package/dist/sun/sky-globe.d.ts +15 -0
  101. package/dist/sun/sky-globe.d.ts.map +1 -0
  102. package/dist/sun/sky-globe.js +51 -0
  103. package/dist/sun/sky-globe.js.map +1 -0
  104. package/dist/sun/sky-lighting.d.ts +27 -0
  105. package/dist/sun/sky-lighting.d.ts.map +1 -0
  106. package/dist/sun/sky-lighting.js +88 -0
  107. package/dist/sun/sky-lighting.js.map +1 -0
  108. package/dist/sun/sky-observer.d.ts +22 -0
  109. package/dist/sun/sky-observer.d.ts.map +1 -0
  110. package/dist/sun/sky-observer.js +57 -0
  111. package/dist/sun/sky-observer.js.map +1 -0
  112. package/dist/sun/sky-time.d.ts +9 -0
  113. package/dist/sun/sky-time.d.ts.map +1 -0
  114. package/dist/sun/sky-time.js +38 -0
  115. package/dist/sun/sky-time.js.map +1 -0
  116. package/dist/sun/star-galactic.d.ts +15 -0
  117. package/dist/sun/star-galactic.d.ts.map +1 -0
  118. package/dist/sun/star-galactic.js +98 -0
  119. package/dist/sun/star-galactic.js.map +1 -0
  120. package/dist/sun/star-milky-way.d.ts +14 -0
  121. package/dist/sun/star-milky-way.d.ts.map +1 -0
  122. package/dist/sun/star-milky-way.js +32 -0
  123. package/dist/sun/star-milky-way.js.map +1 -0
  124. package/dist/sun/star-render.d.ts +38 -0
  125. package/dist/sun/star-render.d.ts.map +1 -0
  126. package/dist/sun/star-render.js +98 -0
  127. package/dist/sun/star-render.js.map +1 -0
  128. package/dist/sun/star-types.d.ts +60 -0
  129. package/dist/sun/star-types.d.ts.map +1 -0
  130. package/dist/sun/star-types.js +5 -0
  131. package/dist/sun/star-types.js.map +1 -0
  132. package/dist/sun/starfield.d.ts +13 -0
  133. package/dist/sun/starfield.d.ts.map +1 -0
  134. package/dist/sun/starfield.js +86 -0
  135. package/dist/sun/starfield.js.map +1 -0
  136. package/dist/sun/stars.cjs +7519 -0
  137. package/dist/sun/stars.cjs.map +6 -0
  138. package/dist/sun/stars.d.ts +26 -0
  139. package/dist/sun/stars.d.ts.map +1 -0
  140. package/dist/sun/stars.js +188 -0
  141. package/dist/sun/stars.js.map +1 -0
  142. package/dist/sun/suncalc.d.ts +26 -0
  143. package/dist/sun/suncalc.d.ts.map +1 -0
  144. package/dist/sun/suncalc.js +94 -0
  145. package/dist/sun/suncalc.js.map +1 -0
  146. package/dist/sun/sunlight.d.ts +25 -0
  147. package/dist/sun/sunlight.d.ts.map +1 -0
  148. package/dist/sun/sunlight.js +76 -0
  149. package/dist/sun/sunlight.js.map +1 -0
  150. package/dist/timezone/index.cjs +205 -0
  151. package/dist/timezone/index.cjs.map +6 -0
  152. package/dist/timezone/index.d.ts +6 -0
  153. package/dist/timezone/index.d.ts.map +1 -0
  154. package/dist/timezone/index.js +8 -0
  155. package/dist/timezone/index.js.map +1 -0
  156. package/dist/timezone/instant.d.ts +4 -0
  157. package/dist/timezone/instant.d.ts.map +1 -0
  158. package/dist/timezone/instant.js +20 -0
  159. package/dist/timezone/instant.js.map +1 -0
  160. package/dist/timezone/local-date-time.d.ts +4 -0
  161. package/dist/timezone/local-date-time.d.ts.map +1 -0
  162. package/dist/timezone/local-date-time.js +34 -0
  163. package/dist/timezone/local-date-time.js.map +1 -0
  164. package/dist/timezone/lookup-async.d.ts +3 -0
  165. package/dist/timezone/lookup-async.d.ts.map +1 -0
  166. package/dist/timezone/lookup-async.js +14 -0
  167. package/dist/timezone/lookup-async.js.map +1 -0
  168. package/dist/timezone/lookup.cjs +83 -0
  169. package/dist/timezone/lookup.cjs.map +6 -0
  170. package/dist/timezone/lookup.d.ts +3 -0
  171. package/dist/timezone/lookup.d.ts.map +1 -0
  172. package/dist/timezone/lookup.js +18 -0
  173. package/dist/timezone/lookup.js.map +1 -0
  174. package/dist/timezone/temporal.cjs +5696 -0
  175. package/dist/timezone/temporal.cjs.map +6 -0
  176. package/dist/timezone/temporal.d.ts +9 -0
  177. package/dist/timezone/temporal.d.ts.map +1 -0
  178. package/dist/timezone/temporal.js +60 -0
  179. package/dist/timezone/temporal.js.map +1 -0
  180. package/dist/timezone/timezone-label.d.ts +5 -0
  181. package/dist/timezone/timezone-label.d.ts.map +1 -0
  182. package/dist/timezone/timezone-label.js +27 -0
  183. package/dist/timezone/timezone-label.js.map +1 -0
  184. package/dist/timezone/timezone-offset.d.ts +3 -0
  185. package/dist/timezone/timezone-offset.d.ts.map +1 -0
  186. package/dist/timezone/timezone-offset.js +22 -0
  187. package/dist/timezone/timezone-offset.js.map +1 -0
  188. package/dist/timezone/types.d.ts +23 -0
  189. package/dist/timezone/types.d.ts.map +1 -0
  190. package/dist/timezone/types.js +5 -0
  191. package/dist/timezone/types.js.map +1 -0
  192. package/dist/timezone/vendor/temporal/runtime.d.ts +3 -0
  193. package/dist/timezone/vendor/temporal/runtime.d.ts.map +1 -0
  194. package/dist/timezone/vendor/temporal/runtime.js +5649 -0
  195. package/dist/timezone/vendor/temporal/runtime.js.map +1 -0
  196. package/dist/timezone/vendor/temporal/types.d.ts +939 -0
  197. package/dist/timezone/vendor/temporal/types.d.ts.map +1 -0
  198. package/dist/timezone/vendor/temporal/types.js +4 -0
  199. package/dist/timezone/vendor/temporal/types.js.map +1 -0
  200. package/dist/timezone/vendor/tz-lookup/runtime.d.ts +3 -0
  201. package/dist/timezone/vendor/tz-lookup/runtime.d.ts.map +1 -0
  202. package/dist/timezone/vendor/tz-lookup/runtime.js +53 -0
  203. package/dist/timezone/vendor/tz-lookup/runtime.js.map +1 -0
  204. package/geoid/data/README.md +28 -0
  205. package/geoid/data/geoid-egm96-hi.pgm +0 -0
  206. package/geoid/data/geoid-egm96-low.pgm +0 -0
  207. package/geoid/data/geoid-manifest.json +22 -0
  208. package/package.json +91 -4
  209. package/src/geoid/create-geoid-from-grid.ts +51 -0
  210. package/src/geoid/geoid.ts +297 -0
  211. package/src/geoid/index.ts +8 -0
  212. package/src/geoid/parse-pgm.ts +189 -0
  213. package/src/index.ts +7 -0
  214. package/src/sun/astronomy.ts +272 -0
  215. package/src/sun/celestial.ts +22 -0
  216. package/src/sun/cloud-lighting.ts +198 -0
  217. package/src/sun/cloud-spectral.ts +54 -0
  218. package/src/sun/data/bright-stars.ts +7024 -0
  219. package/src/sun/data/sunlight.ts +969 -0
  220. package/src/sun/index.ts +43 -0
  221. package/src/sun/moon-appearance.ts +81 -0
  222. package/src/sun/moon-sky-brightness.ts +64 -0
  223. package/src/sun/moon.ts +122 -0
  224. package/src/sun/moonlight.ts +88 -0
  225. package/src/sun/planet-position.ts +305 -0
  226. package/src/sun/planet-times.ts +142 -0
  227. package/src/sun/planet-visibility.ts +143 -0
  228. package/src/sun/planets.ts +18 -0
  229. package/src/sun/sky-brightness.ts +148 -0
  230. package/src/sun/sky-events.ts +66 -0
  231. package/src/sun/sky-globe.ts +72 -0
  232. package/src/sun/sky-lighting.ts +118 -0
  233. package/src/sun/sky-observer.ts +66 -0
  234. package/src/sun/sky-time.ts +42 -0
  235. package/src/sun/star-galactic.ts +111 -0
  236. package/src/sun/star-milky-way.ts +61 -0
  237. package/src/sun/star-render.ts +149 -0
  238. package/src/sun/star-types.ts +66 -0
  239. package/src/sun/starfield.ts +100 -0
  240. package/src/sun/stars.ts +260 -0
  241. package/src/sun/suncalc.ts +141 -0
  242. package/src/sun/sunlight.ts +112 -0
  243. package/src/timezone/index.ts +9 -0
  244. package/src/timezone/instant.ts +21 -0
  245. package/src/timezone/local-date-time.ts +40 -0
  246. package/src/timezone/lookup-async.ts +15 -0
  247. package/src/timezone/lookup.ts +21 -0
  248. package/src/timezone/temporal.ts +81 -0
  249. package/src/timezone/timezone-label.ts +30 -0
  250. package/src/timezone/timezone-offset.ts +21 -0
  251. package/src/timezone/types.ts +30 -0
  252. package/src/timezone/vendor/temporal/JSBI-LICENSE.txt +179 -0
  253. package/src/timezone/vendor/temporal/LICENSE.txt +16 -0
  254. package/src/timezone/vendor/temporal/README.md +23 -0
  255. package/src/timezone/vendor/temporal/runtime.ts +5070 -0
  256. package/src/timezone/vendor/temporal/types.ts +1146 -0
  257. package/src/timezone/vendor/tz-lookup/LICENSE.txt +119 -0
  258. package/src/timezone/vendor/tz-lookup/README.md +22 -0
  259. package/src/timezone/vendor/tz-lookup/runtime.ts +53 -0
  260. package/sun/LICENSE-BRIGHT-STARS +21 -0
  261. package/sun/LICENSE-HOSEK-WILKIE +30 -0
  262. package/sun/LICENSE-SUNCALC +24 -0
  263. package/timezone/data/LICENSE-ODbL.txt +538 -0
  264. package/timezone/data/README.md +50 -0
  265. package/timezone/data/manifest.json +37 -0
  266. package/timezone/data/timezone-geometry-hi.json +1 -0
  267. package/timezone/data/timezone-geometry-hi.parquet +0 -0
  268. package/timezone/data/timezone-geometry-low.json +1 -0
  269. package/timezone/data/timezone-geometry-low.parquet +0 -0
@@ -0,0 +1,297 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) Charles Karney (2009-2018) <charles@karney.com>
4
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
5
+ // SPDX-FileComment: Ported from GeographicLib-1.50.1 under MIT/X11. Original source attribution retained below.
6
+
7
+ /**
8
+ * Code is ported from GeographicLib-1.50.1
9
+ * https://geographiclib.sourceforge.io/html/index.html
10
+ * Location: /GeographicLib-1.50.1/src/Geoid.cpp
11
+ * /GeographicLib-1.50.1/include/GeographicLib/Geoid.hpp
12
+ * /GeographicLib-1.50.1/src/Math.cpp
13
+ *
14
+ * File header:
15
+ * * \file Geoid.cpp (Geoid.hpp)
16
+ * * \brief Implementation for GeographicLib::Geoid class
17
+ * *
18
+ * * Copyright (c) Charles Karney (2009-2018) <charles@karney.com> and licensed
19
+ * * under the MIT/X11 License. For more information, see
20
+ * * https://geographiclib.sourceforge.io/
21
+ **********************************************************************/
22
+
23
+ import {isUint16Array} from '@math.gl/core/types';
24
+
25
+ const c0_ = 240;
26
+
27
+ // biome-ignore format: preserve the coefficient table layout
28
+ const c3_ = [
29
+ 9, -18, -88, 0, 96, 90, 0, 0, -60, -20,
30
+ -9, 18, 8, 0, -96, 30, 0, 0, 60, -20,
31
+ 9, -88, -18, 90, 96, 0, -20, -60, 0, 0,
32
+ 186, -42, -42, -150, -96, -150, 60, 60, 60, 60,
33
+ 54, 162, -78, 30, -24, -90, -60, 60, -60, 60,
34
+ -9, -32, 18, 30, 24, 0, 20, -60, 0, 0,
35
+ -9, 8, 18, 30, -96, 0, -20, 60, 0, 0,
36
+ 54, -78, 162, -90, -24, 30, 60, -60, 60, -60,
37
+ -54, 78, 78, 90, 144, 90, -60, -60, -60, -60,
38
+ 9, -8, -18, -30, -24, 0, 20, 60, 0, 0,
39
+ -9, 18, -32, 0, 24, 30, 0, 0, -60, 20,
40
+ 9, -18, -8, 0, -24, -30, 0, 0, 60, 20
41
+ ];
42
+
43
+ const c0n_ = 372;
44
+
45
+ // biome-ignore format: preserve the coefficient table layout
46
+ const c3n_ = [
47
+ 0, 0, -131, 0, 138, 144, 0, 0, -102, -31,
48
+ 0, 0, 7, 0, -138, 42, 0, 0, 102, -31,
49
+ 62, 0, -31, 0, 0, -62, 0, 0, 0, 31,
50
+ 124, 0, -62, 0, 0, -124, 0, 0, 0, 62,
51
+ 124, 0, -62, 0, 0, -124, 0, 0, 0, 62,
52
+ 62, 0, -31, 0, 0, -62, 0, 0, 0, 31,
53
+ 0, 0, 45, 0, -183, -9, 0, 93, 18, 0,
54
+ 0, 0, 216, 0, 33, 87, 0, -93, 12, -93,
55
+ 0, 0, 156, 0, 153, 99, 0, -93, -12, -93,
56
+ 0, 0, -45, 0, -3, 9, 0, 93, -18, 0,
57
+ 0, 0, -55, 0, 48, 42, 0, 0, -84, 31,
58
+ 0, 0, -7, 0, -48, -42, 0, 0, 84, 31,
59
+ ];
60
+
61
+ const c0s_ = 372;
62
+
63
+ // biome-ignore format: preserve the coefficient table layout
64
+ const c3s_ = [
65
+ 18, -36, -122, 0, 120, 135, 0, 0, -84, -31,
66
+ -18, 36, -2, 0, -120, 51, 0, 0, 84, -31,
67
+ 36, -165, -27, 93, 147, -9, 0, -93, 18, 0,
68
+ 210, 45, -111, -93, -57, -192, 0, 93, 12, 93,
69
+ 162, 141, -75, -93, -129, -180, 0, 93, -12, 93,
70
+ -36, -21, 27, 93, 39, 9, 0, -93, -18, 0,
71
+ 0, 0, 62, 0, 0, 31, 0, 0, 0, -31,
72
+ 0, 0, 124, 0, 0, 62, 0, 0, 0, -62,
73
+ 0, 0, 124, 0, 0, 62, 0, 0, 0, -62,
74
+ 0, 0, 62, 0, 0, 31, 0, 0, 0, -31,
75
+ -18, 36, -64, 0, 66, 51, 0, 0, -102, 31,
76
+ 18, -36, 2, 0, -66, -51, 0, 0, 102, 31,
77
+ ];
78
+ const stencilsize_ = 12;
79
+ const nterms_ = ((3 + 1) * (3 + 2)) / 2; // for a cubic fit
80
+ const PIXEL_SIZE = 2;
81
+
82
+ export type GeoidProps = {
83
+ cubic: boolean;
84
+ _width: number;
85
+ _height: number;
86
+ _rlonres: number;
87
+ _rlatres: number;
88
+ _offset: number;
89
+ _scale: number;
90
+ _swidth: number;
91
+ _datastart: number;
92
+ _maxerror: number;
93
+ _rmserror: number;
94
+ _description: string;
95
+ _datetime: string;
96
+ data: Uint8Array | Uint16Array;
97
+ };
98
+
99
+ /**
100
+ * class Geoid - "Gravity Height Model"
101
+ * Calculates difference between mean see level height and WGS84 ellipsoid height
102
+ * Accepts PGM bytes through parsePGM or decoded samples through createGeoidFromGrid.
103
+ * A particular model file can be loaded on https://geographiclib.sourceforge.io/html/geoid.html
104
+ *
105
+ * The implementation is ported from GeographicLib-1.50.1
106
+ */
107
+ export class Geoid {
108
+ private _v00: number = 0;
109
+ private _v01: number = 0;
110
+ private _v10: number = 0;
111
+ private _v11: number = 0;
112
+ private _t: number[] = [];
113
+ private _ix: number;
114
+ private _iy: number;
115
+ private _hasUint16Data: boolean;
116
+
117
+ options: GeoidProps;
118
+
119
+ /**
120
+ * @constructs
121
+ * Create a Geoid instance.
122
+ * @param options - grid parameters supplied by parsePGM or createGeoidFromGrid
123
+ * @param options.data - PGM bytes or decoded unsigned 16-bit samples
124
+ */
125
+ constructor(options: GeoidProps) {
126
+ this.options = options;
127
+ this._ix = this.options._width;
128
+ this._iy = this.options._height;
129
+ this._hasUint16Data = isUint16Array(options.data);
130
+ }
131
+
132
+ /**
133
+ * Calculates difference between mean see level height and WGS84 ellipsoid height
134
+ * Code is ported from /GeographicLib-1.50.1/src/Geoid.cpp
135
+ * @param lat - latitude
136
+ * @param lon - longitude
137
+ * @returns height in meters
138
+ */
139
+ // eslint-disable-next-line max-statements, complexity
140
+ getHeight(lat: number, lon: number): number {
141
+ // C++: Math::LatFix(lat)
142
+ lat = Math.abs(lat) > 90 ? NaN : lat;
143
+
144
+ if (Number.isNaN(lat) || Number.isNaN(lon)) {
145
+ return NaN;
146
+ }
147
+
148
+ // C++: Math::AngNormalize(lon)
149
+ const rem = remainder(lon, 360);
150
+ lon = rem !== -180 ? rem : 180;
151
+
152
+ let fx = lon * this.options._rlonres;
153
+ let fy = -lat * this.options._rlatres;
154
+ let ix = Math.floor(fx);
155
+ let iy = Math.min(Math.round((this.options._height - 1) / 2 - 1), Math.floor(fy));
156
+ fx -= ix;
157
+ fy -= iy;
158
+ iy += (this.options._height - 1) / 2;
159
+ ix += ix < 0 ? this.options._width : ix >= this.options._width ? -this.options._width : 0;
160
+ let v00 = 0;
161
+ let v01 = 0;
162
+ let v10 = 0;
163
+ let v11 = 0;
164
+ let t: number[] = new Array<number>(nterms_);
165
+ if (!(ix === this._ix && iy === this._iy)) {
166
+ if (!this.options.cubic) {
167
+ v00 = this._rawval(ix, iy);
168
+ v01 = this._rawval(ix + 1, iy);
169
+ v10 = this._rawval(ix, iy + 1);
170
+ v11 = this._rawval(ix + 1, iy + 1);
171
+ } else {
172
+ const v = [
173
+ this._rawval(ix, iy - 1),
174
+ this._rawval(ix + 1, iy - 1),
175
+ this._rawval(ix - 1, iy),
176
+ this._rawval(ix, iy),
177
+ this._rawval(ix + 1, iy),
178
+ this._rawval(ix + 2, iy),
179
+ this._rawval(ix - 1, iy + 1),
180
+ this._rawval(ix, iy + 1),
181
+ this._rawval(ix + 1, iy + 1),
182
+ this._rawval(ix + 2, iy + 1),
183
+ this._rawval(ix, iy + 2),
184
+ this._rawval(ix + 1, iy + 2)
185
+ ];
186
+
187
+ let c3x = c3n_;
188
+ if (iy !== 0) {
189
+ c3x = iy === this.options._height - 2 ? c3s_ : c3_;
190
+ }
191
+ let c0x = c0n_;
192
+ if (iy !== 0) {
193
+ c0x = iy === this.options._height - 2 ? c0s_ : c0_;
194
+ }
195
+ for (let i = 0; i < nterms_; ++i) {
196
+ t[i] = 0;
197
+ // eslint-disable-next-line max-depth
198
+ for (let j = 0; j < stencilsize_; ++j) {
199
+ t[i] += v[j] * c3x[nterms_ * j + i];
200
+ }
201
+ t[i] /= c0x;
202
+ }
203
+ }
204
+ } else if (!this.options.cubic) {
205
+ // same cell; used cached coefficients
206
+ v00 = this._v00;
207
+ v01 = this._v01;
208
+ v10 = this._v10;
209
+ v11 = this._v11;
210
+ } else {
211
+ t = this._t;
212
+ }
213
+
214
+ if (!this.options.cubic) {
215
+ const a = (1 - fx) * v00 + fx * v01;
216
+ const b = (1 - fx) * v10 + fx * v11;
217
+ const c = (1 - fy) * a + fy * b;
218
+ const h = this.options._offset + this.options._scale * c;
219
+ this._ix = ix;
220
+ this._iy = iy;
221
+ this._v00 = v00;
222
+ this._v01 = v01;
223
+ this._v10 = v10;
224
+ this._v11 = v11;
225
+ return h;
226
+ }
227
+ let h =
228
+ t[0] +
229
+ fx * (t[1] + fx * (t[3] + fx * t[6])) +
230
+ fy * (t[2] + fx * (t[4] + fx * t[7]) + fy * (t[5] + fx * t[8] + fy * t[9]));
231
+ h = this.options._offset + this.options._scale * h;
232
+ this._ix = ix;
233
+ this._iy = iy;
234
+ this._t = t;
235
+ return h;
236
+ }
237
+
238
+ // PRIVATE
239
+
240
+ /**
241
+ * Method seeks for particular data in th pgm buffer
242
+ * Code is ported from corresponding method
243
+ * in /GeographicLib-1.50.1/include/GeographicLib/Geoid.hpp
244
+ * @param {number} ix - longituge parameter
245
+ * @param {number} iy - latitude parameter
246
+ * @returns {number} data from pgm binary buffer
247
+ */
248
+ private _rawval(ix: number, iy: number): number {
249
+ if (ix < 0) {
250
+ ix += this.options._width;
251
+ } else if (ix >= this.options._width) {
252
+ ix -= this.options._width;
253
+ }
254
+ if (iy < 0 || iy >= this.options._height) {
255
+ iy = iy < 0 ? -iy : 2 * (this.options._height - 1) - iy;
256
+ ix += ((ix < this.options._width / 2 ? 1 : -1) * this.options._width) / 2;
257
+ }
258
+ const sampleIndex = iy * this.options._swidth + ix;
259
+ if (this._hasUint16Data) {
260
+ return this.options.data[this.options._datastart + sampleIndex];
261
+ }
262
+ const bufferPosition = this.options._datastart + PIXEL_SIZE * sampleIndex;
263
+ // initial values to suppress warnings in case get fails
264
+ const a = this.options.data[bufferPosition];
265
+ const b = this.options.data[bufferPosition + 1];
266
+ const r = (a << 8) | b;
267
+ return r;
268
+ }
269
+ }
270
+
271
+ /**
272
+ * Method calculates remainder of float numbers division
273
+ * Code is ported from corresponding method
274
+ * in /GeographicLib-1.50.1/src/Math.cpp
275
+ * Math::remainder(T x, T y)
276
+ * @param {number} x - numerator
277
+ * @param {number} y - denominator
278
+ * @returns {number} - remainder
279
+ */
280
+ function remainder(x: number, y: number): number {
281
+ y = Math.abs(y); // The result doesn't depend on the sign of y
282
+ let z = fmod(x, y);
283
+ if (2 * Math.abs(z) === y) z -= fmod(x, 2 * y) - z;
284
+ // Implement ties to even
285
+ else if (2 * Math.abs(z) > y) z += z < 0 ? y : -y; // Fold remaining cases to (-y/2, y/2)
286
+ return z;
287
+ }
288
+
289
+ /**
290
+ * Computes the floating-point remainder of the division operation x/y
291
+ * @param {number} x - numerator
292
+ * @param {number} y - denominator
293
+ * @returns {number} - remainder
294
+ */
295
+ function fmod(x: number, y: number): number {
296
+ return x - Math.floor(x / y) * y;
297
+ }
@@ -0,0 +1,8 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ export {parsePGM} from './parse-pgm';
6
+ export {Geoid} from './geoid';
7
+ export {createGeoidFromGrid} from './create-geoid-from-grid';
8
+ export type {GeoidGridProps} from './create-geoid-from-grid';
@@ -0,0 +1,189 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) Charles Karney (2009-2018) <charles@karney.com>
4
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
5
+ // SPDX-FileComment: Ported from GeographicLib-1.50.1 under MIT/X11. Original source attribution retained below.
6
+
7
+ // Parsing code is ported from GeographicLib-1.50.1: /GeographicLib-1.50.1/src/Geoid.cpp
8
+ // https://geographiclib.sourceforge.io/html/index.html
9
+ // Original code attribution:
10
+ // Copyright (c) Charles Karney (2009-2018) <charles@karney.com> and licensed
11
+ // under the MIT/X11 License.
12
+
13
+ import {Geoid} from './geoid';
14
+
15
+ const ENDL = 10;
16
+ const PIXEL_MAX = 65535;
17
+
18
+ /**
19
+ * Parse "Earth Gravity Model" loaded from a *.pgm file
20
+ * https://geographiclib.sourceforge.io/html/geoid.html
21
+ * @param {} data - binary buffer of pgm file
22
+ * @param {Object} options - loader options
23
+ * @returns {GeoidHeightModel} - instance of GeoidHeightModel class
24
+ */
25
+ // eslint-disable-next-line
26
+ export function parsePGM(
27
+ data: Uint8Array,
28
+ options: {
29
+ cubic?: boolean;
30
+ }
31
+ ) {
32
+ const getline = _getLineGenerator(data);
33
+ let currentLine = getline.next();
34
+ if (currentLine.done || currentLine.value.line !== 'P5') {
35
+ throw new Error('Geoid model file: File not in PGM format');
36
+ }
37
+ let _offset = Number.MAX_VALUE;
38
+ let _scale = 0;
39
+ let _maxerror = -1;
40
+ let _rmserror = -1;
41
+ let _description = 'NONE';
42
+ let _datetime = 'UNKNOWN';
43
+ let _width = 0;
44
+ let _height = 0;
45
+ let _datastart: number | null = null;
46
+ let _swidth: number | null = null;
47
+ do {
48
+ currentLine = getline.next();
49
+ const s = currentLine.value.line;
50
+ if (!s.length) {
51
+ continue; // eslint-disable-line no-continue
52
+ }
53
+ if (s[0] === '#') {
54
+ const sArr = s.split(' ');
55
+ const commentId = sArr[0];
56
+ const key = sArr[1];
57
+ if (commentId !== '#' || !key) {
58
+ continue; // eslint-disable-line no-continue
59
+ }
60
+ const infoArr = sArr.length > 2 ? sArr.slice(2) : [];
61
+ if (key === 'Description') {
62
+ _description = infoArr.join(' ');
63
+ } else if (key === 'DateTime') {
64
+ _datetime = infoArr.join(' ');
65
+ } else if (key === 'Offset') {
66
+ // eslint-disable-next-line max-depth
67
+ if (!sArr[2]) {
68
+ throw new Error('Geoid model file: Error reading offset');
69
+ }
70
+ _offset = parseInt(sArr[2], 10);
71
+ } else if (key === 'Scale') {
72
+ // eslint-disable-next-line max-depth
73
+ if (!sArr[2]) {
74
+ throw new Error('Geoid model file: Error reading scale');
75
+ }
76
+ _scale = parseFloat(sArr[2]);
77
+ } else if (key === (options.cubic ? 'MaxCubicError' : 'MaxBilinearError')) {
78
+ // It's not an error if the error can't be read
79
+ // eslint-disable-next-line max-depth
80
+ if (isFinite(parseFloat(sArr[2]))) {
81
+ _maxerror = parseFloat(sArr[2]);
82
+ }
83
+ } else if (key === (options.cubic ? 'RMSCubicError' : 'RMSBilinearError')) {
84
+ // It's not an error if the error can't be read
85
+ // eslint-disable-next-line max-depth
86
+ if (isFinite(parseFloat(sArr[2]))) {
87
+ _rmserror = parseFloat(sArr[2]);
88
+ }
89
+ }
90
+ } else {
91
+ let sArr = s.split(' ');
92
+ sArr = sArr.filter(testString => testString !== '');
93
+ _width = parseInt(sArr[0], 10);
94
+ _height = parseInt(sArr[1], 10);
95
+ if (!(_width && _height)) {
96
+ throw new Error('Geoid model file: Error reading raster size');
97
+ }
98
+ break;
99
+ }
100
+ } while (!currentLine.done);
101
+
102
+ currentLine = getline.next();
103
+ const maxval = parseInt(currentLine.value.line, 10);
104
+ if (currentLine.done) {
105
+ throw new Error('Geoid model file: Error reading maxval');
106
+ }
107
+ if (maxval !== PIXEL_MAX) {
108
+ throw new Error('Geoid model file: Incorrect value of maxval');
109
+ }
110
+ // Add 1 for whitespace after maxval
111
+ _datastart = currentLine.value.offset;
112
+ _swidth = _width;
113
+
114
+ if (_offset === Number.MAX_VALUE) {
115
+ throw new Error('Geoid model file: Offset not set');
116
+ }
117
+ if (_scale === 0) {
118
+ throw new Error('Geoid model file: Scale not set');
119
+ }
120
+ if (_scale < 0) {
121
+ throw new Error('Geoid model file: Scale must be positive');
122
+ }
123
+ if (_height < 2 || _width < 2) {
124
+ // Coarsest grid spacing is 180deg.
125
+ throw new Error('Geoid model file: Raster size too small');
126
+ }
127
+ if (_width & 1) {
128
+ // This is so that longitude grids can be extended thru the poles.
129
+ throw new Error('Geoid model file: Raster width is odd');
130
+ }
131
+ if (!(_height & 1)) {
132
+ // This is so that latitude grid includes the equator.
133
+ throw new Error('Geoid model file: Raster height is even');
134
+ }
135
+
136
+ const _rlonres = _width / 360;
137
+ const _rlatres = (_height - 1) / 180;
138
+ return new Geoid({
139
+ cubic: options.cubic,
140
+ _width,
141
+ _height,
142
+ _rlonres,
143
+ _rlatres,
144
+ _offset,
145
+ _scale,
146
+ _swidth,
147
+ _datastart,
148
+ _maxerror,
149
+ _rmserror,
150
+ _description,
151
+ _datetime,
152
+ data
153
+ });
154
+ }
155
+
156
+ /**
157
+ * Yields strings from pgm file (splitted by 10 - new line symbol)
158
+ * @param {Uint8Array} data - binary buffer of pgm file
159
+ * @returns {Generator}
160
+ */
161
+ function* _getLineGenerator(data: Uint8Array) {
162
+ let offset = 0;
163
+ do {
164
+ const endLineIndex = data.indexOf(ENDL, offset);
165
+ if (endLineIndex !== -1) {
166
+ const line = data.subarray(offset, endLineIndex);
167
+ offset = endLineIndex + 1;
168
+ yield {offset, line: _getStringFromCharArray(line)};
169
+ } else {
170
+ const line = data.subarray(offset, data.length);
171
+ offset = data.length;
172
+ yield {offset, line: _getStringFromCharArray(line)};
173
+ }
174
+ } while (offset < data.length);
175
+ return {offset, line: ''};
176
+ }
177
+
178
+ /**
179
+ * Converts Uint8Array of char-codes to string
180
+ * @param array - binary buffer of pgm file
181
+ * @returns string
182
+ */
183
+ function _getStringFromCharArray(array: Uint8Array): string {
184
+ let s = '';
185
+ for (const char of array) {
186
+ s += String.fromCharCode(char);
187
+ }
188
+ return s;
189
+ }
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ export * as geoid from './geoid/index';
6
+ export * as sun from './sun/index';
7
+ export * as timezone from './timezone/index';