@idm-plugin/geo 1.0.1 → 1.0.2
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/index.js +169 -113
- package/dist/index.umd.cjs +1 -1
- package/dist/tropicals/src/index.d.ts +13 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import M from "moment";
|
|
2
2
|
import "moment-timezone";
|
|
3
|
-
import
|
|
4
|
-
import * as
|
|
5
|
-
class
|
|
3
|
+
import T from "tz-lookup";
|
|
4
|
+
import * as N from "@turf/turf";
|
|
5
|
+
class u {
|
|
6
6
|
/**
|
|
7
7
|
* 基于输入的经度,计算出时区
|
|
8
8
|
* @param lng
|
|
9
9
|
* @param lat
|
|
10
10
|
*/
|
|
11
|
-
static guessTimeZoneOffset(e,
|
|
12
|
-
const
|
|
11
|
+
static guessTimeZoneOffset(e, t) {
|
|
12
|
+
const o = T(t, e), i = M().tz(o).utcOffset();
|
|
13
13
|
return this.roundPrecision(i / 60, 1);
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
@@ -18,22 +18,22 @@ class s {
|
|
|
18
18
|
* @return timezone => +08:30
|
|
19
19
|
*/
|
|
20
20
|
static prettyTimeZoneOffset(e) {
|
|
21
|
-
let
|
|
22
|
-
return
|
|
21
|
+
let t = Math.floor(Math.abs(e)), o = Math.round((Math.abs(e) - t) * 60);
|
|
22
|
+
return o = o > 9 ? o : `0${o}`, t = t > 9 ? t : `0${t}`, e > 0 ? `+${t}:${o}` : `-${t}:${o}`;
|
|
23
23
|
}
|
|
24
|
-
static lng2pretty(e,
|
|
25
|
-
e =
|
|
24
|
+
static lng2pretty(e, t = 6, o = "H°M′") {
|
|
25
|
+
e = u.convertToStdLng(e, t);
|
|
26
26
|
let i = "E";
|
|
27
|
-
e < 0 && (i = "W"), e = Math.abs(e),
|
|
28
|
-
let
|
|
29
|
-
n =
|
|
30
|
-
const
|
|
27
|
+
e < 0 && (i = "W"), e = Math.abs(e), o = o.toUpperCase();
|
|
28
|
+
let r = e * 3600, n, p, s, d, a, f;
|
|
29
|
+
n = r % 3600 % 60, o.indexOf("S") !== -1 && (r = r - n, p = u.padNumber(n, 2, 2)), s = r / 60 % 60, o.indexOf("M") !== -1 && (o.indexOf("S") !== -1 ? d = u.roundPrecision(s, t).toString().padStart(2, "0") : d = u.padNumber(s, 2, 2), r = r - s * 60), a = r / 3600, o.indexOf("M") !== -1 ? f = u.roundPrecision(a, t).toString().padStart(3, "0") : f = u.padNumber(a, 3, 2);
|
|
30
|
+
const h = `${o.replace(/S+/gi, p).replace(/M+/gi, d).replace(/H+/gi, f)}${i}`;
|
|
31
31
|
return {
|
|
32
32
|
direction: i,
|
|
33
|
-
degree:
|
|
34
|
-
minute:
|
|
35
|
-
second:
|
|
36
|
-
pretty:
|
|
33
|
+
degree: u.roundPrecision(a, t),
|
|
34
|
+
minute: u.roundPrecision(s, t),
|
|
35
|
+
second: u.roundPrecision(n, t),
|
|
36
|
+
pretty: h
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
@@ -42,71 +42,71 @@ class s {
|
|
|
42
42
|
* @param precision 精确度
|
|
43
43
|
* @param format 格式化
|
|
44
44
|
*/
|
|
45
|
-
static lat2pretty(e,
|
|
45
|
+
static lat2pretty(e, t = 6, o = "H°M′") {
|
|
46
46
|
e = e % 180;
|
|
47
47
|
let i = "N";
|
|
48
|
-
e < 0 && (i = "S"), e = Math.abs(e),
|
|
49
|
-
let
|
|
50
|
-
n =
|
|
51
|
-
const
|
|
48
|
+
e < 0 && (i = "S"), e = Math.abs(e), o = o.toUpperCase();
|
|
49
|
+
let r = e * 3600, n, p, s, d, a, f;
|
|
50
|
+
n = r % 3600 % 60, o.indexOf("S") !== -1 && (r = r - n, p = u.padNumber(n, 2, 2)), s = r / 60 % 60, o.indexOf("M") !== -1 && (o.indexOf("S") !== -1 ? d = u.roundPrecision(s, t).toString().padStart(2, "0") : d = u.padNumber(s, 2, 2), r = r - s * 60), a = r / 3600, o.indexOf("M") !== -1 ? f = u.roundPrecision(a, t).toString().padStart(2, "0") : f = u.padNumber(a, 2, 2);
|
|
51
|
+
const h = `${o.replace(/S+/gi, p).replace(/M+/gi, d).replace(/H+/gi, f)}${i}`;
|
|
52
52
|
return {
|
|
53
53
|
direction: i,
|
|
54
|
-
degree:
|
|
55
|
-
minute:
|
|
56
|
-
second:
|
|
57
|
-
pretty:
|
|
54
|
+
degree: u.roundPrecision(a, t),
|
|
55
|
+
minute: u.roundPrecision(s, t),
|
|
56
|
+
second: u.roundPrecision(n, t),
|
|
57
|
+
pretty: h
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
|
-
static str2Lng(e,
|
|
61
|
-
let
|
|
60
|
+
static str2Lng(e, t = 6) {
|
|
61
|
+
let o;
|
|
62
62
|
if (isNaN(e)) {
|
|
63
|
-
e =
|
|
63
|
+
e = u.strReplace(e, "LNG");
|
|
64
64
|
const i = e[e.length - 1].toUpperCase();
|
|
65
65
|
e = e.substring(0, e.length - 1).trim();
|
|
66
|
-
const
|
|
67
|
-
let [n,
|
|
68
|
-
if (n > 360 && !
|
|
69
|
-
const
|
|
70
|
-
|
|
66
|
+
const r = e.split(" ").filter((s) => s !== "").map((s) => Number(s));
|
|
67
|
+
let [n, p] = r;
|
|
68
|
+
if (n > 360 && !p) {
|
|
69
|
+
const s = this.roundPrecision(n / 100, 0);
|
|
70
|
+
p = n - s * 100, n = s;
|
|
71
71
|
}
|
|
72
|
-
|
|
72
|
+
o = n + (p ?? 0) / 60, i === "W" && (o = o * -1);
|
|
73
73
|
} else
|
|
74
|
-
|
|
75
|
-
return
|
|
74
|
+
o = Number(e);
|
|
75
|
+
return u.convertToStdLng(o, t);
|
|
76
76
|
}
|
|
77
|
-
static str2Lat(e,
|
|
78
|
-
let
|
|
77
|
+
static str2Lat(e, t = 6) {
|
|
78
|
+
let o;
|
|
79
79
|
if (isNaN(e)) {
|
|
80
|
-
e =
|
|
80
|
+
e = u.strReplace(e, "LAT");
|
|
81
81
|
const i = e[e.length - 1].toUpperCase();
|
|
82
82
|
e = e.substring(0, e.length - 1).trim();
|
|
83
|
-
const
|
|
84
|
-
let [n,
|
|
85
|
-
if (n > 90 && !
|
|
86
|
-
const
|
|
87
|
-
|
|
83
|
+
const r = e.split(" ").filter((s) => s !== "").map((s) => Number(s));
|
|
84
|
+
let [n, p] = r;
|
|
85
|
+
if (n > 90 && !p) {
|
|
86
|
+
const s = this.roundPrecision(n / 100, 0);
|
|
87
|
+
p = n - s * 100, n = s;
|
|
88
88
|
}
|
|
89
|
-
|
|
89
|
+
o = n + (p ?? 0) / 60, i === "S" && (o = o * -1);
|
|
90
90
|
} else
|
|
91
|
-
|
|
92
|
-
return
|
|
91
|
+
o = Number(e);
|
|
92
|
+
return u.roundPrecision(o, t);
|
|
93
93
|
}
|
|
94
|
-
static str2LngOrLat(e,
|
|
95
|
-
e =
|
|
94
|
+
static str2LngOrLat(e, t = 6, o = "LAT") {
|
|
95
|
+
e = u.strReplace(e, o);
|
|
96
96
|
const i = e[e.length - 1].toUpperCase();
|
|
97
97
|
return ["N", "S"].includes(i) ? {
|
|
98
|
-
lat:
|
|
98
|
+
lat: u.str2Lat(e, t)
|
|
99
99
|
} : {
|
|
100
|
-
lng:
|
|
100
|
+
lng: u.str2Lng(e, t)
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
|
-
static convertToStdLng(e,
|
|
104
|
-
return e > 180 ? (e = e % 360, e = e > 180 ? e - 360 : e) : e < -180 && (e = e % 360, e = e < -180 ? e + 360 : e),
|
|
103
|
+
static convertToStdLng(e, t = 4) {
|
|
104
|
+
return e > 180 ? (e = e % 360, e = e > 180 ? e - 360 : e) : e < -180 && (e = e % 360, e = e < -180 ? e + 360 : e), u.roundPrecision(e, t);
|
|
105
105
|
}
|
|
106
|
-
static roundPrecision(e,
|
|
106
|
+
static roundPrecision(e, t = 4) {
|
|
107
107
|
if (typeof e == "number") {
|
|
108
|
-
const
|
|
109
|
-
return Math.round(e *
|
|
108
|
+
const o = Number("1".padEnd(t + 1, "0"));
|
|
109
|
+
return Math.round(e * o) / o;
|
|
110
110
|
}
|
|
111
111
|
return e;
|
|
112
112
|
}
|
|
@@ -115,8 +115,8 @@ class s {
|
|
|
115
115
|
* @param coordinates [[lng, lat]]
|
|
116
116
|
*/
|
|
117
117
|
static convertToMonotonicLng2(e) {
|
|
118
|
-
for (let
|
|
119
|
-
e[
|
|
118
|
+
for (let t = 1; t < e.length; t++)
|
|
119
|
+
e[t][0] += Math.round((e[t - 1][0] - e[t][0]) / 360) * 360;
|
|
120
120
|
return e;
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
@@ -124,18 +124,18 @@ class s {
|
|
|
124
124
|
* @param coordinates [{lng, lat}]
|
|
125
125
|
*/
|
|
126
126
|
static convertToMonotonicLng(e) {
|
|
127
|
-
for (let
|
|
128
|
-
e[
|
|
127
|
+
for (let t = 1; t < e.length; t++)
|
|
128
|
+
e[t].lng += Math.round((e[t - 1].lng - e[t].lng) / 360) * 360;
|
|
129
129
|
return e;
|
|
130
130
|
}
|
|
131
|
-
static strReplace(e,
|
|
131
|
+
static strReplace(e, t = "LAT") {
|
|
132
132
|
e = e.replace(/([0-9]+)\.([0-9]+\.[0-9]+)/g, "$1 $2").replace(/-/g, " ").replace(/°/, " ").replace(/'/g, " ").replace(/′/g, " ").replace(/"/g, " ").replace(/∼/g, " ").replace(/°/g, " ").replace(/,/g, ".").replace(/^ /g, "").replace(/ $/g, "").trim();
|
|
133
|
-
const
|
|
134
|
-
if (!["N", "S", "E", "W"].includes(
|
|
135
|
-
const i = e,
|
|
136
|
-
if (isNaN(
|
|
133
|
+
const o = e[e.length - 1].toUpperCase();
|
|
134
|
+
if (!["N", "S", "E", "W"].includes(o)) {
|
|
135
|
+
const i = e, r = Number(i.split(" ")[0]);
|
|
136
|
+
if (isNaN(r))
|
|
137
137
|
throw new Error(`invalid Lat/Lng: ${e}`);
|
|
138
|
-
|
|
138
|
+
r >= 90 ? e = `${i}E` : r <= -90 ? e = `${i}W` : ["LAN", "LNG"].includes(t == null ? void 0 : t.toUpperCase()) ? e = `${i}${r > 0 ? "E" : "W"}` : e = `${i}${r > 0 ? "N" : "S"}`;
|
|
139
139
|
}
|
|
140
140
|
return e;
|
|
141
141
|
}
|
|
@@ -146,80 +146,136 @@ class s {
|
|
|
146
146
|
* @param intPrecision 整数位数
|
|
147
147
|
* @param dcmPrecision 小数位数
|
|
148
148
|
*/
|
|
149
|
-
static padNumber(e,
|
|
150
|
-
const i = Math.trunc(e).toString().padStart(
|
|
151
|
-
return `${i}.${
|
|
149
|
+
static padNumber(e, t = 2, o = 2) {
|
|
150
|
+
const i = Math.trunc(e).toString().padStart(t, "0"), r = Math.trunc(u.roundPrecision(e - Math.trunc(e), o) * Math.pow(10, o)).toString().padStart(o, "0");
|
|
151
|
+
return `${i}.${r}`;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
class
|
|
154
|
+
class D {
|
|
155
155
|
static convert2Geojson(e) {
|
|
156
|
-
const
|
|
157
|
-
for (const
|
|
158
|
-
if (
|
|
159
|
-
for (const i of
|
|
160
|
-
const
|
|
161
|
-
for (const
|
|
162
|
-
const d = i.hours[
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
156
|
+
const t = N.featureCollection([]);
|
|
157
|
+
for (const o of e) {
|
|
158
|
+
if (o.forecasts)
|
|
159
|
+
for (const i of o.forecasts) {
|
|
160
|
+
const r = [], n = M(i.date).utc(), p = `${o.name}-${i.model}`;
|
|
161
|
+
for (const s in i == null ? void 0 : i.hours) {
|
|
162
|
+
const d = i.hours[s];
|
|
163
|
+
d.wind.spd = d.wind.spd || d.wind.speed;
|
|
164
|
+
const a = n.clone().add(Number(s), "hour"), f = N.point([d.lng, d.lat], {
|
|
165
|
+
date: a.format(),
|
|
166
|
+
hour: Number(s),
|
|
167
|
+
format: a.format("MMM-DD/HHmm[Z]"),
|
|
168
|
+
pressure: d.pressure > 1e4 ? u.roundPrecision(d.pressure / 100, 0) : u.roundPrecision(d.pressure, 0),
|
|
167
169
|
gusts: d.gusts,
|
|
168
170
|
wind: d.wind || {},
|
|
169
171
|
movement: d.movement,
|
|
170
|
-
category:
|
|
172
|
+
category: p,
|
|
171
173
|
type: "forecast"
|
|
172
174
|
});
|
|
173
|
-
|
|
175
|
+
t.features.push(f), r.push(f.geometry.coordinates);
|
|
174
176
|
}
|
|
175
|
-
if ((
|
|
176
|
-
const
|
|
177
|
+
if ((r == null ? void 0 : r.length) > 1) {
|
|
178
|
+
const s = N.lineString(u.convertToMonotonicLng2(r), {
|
|
177
179
|
date: i.date,
|
|
178
|
-
id:
|
|
180
|
+
id: o.id || o.name,
|
|
179
181
|
model: i.model,
|
|
180
|
-
name:
|
|
181
|
-
category:
|
|
182
|
+
name: o.name,
|
|
183
|
+
category: p,
|
|
182
184
|
type: "forecast"
|
|
183
185
|
});
|
|
184
|
-
|
|
186
|
+
t.features.push(s);
|
|
185
187
|
}
|
|
186
188
|
}
|
|
187
|
-
if (
|
|
189
|
+
if (o.history) {
|
|
188
190
|
const i = [];
|
|
189
|
-
for (const n of
|
|
190
|
-
const
|
|
191
|
-
date:
|
|
192
|
-
format:
|
|
193
|
-
pressure: n.pressure > 1e4 ?
|
|
194
|
-
|
|
191
|
+
for (const n of o.history) {
|
|
192
|
+
const p = M(n.updated).utc(), s = N.point([n.lng, n.lat], {
|
|
193
|
+
date: p.format(),
|
|
194
|
+
format: p.format("MMM-DD/HHmm[Z]"),
|
|
195
|
+
pressure: n.pressure > 1e4 ? u.roundPrecision(n.pressure / 100, 0) : u.roundPrecision(n.pressure, 0),
|
|
196
|
+
spd: n.speed || n.spd,
|
|
195
197
|
kts: n.kts,
|
|
196
198
|
source: n.source,
|
|
197
199
|
level: n.type,
|
|
198
200
|
type: "history",
|
|
199
|
-
category: `${
|
|
201
|
+
category: `${o.name}-history`
|
|
200
202
|
});
|
|
201
|
-
|
|
203
|
+
t.features.push(s), i.push(s.geometry.coordinates);
|
|
202
204
|
}
|
|
203
|
-
const
|
|
205
|
+
const r = o.history[0];
|
|
204
206
|
if (i.length === 1 && i.push(i[0]), i.length > 1) {
|
|
205
|
-
const n =
|
|
206
|
-
name:
|
|
207
|
+
const n = N.lineString(u.convertToMonotonicLng2(i), {
|
|
208
|
+
name: o.name,
|
|
207
209
|
type: "history",
|
|
208
|
-
updated:
|
|
209
|
-
pressure: (
|
|
210
|
-
|
|
211
|
-
kts:
|
|
212
|
-
source:
|
|
213
|
-
level:
|
|
210
|
+
updated: r == null ? void 0 : r.updated,
|
|
211
|
+
pressure: (r == null ? void 0 : r.pressure) > 1e4 ? u.roundPrecision((r == null ? void 0 : r.pressure) / 100, 0) : u.roundPrecision(r == null ? void 0 : r.pressure, 0),
|
|
212
|
+
spd: (r == null ? void 0 : r.speed) || (r == null ? void 0 : r.spd),
|
|
213
|
+
kts: r == null ? void 0 : r.kts,
|
|
214
|
+
source: r == null ? void 0 : r.source,
|
|
215
|
+
level: r == null ? void 0 : r.type
|
|
214
216
|
});
|
|
215
|
-
|
|
217
|
+
t.features.push(n);
|
|
216
218
|
}
|
|
217
219
|
}
|
|
218
220
|
}
|
|
219
|
-
return
|
|
221
|
+
return t;
|
|
222
|
+
}
|
|
223
|
+
static interpolate(e, t = 3) {
|
|
224
|
+
var r, n, p, s;
|
|
225
|
+
const o = (r = e == null ? void 0 : e.data) == null ? void 0 : r.features.filter((d) => d.geometry.type === "LineString" && d.properties.type === "forecast"), i = [];
|
|
226
|
+
for (const d of o) {
|
|
227
|
+
const a = d.properties.name, f = d.properties.model, h = M(d.properties.date).utc();
|
|
228
|
+
let y = t * 60 - (h.get("hour") * 60 + h.get("minute")) % (t * 60);
|
|
229
|
+
const b = (n = e == null ? void 0 : e.data) == null ? void 0 : n.features.filter(
|
|
230
|
+
(m) => m.geometry.type === "Point" && m.properties.type === "forecast" && m.properties.category === `${a}-${f}`
|
|
231
|
+
);
|
|
232
|
+
let g, S = h.clone().add(y, "minute").set({ minute: 0, second: 0, millisecond: 0 });
|
|
233
|
+
for (; g = this.pickIndex(b, S), g <= b.length - 1; ) {
|
|
234
|
+
if (g > 0) {
|
|
235
|
+
const m = b[g], c = g === 0 ? void 0 : b[g - 1], l = (y / 60 - ((p = c == null ? void 0 : c.properties) == null ? void 0 : p.hour)) / (m.properties.hour - ((s = c == null ? void 0 : c.properties) == null ? void 0 : s.hour)), $ = this.computeNumber(c == null ? void 0 : c.geometry.coordinates[0], m.geometry.coordinates[0], l), P = this.computeNumber(c == null ? void 0 : c.geometry.coordinates[1], m.geometry.coordinates[1], l), w = N.point([$, P], {
|
|
236
|
+
model: f,
|
|
237
|
+
category: m == null ? void 0 : m.properties.category,
|
|
238
|
+
date: S.format(),
|
|
239
|
+
format: S.format("MMM-DD/HHmm[Z]"),
|
|
240
|
+
gusts: this.computeNumber(c == null ? void 0 : c.properties.gusts, m.properties.gusts, l),
|
|
241
|
+
hour: this.computeNumber(c == null ? void 0 : c.properties.hour, m.properties.hour, l),
|
|
242
|
+
movement: this.computeNumber(c == null ? void 0 : c.properties.movement, m.properties.movement, l),
|
|
243
|
+
pressure: this.computeNumber(c == null ? void 0 : c.properties.pressure, m.properties.pressure, l),
|
|
244
|
+
wind: this.computeNumber(c == null ? void 0 : c.properties.wind, m.properties.wind, l)
|
|
245
|
+
});
|
|
246
|
+
i.push(w);
|
|
247
|
+
}
|
|
248
|
+
y += t * 60, S = h.clone().add(y, "minute").set({ minute: 0, second: 0, millisecond: 0 });
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return i;
|
|
252
|
+
}
|
|
253
|
+
static pickIndex(e, t) {
|
|
254
|
+
let o = 0;
|
|
255
|
+
for (const i of e) {
|
|
256
|
+
if (M(i.properties.date).isAfter(t))
|
|
257
|
+
return o === 0 ? -1 : o;
|
|
258
|
+
o++;
|
|
259
|
+
}
|
|
260
|
+
return o;
|
|
261
|
+
}
|
|
262
|
+
static computeNumber(e, t, o) {
|
|
263
|
+
if (e)
|
|
264
|
+
if (t) {
|
|
265
|
+
if (isNaN(e) && isNaN(t) && typeof e != "string" && typeof t != "string") {
|
|
266
|
+
const i = {};
|
|
267
|
+
for (const r in e)
|
|
268
|
+
i[r] = this.computeNumber(e[r], t[r], o);
|
|
269
|
+
return i;
|
|
270
|
+
}
|
|
271
|
+
return Math.round((e + (t - e) * o) * 100) / 100;
|
|
272
|
+
} else
|
|
273
|
+
return e;
|
|
274
|
+
else
|
|
275
|
+
return t;
|
|
220
276
|
}
|
|
221
277
|
}
|
|
222
278
|
export {
|
|
223
|
-
|
|
224
|
-
|
|
279
|
+
u as LngLatHelper,
|
|
280
|
+
D as TropicalHelper
|
|
225
281
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(h,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("moment"),require("moment-timezone"),require("tz-lookup"),require("@turf/turf")):typeof define=="function"&&define.amd?define(["exports","moment","moment-timezone","tz-lookup","@turf/turf"],l):(h=typeof globalThis<"u"?globalThis:h||self,l(h["idm-plugin-rabbitmq"]={},h.moment,h["moment-timezone"],h["tz-lookup"],h["@turf/turf"]))})(this,function(h,l,j,T,O){"use strict";function w(b){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(b){for(const t in b)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(b,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:()=>b[t]})}}return e.default=b,Object.freeze(e)}const N=w(O);class u{static guessTimeZoneOffset(e,t){const o=T(t,e),i=l().tz(o).utcOffset();return this.roundPrecision(i/60,1)}static prettyTimeZoneOffset(e){let t=Math.floor(Math.abs(e)),o=Math.round((Math.abs(e)-t)*60);return o=o>9?o:`0${o}`,t=t>9?t:`0${t}`,e>0?`+${t}:${o}`:`-${t}:${o}`}static lng2pretty(e,t=6,o="H°M′"){e=u.convertToStdLng(e,t);let i="E";e<0&&(i="W"),e=Math.abs(e),o=o.toUpperCase();let r=e*3600,n,p,s,d,f,a;n=r%3600%60,o.indexOf("S")!==-1&&(r=r-n,p=u.padNumber(n,2,2)),s=r/60%60,o.indexOf("M")!==-1&&(o.indexOf("S")!==-1?d=u.roundPrecision(s,t).toString().padStart(2,"0"):d=u.padNumber(s,2,2),r=r-s*60),f=r/3600,o.indexOf("M")!==-1?a=u.roundPrecision(f,t).toString().padStart(3,"0"):a=u.padNumber(f,3,2);const g=`${o.replace(/S+/gi,p).replace(/M+/gi,d).replace(/H+/gi,a)}${i}`;return{direction:i,degree:u.roundPrecision(f,t),minute:u.roundPrecision(s,t),second:u.roundPrecision(n,t),pretty:g}}static lat2pretty(e,t=6,o="H°M′"){e=e%180;let i="N";e<0&&(i="S"),e=Math.abs(e),o=o.toUpperCase();let r=e*3600,n,p,s,d,f,a;n=r%3600%60,o.indexOf("S")!==-1&&(r=r-n,p=u.padNumber(n,2,2)),s=r/60%60,o.indexOf("M")!==-1&&(o.indexOf("S")!==-1?d=u.roundPrecision(s,t).toString().padStart(2,"0"):d=u.padNumber(s,2,2),r=r-s*60),f=r/3600,o.indexOf("M")!==-1?a=u.roundPrecision(f,t).toString().padStart(2,"0"):a=u.padNumber(f,2,2);const g=`${o.replace(/S+/gi,p).replace(/M+/gi,d).replace(/H+/gi,a)}${i}`;return{direction:i,degree:u.roundPrecision(f,t),minute:u.roundPrecision(s,t),second:u.roundPrecision(n,t),pretty:g}}static str2Lng(e,t=6){let o;if(isNaN(e)){e=u.strReplace(e,"LNG");const i=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const r=e.split(" ").filter(s=>s!=="").map(s=>Number(s));let[n,p]=r;if(n>360&&!p){const s=this.roundPrecision(n/100,0);p=n-s*100,n=s}o=n+(p??0)/60,i==="W"&&(o=o*-1)}else o=Number(e);return u.convertToStdLng(o,t)}static str2Lat(e,t=6){let o;if(isNaN(e)){e=u.strReplace(e,"LAT");const i=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const r=e.split(" ").filter(s=>s!=="").map(s=>Number(s));let[n,p]=r;if(n>90&&!p){const s=this.roundPrecision(n/100,0);p=n-s*100,n=s}o=n+(p??0)/60,i==="S"&&(o=o*-1)}else o=Number(e);return u.roundPrecision(o,t)}static str2LngOrLat(e,t=6,o="LAT"){e=u.strReplace(e,o);const i=e[e.length-1].toUpperCase();return["N","S"].includes(i)?{lat:u.str2Lat(e,t)}:{lng:u.str2Lng(e,t)}}static convertToStdLng(e,t=4){return e>180?(e=e%360,e=e>180?e-360:e):e<-180&&(e=e%360,e=e<-180?e+360:e),u.roundPrecision(e,t)}static roundPrecision(e,t=4){if(typeof e=="number"){const o=Number("1".padEnd(t+1,"0"));return Math.round(e*o)/o}return e}static convertToMonotonicLng2(e){for(let t=1;t<e.length;t++)e[t][0]+=Math.round((e[t-1][0]-e[t][0])/360)*360;return e}static convertToMonotonicLng(e){for(let t=1;t<e.length;t++)e[t].lng+=Math.round((e[t-1].lng-e[t].lng)/360)*360;return e}static strReplace(e,t="LAT"){e=e.replace(/([0-9]+)\.([0-9]+\.[0-9]+)/g,"$1 $2").replace(/-/g," ").replace(/°/," ").replace(/'/g," ").replace(/′/g," ").replace(/"/g," ").replace(/∼/g," ").replace(/°/g," ").replace(/,/g,".").replace(/^ /g,"").replace(/ $/g,"").trim();const o=e[e.length-1].toUpperCase();if(!["N","S","E","W"].includes(o)){const i=e,r=Number(i.split(" ")[0]);if(isNaN(r))throw new Error(`invalid Lat/Lng: ${e}`);r>=90?e=`${i}E`:r<=-90?e=`${i}W`:["LAN","LNG"].includes(t==null?void 0:t.toUpperCase())?e=`${i}${r>0?"E":"W"}`:e=`${i}${r>0?"N":"S"}`}return e}static padNumber(e,t=2,o=2){const i=Math.trunc(e).toString().padStart(t,"0"),r=Math.trunc(u.roundPrecision(e-Math.trunc(e),o)*Math.pow(10,o)).toString().padStart(o,"0");return`${i}.${r}`}}class k{static convert2Geojson(e){const t=N.featureCollection([]);for(const o of e){if(o.forecasts)for(const i of o.forecasts){const r=[],n=l(i.date).utc(),p=`${o.name}-${i.model}`;for(const s in i==null?void 0:i.hours){const d=i.hours[s];d.wind.spd=d.wind.spd||d.wind.speed;const f=n.clone().add(Number(s),"hour"),a=N.point([d.lng,d.lat],{date:f.format(),hour:Number(s),format:f.format("MMM-DD/HHmm[Z]"),pressure:d.pressure>1e4?u.roundPrecision(d.pressure/100,0):u.roundPrecision(d.pressure,0),gusts:d.gusts,wind:d.wind||{},movement:d.movement,category:p,type:"forecast"});t.features.push(a),r.push(a.geometry.coordinates)}if((r==null?void 0:r.length)>1){const s=N.lineString(u.convertToMonotonicLng2(r),{date:i.date,id:o.id||o.name,model:i.model,name:o.name,category:p,type:"forecast"});t.features.push(s)}}if(o.history){const i=[];for(const n of o.history){const p=l(n.updated).utc(),s=N.point([n.lng,n.lat],{date:p.format(),format:p.format("MMM-DD/HHmm[Z]"),pressure:n.pressure>1e4?u.roundPrecision(n.pressure/100,0):u.roundPrecision(n.pressure,0),spd:n.speed||n.spd,kts:n.kts,source:n.source,level:n.type,type:"history",category:`${o.name}-history`});t.features.push(s),i.push(s.geometry.coordinates)}const r=o.history[0];if(i.length===1&&i.push(i[0]),i.length>1){const n=N.lineString(u.convertToMonotonicLng2(i),{name:o.name,type:"history",updated:r==null?void 0:r.updated,pressure:(r==null?void 0:r.pressure)>1e4?u.roundPrecision((r==null?void 0:r.pressure)/100,0):u.roundPrecision(r==null?void 0:r.pressure,0),spd:(r==null?void 0:r.speed)||(r==null?void 0:r.spd),kts:r==null?void 0:r.kts,source:r==null?void 0:r.source,level:r==null?void 0:r.type});t.features.push(n)}}}return t}static interpolate(e,t=3){var r,n,p,s;const o=(r=e==null?void 0:e.data)==null?void 0:r.features.filter(d=>d.geometry.type==="LineString"&&d.properties.type==="forecast"),i=[];for(const d of o){const f=d.properties.name,a=d.properties.model,g=l(d.properties.date).utc();let S=t*60-(g.get("hour")*60+g.get("minute"))%(t*60);const $=(n=e==null?void 0:e.data)==null?void 0:n.features.filter(m=>m.geometry.type==="Point"&&m.properties.type==="forecast"&&m.properties.category===`${f}-${a}`);let M,P=g.clone().add(S,"minute").set({minute:0,second:0,millisecond:0});for(;M=this.pickIndex($,P),M<=$.length-1;){if(M>0){const m=$[M],c=M===0?void 0:$[M-1],y=(S/60-((p=c==null?void 0:c.properties)==null?void 0:p.hour))/(m.properties.hour-((s=c==null?void 0:c.properties)==null?void 0:s.hour)),z=this.computeNumber(c==null?void 0:c.geometry.coordinates[0],m.geometry.coordinates[0],y),D=this.computeNumber(c==null?void 0:c.geometry.coordinates[1],m.geometry.coordinates[1],y),C=N.point([z,D],{model:a,category:m==null?void 0:m.properties.category,date:P.format(),format:P.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(c==null?void 0:c.properties.gusts,m.properties.gusts,y),hour:this.computeNumber(c==null?void 0:c.properties.hour,m.properties.hour,y),movement:this.computeNumber(c==null?void 0:c.properties.movement,m.properties.movement,y),pressure:this.computeNumber(c==null?void 0:c.properties.pressure,m.properties.pressure,y),wind:this.computeNumber(c==null?void 0:c.properties.wind,m.properties.wind,y)});i.push(C)}S+=t*60,P=g.clone().add(S,"minute").set({minute:0,second:0,millisecond:0})}}return i}static pickIndex(e,t){let o=0;for(const i of e){if(l(i.properties.date).isAfter(t))return o===0?-1:o;o++}return o}static computeNumber(e,t,o){if(e)if(t){if(isNaN(e)&&isNaN(t)&&typeof e!="string"&&typeof t!="string"){const i={};for(const r in e)i[r]=this.computeNumber(e[r],t[r],o);return i}return Math.round((e+(t-e)*o)*100)/100}else return e;else return t}}h.LngLatHelper=u,h.TropicalHelper=k,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -6,4 +6,17 @@ export declare class TropicalHelper {
|
|
|
6
6
|
forecasts: any[];
|
|
7
7
|
history: any[];
|
|
8
8
|
}[]): turf.helpers.FeatureCollection<turf.helpers.Geometry, turf.helpers.Properties>;
|
|
9
|
+
static interpolate(tropicals: any, step?: number): turf.helpers.Feature<turf.helpers.Point, {
|
|
10
|
+
model: any;
|
|
11
|
+
category: any;
|
|
12
|
+
date: string;
|
|
13
|
+
format: string;
|
|
14
|
+
gusts: any;
|
|
15
|
+
hour: any;
|
|
16
|
+
movement: any;
|
|
17
|
+
pressure: any;
|
|
18
|
+
wind: any;
|
|
19
|
+
}>[];
|
|
20
|
+
private static pickIndex;
|
|
21
|
+
private static computeNumber;
|
|
9
22
|
}
|