@3clear/basegis 0.1.2 → 0.1.4

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.
@@ -0,0 +1,96 @@
1
+ const u = {
2
+ OK: "OK",
3
+ FAILED: "FAILED",
4
+ NOT_INITIALIZED: "NOT_INITIALIZED",
5
+ INVALID_CONTAINER: "INVALID_CONTAINER",
6
+ ENGINE_NOT_REGISTERED: "ENGINE_NOT_REGISTERED",
7
+ ENGINE_RESOURCE_MISSING: "ENGINE_RESOURCE_MISSING",
8
+ METHOD_NOT_FOUND: "METHOD_NOT_FOUND",
9
+ UNSUPPORTED_CAPABILITY: "UNSUPPORTED_CAPABILITY",
10
+ INVALID_DEM: "INVALID_DEM"
11
+ };
12
+ function _({
13
+ success: i = !0,
14
+ message: t = "",
15
+ data: s = null,
16
+ code: n = u.OK
17
+ } = {}) {
18
+ return { success: i, message: t, data: s, code: n };
19
+ }
20
+ function C(i = null, t = "OK", s = u.OK) {
21
+ return _({ success: !0, message: t, data: i, code: s });
22
+ }
23
+ function g(i = "Operation failed.", t = u.FAILED, s = null) {
24
+ return _({ success: !1, message: i, data: s, code: t });
25
+ }
26
+ function T(i, t, s = "") {
27
+ const n = `${t} adapter does not support "${i}". ${s}`.trim();
28
+ return console.warn(`[3clear-dt-base] ${n}`), g(n, u.UNSUPPORTED_CAPABILITY, {
29
+ methodName: i,
30
+ engineType: t,
31
+ detail: s
32
+ });
33
+ }
34
+ class x {
35
+ constructor(t = {}) {
36
+ this.rawData = t, this.bound = Array.isArray(t.Bound) ? t.Bound : [], this.data = Array.isArray(t.DataAry) ? t.DataAry : [], this.valid = !1, this.errorMessage = "", this.lonMin = 0, this.latMin = 0, this.lonMax = 0, this.latMax = 0, this.lonCount = 0, this.latCount = 0, this.lonSpan = 0, this.latSpan = 0, this.lonStep = 0, this.latStep = 0, this.valueScale = 1, this.parse();
37
+ }
38
+ parse() {
39
+ if (this.bound.length < 6) {
40
+ this.errorMessage = "Wind field Bound must contain at least 6 values.";
41
+ return;
42
+ }
43
+ const [t, s, n, o, e, a, l = 1] = this.bound, r = Number(n) * Number(o) * 2;
44
+ if (!Number.isFinite(Number(t)) || !Number.isFinite(Number(s)) || Number(n) < 2 || Number(o) < 2 || Number(e) <= 0 || Number(a) <= 0 || this.data.length !== r) {
45
+ this.errorMessage = `Invalid wind field data. Expected DataAry length ${r}, got ${this.data.length}.`;
46
+ return;
47
+ }
48
+ this.lonMin = Number(t), this.latMin = Number(s), this.lonCount = Number(n), this.latCount = Number(o), this.lonSpan = Number(e), this.latSpan = Number(a), this.valueScale = Number(l) || 1, this.lonMax = this.lonMin + this.lonSpan, this.latMax = this.latMin + this.latSpan, this.lonStep = this.lonSpan / (this.lonCount - 1), this.latStep = this.latSpan / (this.latCount - 1), this.valid = !0;
49
+ }
50
+ contains(t, s) {
51
+ return Number.isFinite(t) && Number.isFinite(s) && t >= this.lonMin && t <= this.lonMax && s >= this.latMin && s <= this.latMax;
52
+ }
53
+ getBounds() {
54
+ return {
55
+ west: this.lonMin,
56
+ south: this.latMin,
57
+ east: this.lonMax,
58
+ north: this.latMax
59
+ };
60
+ }
61
+ getCenter() {
62
+ return {
63
+ lon: this.lonMin + this.lonSpan / 2,
64
+ lat: this.latMin + this.latSpan / 2
65
+ };
66
+ }
67
+ getVector(t, s) {
68
+ const n = (t * this.lonCount + s) * 2;
69
+ return {
70
+ u: Number(this.data[n]) / this.valueScale,
71
+ v: Number(this.data[n + 1]) / this.valueScale
72
+ };
73
+ }
74
+ /**
75
+ * 双线性插值。
76
+ *
77
+ * 数据约定为从左下角开始平铺,因此 row 直接对应从南到北的纬度索引。
78
+ */
79
+ sample(t, s) {
80
+ if (!this.valid || !this.contains(t, s))
81
+ return null;
82
+ const n = (t - this.lonMin) / this.lonStep, o = (s - this.latMin) / this.latStep, e = Math.max(0, Math.min(Math.floor(n), this.lonCount - 2)), a = Math.max(0, Math.min(Math.floor(o), this.latCount - 2)), l = e + 1, r = a + 1, h = Math.max(0, Math.min(n - e, 1)), c = Math.max(0, Math.min(o - a, 1)), I = this.getVector(a, e), S = this.getVector(a, l), E = this.getVector(r, e), m = this.getVector(r, l), d = 1 - h, p = 1 - c, b = d * p, A = h * p, O = d * c, D = h * c, N = I.u * b + S.u * A + E.u * O + m.u * D, M = I.v * b + S.v * A + E.v * O + m.v * D;
83
+ return !Number.isFinite(N) || !Number.isFinite(M) ? null : {
84
+ u: N,
85
+ v: M,
86
+ speed: Math.hypot(N, M)
87
+ };
88
+ }
89
+ }
90
+ export {
91
+ u as R,
92
+ x as W,
93
+ g as f,
94
+ C as s,
95
+ T as u
96
+ };