@idm-plugin/geo 1.0.1 → 1.0.3

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