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