@kalisio/common-geospatial 0.5.0 → 0.7.0
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.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +407 -340
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -5
package/dist/index.mjs
CHANGED
|
@@ -1,116 +1,146 @@
|
|
|
1
|
-
import { assert as
|
|
2
|
-
import { getLogger as
|
|
3
|
-
import { Heap as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
1
|
+
import { assert as u, is as i, has as A, conform as T, optional as $ } from "@kalisio/common-core";
|
|
2
|
+
import { getLogger as Q } from "@logtape/logtape";
|
|
3
|
+
import { Heap as fe } from "heap-js";
|
|
4
|
+
import me from "@turf/truncate";
|
|
5
|
+
import de from "@turf/boolean-clockwise";
|
|
6
|
+
import pe from "@turf/kinks";
|
|
7
7
|
const d = {
|
|
8
8
|
LATITUDE: "LAT",
|
|
9
9
|
LONGITUDE: "LON",
|
|
10
10
|
ALTITUDE: "ALT"
|
|
11
11
|
};
|
|
12
|
-
function
|
|
13
|
-
return
|
|
12
|
+
function ve(e) {
|
|
13
|
+
return u.that(e, i.string, "axis must be a string"), Object.values(d).includes(e);
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
return
|
|
15
|
+
function M(e) {
|
|
16
|
+
return u.that(e, i.string, "axis must be a string"), e === d.LATITUDE;
|
|
17
17
|
}
|
|
18
|
-
function
|
|
19
|
-
return
|
|
18
|
+
function Z(e) {
|
|
19
|
+
return u.that(e, i.string, "axis must be a string"), e === d.LONGITUDE;
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
return
|
|
21
|
+
function ut(e) {
|
|
22
|
+
return u.that(e, i.string, "axis must be a string"), e === d.ALTITUDE;
|
|
23
23
|
}
|
|
24
|
-
const
|
|
25
|
-
DIRECTIONS:
|
|
26
|
-
},
|
|
27
|
-
DIRECTIONS:
|
|
28
|
-
},
|
|
24
|
+
const Ee = { NORTH: { label: "Nord", symbol: "N" }, SOUTH: { label: "Sud", symbol: "S" }, EAST: { label: "Est", symbol: "E" }, WEST: { label: "Ouest", symbol: "O" } }, be = {
|
|
25
|
+
DIRECTIONS: Ee
|
|
26
|
+
}, he = { NORTH: { label: "North", symbol: "N" }, SOUTH: { label: "South", symbol: "S" }, EAST: { label: "East", symbol: "E" }, WEST: { label: "West", symbol: "W" } }, ye = {
|
|
27
|
+
DIRECTIONS: he
|
|
28
|
+
}, Oe = {
|
|
29
29
|
DIRECTIONS: {
|
|
30
|
-
NORTH: { label: i.string, symbol: i.
|
|
31
|
-
SOUTH: { label: i.string, symbol: i.
|
|
32
|
-
EAST: { label: i.string, symbol: i.
|
|
33
|
-
WEST: { label: i.string, symbol: i.
|
|
30
|
+
NORTH: { label: i.string, symbol: i.char },
|
|
31
|
+
SOUTH: { label: i.string, symbol: i.char },
|
|
32
|
+
EAST: { label: i.string, symbol: i.char },
|
|
33
|
+
WEST: { label: i.string, symbol: i.char }
|
|
34
34
|
}
|
|
35
|
-
},
|
|
36
|
-
en:
|
|
37
|
-
fr:
|
|
35
|
+
}, h = {
|
|
36
|
+
en: ye,
|
|
37
|
+
fr: be
|
|
38
38
|
};
|
|
39
|
-
let
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
let O = "en";
|
|
40
|
+
const Y = "en";
|
|
41
|
+
function lt() {
|
|
42
|
+
return Object.keys(h);
|
|
42
43
|
}
|
|
43
|
-
function
|
|
44
|
-
|
|
44
|
+
function ct(e, t) {
|
|
45
|
+
u.all([
|
|
45
46
|
{ value: e, validator: i.string, message: "code must be a string" },
|
|
46
|
-
{ value: e, validator: (r) => !
|
|
47
|
+
{ value: e, validator: (r) => !A.key(h, r), message: "locale already registered" },
|
|
47
48
|
{ value: t, validator: i.plainObject, message: "content must be an object" },
|
|
48
|
-
{ value: t, validator: (r) => T.schema(r,
|
|
49
|
-
]),
|
|
49
|
+
{ value: t, validator: (r) => T.schema(r, Oe), message: "content does not conform to schema" }
|
|
50
|
+
]), h[e] = t;
|
|
50
51
|
}
|
|
51
|
-
function
|
|
52
|
-
|
|
52
|
+
function gt(e) {
|
|
53
|
+
u.all([
|
|
53
54
|
{ value: e, validator: i.string, message: "code must be a string" },
|
|
54
|
-
{ value: e, validator: (t) =>
|
|
55
|
-
]),
|
|
55
|
+
{ value: e, validator: (t) => A.key(h, t), message: "code is unknown" }
|
|
56
|
+
]), O = e;
|
|
56
57
|
}
|
|
57
|
-
function
|
|
58
|
-
return
|
|
59
|
-
code: A,
|
|
60
|
-
content: O[A]
|
|
61
|
-
};
|
|
58
|
+
function Te() {
|
|
59
|
+
return O;
|
|
62
60
|
}
|
|
63
|
-
function
|
|
64
|
-
return
|
|
61
|
+
function U(e) {
|
|
62
|
+
return u.all([
|
|
63
|
+
{ value: e, validator: i.string, message: "code must be a string" },
|
|
64
|
+
{ value: e, validator: (t) => A.key(h, t), message: "code is unknown" }
|
|
65
|
+
]), h[e];
|
|
65
66
|
}
|
|
66
|
-
function
|
|
67
|
-
|
|
68
|
-
return t.toUpperCase() === n || t.toUpperCase() === s;
|
|
67
|
+
function J() {
|
|
68
|
+
return O === Y ? [O] : [O, Y];
|
|
69
69
|
}
|
|
70
|
-
function
|
|
71
|
-
const t =
|
|
72
|
-
|
|
70
|
+
function _(e) {
|
|
71
|
+
const t = /* @__PURE__ */ new Set();
|
|
72
|
+
for (const r of J()) {
|
|
73
|
+
const { DIRECTIONS: n } = U(r);
|
|
74
|
+
for (const s of e) t.add(n[s].symbol);
|
|
75
|
+
}
|
|
76
|
+
return [...t];
|
|
73
77
|
}
|
|
74
|
-
function
|
|
75
|
-
return
|
|
78
|
+
function Ie() {
|
|
79
|
+
return _(["NORTH", "SOUTH"]);
|
|
76
80
|
}
|
|
77
|
-
function
|
|
78
|
-
return
|
|
81
|
+
function Le() {
|
|
82
|
+
return _(["EAST", "WEST"]);
|
|
79
83
|
}
|
|
80
|
-
function
|
|
81
|
-
return
|
|
84
|
+
function F() {
|
|
85
|
+
return _(["NORTH", "SOUTH", "EAST", "WEST"]);
|
|
82
86
|
}
|
|
83
|
-
function
|
|
84
|
-
return
|
|
87
|
+
function I() {
|
|
88
|
+
return U(Te()).DIRECTIONS;
|
|
89
|
+
}
|
|
90
|
+
function w(e, t) {
|
|
91
|
+
const r = t.toUpperCase();
|
|
92
|
+
return J().some((n) => {
|
|
93
|
+
const { label: s, symbol: o } = U(n).DIRECTIONS[e];
|
|
94
|
+
return r === s.toUpperCase() || r === o.toUpperCase();
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function ft(e = null) {
|
|
98
|
+
const t = I();
|
|
99
|
+
return i.defined(e) ? (u.that(e, ve, "axis must be a valid axis"), M(e) ? [t.SOUTH, t.NORTH] : Z(e) ? [t.EAST, t.WEST] : []) : [t.SOUTH, t.NORTH, t.EAST, t.WEST];
|
|
100
|
+
}
|
|
101
|
+
function mt() {
|
|
102
|
+
return I().NORTH;
|
|
103
|
+
}
|
|
104
|
+
function dt() {
|
|
105
|
+
return I().SOUTH;
|
|
106
|
+
}
|
|
107
|
+
function pt() {
|
|
108
|
+
return I().EAST;
|
|
109
|
+
}
|
|
110
|
+
function vt() {
|
|
111
|
+
return I().WEST;
|
|
85
112
|
}
|
|
86
113
|
function E(e) {
|
|
87
|
-
return
|
|
114
|
+
return u.that(e, i.string, "dir must be a string"), Se(e) || ee(e) || k(e) || C(e);
|
|
88
115
|
}
|
|
89
|
-
function
|
|
90
|
-
return
|
|
116
|
+
function Se(e) {
|
|
117
|
+
return u.that(e, i.string, "dir must be a string"), w("NORTH", e);
|
|
91
118
|
}
|
|
92
|
-
function
|
|
93
|
-
return
|
|
119
|
+
function ee(e) {
|
|
120
|
+
return u.that(e, i.string, "dir must be a string"), w("SOUTH", e);
|
|
94
121
|
}
|
|
95
|
-
function
|
|
96
|
-
return
|
|
122
|
+
function k(e) {
|
|
123
|
+
return u.that(e, i.string, "dir must be a string"), w("EAST", e);
|
|
97
124
|
}
|
|
98
|
-
function
|
|
99
|
-
return
|
|
125
|
+
function C(e) {
|
|
126
|
+
return u.that(e, i.string, "dir must be a string"), w("WEST", e);
|
|
100
127
|
}
|
|
101
|
-
function
|
|
102
|
-
return
|
|
128
|
+
function Re(e) {
|
|
129
|
+
return u.that(e, E, "dir must be a direction"), C(e) || k(e) ? d.LONGITUDE : d.LATITUDE;
|
|
103
130
|
}
|
|
104
|
-
const
|
|
131
|
+
const De = {
|
|
105
132
|
degrees: i.number,
|
|
106
133
|
direction: $(E)
|
|
107
|
-
},
|
|
108
|
-
function
|
|
134
|
+
}, Ae = /^(-?\d{1,3}(?:\.\d+)?)°?$/;
|
|
135
|
+
function we() {
|
|
136
|
+
return new RegExp(`^(\\d{1,3}(?:\\.\\d+)?)°?([${F()}])$`, "i");
|
|
137
|
+
}
|
|
138
|
+
function L(e) {
|
|
109
139
|
let t = null, r = null;
|
|
110
|
-
if (i.plainObject(e) && T.schema(e,
|
|
140
|
+
if (i.plainObject(e) && T.schema(e, De))
|
|
111
141
|
i.defined(e.direction) ? e.degrees >= 0 && (t = e.degrees, r = e.direction) : t = e.degrees;
|
|
112
142
|
else if (i.string(e)) {
|
|
113
|
-
const n = e.replace(/\s+/g, ""), s = n.match(
|
|
143
|
+
const n = e.replace(/\s+/g, ""), s = n.match(Ae) ?? n.match(we());
|
|
114
144
|
s && (t = parseFloat(s[1]), r = s[2] ?? null);
|
|
115
145
|
}
|
|
116
146
|
return {
|
|
@@ -127,26 +157,29 @@ function I(e) {
|
|
|
127
157
|
return i.number(t);
|
|
128
158
|
},
|
|
129
159
|
toString(n) {
|
|
130
|
-
if (
|
|
160
|
+
if (u.that(n, i.positiveInteger, "decimalPlaces must be a positive integer"), !this.isValid()) return "";
|
|
131
161
|
let s = `${t.toFixed(n)}°`;
|
|
132
162
|
return r && (s += ` ${r}`), s;
|
|
133
163
|
},
|
|
134
164
|
toDecimal() {
|
|
135
|
-
return this.isValid() ?
|
|
165
|
+
return this.isValid() ? L({ degrees: t, direction: r }) : null;
|
|
136
166
|
}
|
|
137
167
|
};
|
|
138
168
|
}
|
|
139
|
-
const
|
|
169
|
+
const Ce = {
|
|
140
170
|
degrees: i.integer,
|
|
141
171
|
minutes: (e) => i.inRangeExclusiveMax(e, 0, 60),
|
|
142
172
|
direction: $(E)
|
|
143
|
-
},
|
|
144
|
-
function
|
|
173
|
+
}, Ne = /^(-?\d{1,3})°(\d{1,2}(?:\.\d+)?)'?$/;
|
|
174
|
+
function Me() {
|
|
175
|
+
return new RegExp(`^(\\d{1,3})°(\\d{1,2}(?:\\.\\d+)?)'?([${F().join("")}])$`, "i");
|
|
176
|
+
}
|
|
177
|
+
function te(e) {
|
|
145
178
|
let t = null, r = null, n = null;
|
|
146
|
-
if (i.plainObject(e) && T.schema(e,
|
|
179
|
+
if (i.plainObject(e) && T.schema(e, Ce))
|
|
147
180
|
i.defined(e.direction) ? e.degrees >= 0 && (t = e.degrees, r = e.minutes, n = e.direction) : (t = e.degrees, r = e.minutes);
|
|
148
181
|
else if (i.string(e)) {
|
|
149
|
-
const s = e.replace(/\s+/g, ""), o = s.match(
|
|
182
|
+
const s = e.replace(/\s+/g, ""), o = s.match(Ne) ?? s.match(Me());
|
|
150
183
|
o && (t = parseFloat(o[1]), r = parseFloat(o[2]), n = o[3] ?? null);
|
|
151
184
|
}
|
|
152
185
|
return {
|
|
@@ -166,26 +199,32 @@ function K(e) {
|
|
|
166
199
|
return i.integer(t) && i.inRangeExclusiveMax(r, 0, 60);
|
|
167
200
|
},
|
|
168
201
|
toString(s) {
|
|
169
|
-
if (
|
|
202
|
+
if (u.that(s, i.positiveInteger, "decimalPlaces must be a positive integer"), !this.isValid()) return "";
|
|
170
203
|
let o = `${t}° ${r.toFixed(s)}'`;
|
|
171
204
|
return n && (o += ` ${n}`), o;
|
|
172
205
|
},
|
|
173
206
|
toDecimal() {
|
|
174
|
-
return this.isValid() ?
|
|
207
|
+
return this.isValid() ? L({ degrees: t + r / 60, direction: n }) : null;
|
|
175
208
|
}
|
|
176
209
|
};
|
|
177
210
|
}
|
|
178
|
-
const
|
|
211
|
+
const xe = {
|
|
179
212
|
degrees: i.nonNegativeInteger,
|
|
180
213
|
minutes: (e) => i.inRangeExclusiveMax(e, 0, 60),
|
|
181
214
|
direction: E
|
|
182
|
-
}
|
|
183
|
-
function
|
|
215
|
+
};
|
|
216
|
+
function $e() {
|
|
217
|
+
return new RegExp(`^(\\d{2})(\\d{3})([${Ie().join("")}])$`, "i");
|
|
218
|
+
}
|
|
219
|
+
function Ue() {
|
|
220
|
+
return new RegExp(`^(\\d{3})(\\d{3})([${Le().join("")}])$`, "i");
|
|
221
|
+
}
|
|
222
|
+
function ne(e) {
|
|
184
223
|
let t = null, r = null, n = null;
|
|
185
|
-
if (i.plainObject(e) && T.schema(e,
|
|
224
|
+
if (i.plainObject(e) && T.schema(e, xe))
|
|
186
225
|
t = e.degrees, r = e.minutes, n = e.direction;
|
|
187
226
|
else if (i.string(e)) {
|
|
188
|
-
const s = e.trim(), o = s.match(
|
|
227
|
+
const s = e.trim(), o = s.match($e()) ?? s.match(Ue());
|
|
189
228
|
o && (t = parseFloat(o[1]), r = parseFloat(o[2]) / 10, n = o[3]);
|
|
190
229
|
}
|
|
191
230
|
return {
|
|
@@ -206,27 +245,30 @@ function z(e) {
|
|
|
206
245
|
},
|
|
207
246
|
toString() {
|
|
208
247
|
if (!this.isValid()) return "";
|
|
209
|
-
const s = n
|
|
210
|
-
return `${o}${
|
|
248
|
+
const s = k(n) || C(n), o = String(t).padStart(s ? 3 : 2, "0"), l = Math.floor(r * 10).toString().padStart(3, "0");
|
|
249
|
+
return `${o}${l}${n}`;
|
|
211
250
|
},
|
|
212
251
|
toDecimal() {
|
|
213
|
-
return this.isValid() ?
|
|
252
|
+
return this.isValid() ? L({ degrees: t + r / 60, direction: n }) : null;
|
|
214
253
|
}
|
|
215
254
|
};
|
|
216
255
|
}
|
|
217
|
-
const
|
|
256
|
+
const _e = {
|
|
218
257
|
degrees: i.integer,
|
|
219
258
|
minutes: (e) => i.integer(e) && i.inRange(e, 0, 59),
|
|
220
259
|
seconds: (e) => i.inRangeExclusiveMax(e, 0, 60),
|
|
221
260
|
direction: $(E)
|
|
222
|
-
},
|
|
223
|
-
function
|
|
261
|
+
}, Fe = /^(-?\d{1,3})°(\d{1,2})'(\d{1,2}(?:\.\d+)?)"?$/;
|
|
262
|
+
function ke() {
|
|
263
|
+
return new RegExp(`^(\\d{1,3})°(\\d{1,2})'(\\d{1,2}(?:\\.\\d+)?)"?([${F().join("")}])$`, "i");
|
|
264
|
+
}
|
|
265
|
+
function re(e) {
|
|
224
266
|
let t = null, r = null, n = null, s = null;
|
|
225
|
-
if (i.plainObject(e) && T.schema(e,
|
|
267
|
+
if (i.plainObject(e) && T.schema(e, _e))
|
|
226
268
|
i.defined(e.direction) ? e.degrees >= 0 && (t = e.degrees, r = e.minutes, n = e.seconds, s = e.direction) : (t = e.degrees, r = e.minutes, n = e.seconds);
|
|
227
269
|
else if (i.string(e)) {
|
|
228
|
-
const o = e.replace(/\s+/g, ""),
|
|
229
|
-
|
|
270
|
+
const o = e.replace(/\s+/g, ""), l = o.match(Fe) ?? o.match(ke());
|
|
271
|
+
l && (t = parseFloat(l[1]), r = parseFloat(l[2]), n = parseFloat(l[3]), s = l[4] ?? null);
|
|
230
272
|
}
|
|
231
273
|
return {
|
|
232
274
|
get degrees() {
|
|
@@ -248,127 +290,127 @@ function q(e) {
|
|
|
248
290
|
return i.integer(t) && i.integer(r) && i.inRange(r, 0, 59) && i.inRangeExclusiveMax(n, 0, 60);
|
|
249
291
|
},
|
|
250
292
|
toString(o) {
|
|
251
|
-
if (
|
|
252
|
-
let
|
|
253
|
-
return s && (
|
|
293
|
+
if (u.that(o, i.positiveInteger, "decimalPlaces must be a positive integer"), !this.isValid()) return "";
|
|
294
|
+
let l = `${t}° ${r}' ${n.toFixed(o)}"`;
|
|
295
|
+
return s && (l += ` ${s}`), l;
|
|
254
296
|
},
|
|
255
297
|
toDecimal() {
|
|
256
|
-
return this.isValid() ?
|
|
298
|
+
return this.isValid() ? L({ degrees: t + r / 60 + n / 3600, direction: s }) : null;
|
|
257
299
|
}
|
|
258
300
|
};
|
|
259
301
|
}
|
|
260
|
-
function
|
|
302
|
+
function W(e) {
|
|
261
303
|
const t = Math.floor(e.degrees), r = (e.degrees - t) * 60;
|
|
262
304
|
return { degrees: t, minutes: r, direction: e.direction };
|
|
263
305
|
}
|
|
264
|
-
function
|
|
306
|
+
function Ge(e) {
|
|
265
307
|
const t = Math.floor(e.degrees), r = (e.degrees - t) * 60, n = Math.floor(r), s = (r - n) * 60;
|
|
266
308
|
return { degrees: t, minutes: n, seconds: s, direction: e.direction };
|
|
267
309
|
}
|
|
268
|
-
const
|
|
269
|
-
DD: (e) => (
|
|
310
|
+
const K = {
|
|
311
|
+
DD: (e) => (u.that(e, (t) => t.isValid(), "dd must be a valid coordinate"), e),
|
|
270
312
|
DDM: (e) => {
|
|
271
|
-
|
|
272
|
-
const { degrees: t, minutes: r, direction: n } =
|
|
273
|
-
return
|
|
313
|
+
u.that(e, (s) => s.isValid(), "dd must be a valid coordinate");
|
|
314
|
+
const { degrees: t, minutes: r, direction: n } = W(e);
|
|
315
|
+
return te(n ? { degrees: t, minutes: r, direction: n } : { degrees: t, minutes: r });
|
|
274
316
|
},
|
|
275
317
|
DMS: (e) => {
|
|
276
|
-
|
|
277
|
-
const { degrees: t, minutes: r, seconds: n, direction: s } =
|
|
278
|
-
return
|
|
318
|
+
u.that(e, (o) => o.isValid(), "dd must be a valid coordinate");
|
|
319
|
+
const { degrees: t, minutes: r, seconds: n, direction: s } = Ge(e);
|
|
320
|
+
return re(s ? { degrees: t, minutes: r, seconds: n, direction: s } : { degrees: t, minutes: r, seconds: n });
|
|
279
321
|
},
|
|
280
322
|
DDM_AERO: (e) => {
|
|
281
|
-
|
|
282
|
-
const { degrees: t, minutes: r, direction: n } =
|
|
283
|
-
return
|
|
323
|
+
u.that(e, (s) => s.isValid(), "dd must be a valid coordinate");
|
|
324
|
+
const { degrees: t, minutes: r, direction: n } = W(e);
|
|
325
|
+
return ne({ degrees: t, minutes: r, direction: n });
|
|
284
326
|
}
|
|
285
|
-
},
|
|
327
|
+
}, x = {
|
|
286
328
|
DD: "DD",
|
|
287
329
|
DDM: "DDM",
|
|
288
330
|
DDM_AERO: "DDM_AERO",
|
|
289
331
|
DMS: "DMS"
|
|
290
|
-
},
|
|
291
|
-
DD:
|
|
292
|
-
DDM:
|
|
293
|
-
DDM_AERO:
|
|
294
|
-
DMS:
|
|
295
|
-
},
|
|
296
|
-
function
|
|
297
|
-
if (
|
|
298
|
-
return
|
|
332
|
+
}, Pe = {
|
|
333
|
+
DD: L,
|
|
334
|
+
DDM: te,
|
|
335
|
+
DDM_AERO: ne,
|
|
336
|
+
DMS: re
|
|
337
|
+
}, G = Array.from({ length: 9 }, (e, t) => 10 ** t);
|
|
338
|
+
function X(e, t) {
|
|
339
|
+
if (u.that(e, i.number, "coord must be a number"), i.defined(t))
|
|
340
|
+
return u.that(t, E, "dir must be a direction"), Re(t);
|
|
299
341
|
if (Math.abs(e) > 90) return d.LONGITUDE;
|
|
300
342
|
}
|
|
301
|
-
function
|
|
302
|
-
|
|
343
|
+
function z(e) {
|
|
344
|
+
u.that(e, i.number, "coord must be a number");
|
|
303
345
|
const t = e.toExponential(), [r, n] = t.split("e").map(Number), s = (r.toString().split(".")[1] || "").length;
|
|
304
346
|
return Math.max(0, s - n);
|
|
305
347
|
}
|
|
306
|
-
function
|
|
307
|
-
|
|
348
|
+
function Et(e, t = 7) {
|
|
349
|
+
u.all([
|
|
308
350
|
{ value: e, validator: i.number, message: "coord must be a number" },
|
|
309
351
|
{ value: t, validator: (n) => i.inRange(n, 0, 8), message: "precision must be in range [0, 8]" }
|
|
310
352
|
]);
|
|
311
|
-
const r =
|
|
353
|
+
const r = G[t];
|
|
312
354
|
return Math.round(e * r) / r;
|
|
313
355
|
}
|
|
314
|
-
function
|
|
315
|
-
if (
|
|
356
|
+
function bt(e, t) {
|
|
357
|
+
if (u.all([
|
|
316
358
|
{ value: e, validator: i.number, message: "coord must be a number" },
|
|
317
|
-
{ value: t, validator: (n) =>
|
|
318
|
-
]),
|
|
359
|
+
{ value: t, validator: (n) => Z(n) || M(n), message: "axis must be either a longitude or latitude" }
|
|
360
|
+
]), M(t))
|
|
319
361
|
return Math.max(-90, Math.min(90, e));
|
|
320
362
|
let r = ((e + 180) % 360 + 360) % 360 - 180;
|
|
321
363
|
return r === -180 && (r = 180), Object.is(r, -0) && (r = 0), r;
|
|
322
364
|
}
|
|
323
|
-
function
|
|
324
|
-
|
|
365
|
+
function ht(e, t) {
|
|
366
|
+
u.all([
|
|
325
367
|
{ value: e, validator: (n) => i.defined(n) && n.isValid(), message: "from must be a valid coordinate" },
|
|
326
|
-
{ value: t, validator: (n) =>
|
|
368
|
+
{ value: t, validator: (n) => A.key(K, n), message: `unknown format: ${t}` }
|
|
327
369
|
]);
|
|
328
|
-
const r = e.format ===
|
|
329
|
-
return r.isValid() ? t ===
|
|
370
|
+
const r = e.format === x.DD ? e : e.toDecimal();
|
|
371
|
+
return r.isValid() ? t === x.DD ? r : K[t](r) : null;
|
|
330
372
|
}
|
|
331
|
-
function
|
|
332
|
-
|
|
333
|
-
for (const t of Object.keys(
|
|
334
|
-
const r =
|
|
373
|
+
function He(e) {
|
|
374
|
+
u.that(e, i.nonEmptyString, "pattern must be a non empty string");
|
|
375
|
+
for (const t of Object.keys(x)) {
|
|
376
|
+
const r = Pe[t](e);
|
|
335
377
|
if (r.isValid()) return r;
|
|
336
378
|
}
|
|
337
379
|
return null;
|
|
338
380
|
}
|
|
339
|
-
function
|
|
340
|
-
|
|
381
|
+
function yt(e) {
|
|
382
|
+
u.that(e, (a) => i.nonEmptyString(a), "pattern must be a non-empty string");
|
|
341
383
|
const t = e.split(/[,;|]/);
|
|
342
384
|
if (t.length !== 2) return null;
|
|
343
|
-
const [r, n] = t.map(
|
|
385
|
+
const [r, n] = t.map(He);
|
|
344
386
|
if (!r || !n) return null;
|
|
345
|
-
const s = r.toDecimal(), o = n.toDecimal(),
|
|
346
|
-
const { degrees: p, direction:
|
|
347
|
-
return
|
|
387
|
+
const s = r.toDecimal(), o = n.toDecimal(), l = X(s.degrees, s.direction), g = X(o.degrees, o.direction), c = (a) => {
|
|
388
|
+
const { degrees: p, direction: f } = a;
|
|
389
|
+
return f && (C(f) || ee(f)) ? -p : p;
|
|
348
390
|
};
|
|
349
|
-
if (
|
|
350
|
-
if (g === d.LONGITUDE &&
|
|
351
|
-
if (
|
|
352
|
-
if (
|
|
353
|
-
if (g === d.LONGITUDE && !
|
|
354
|
-
if (g === d.LATITUDE && !
|
|
355
|
-
if (!
|
|
391
|
+
if (l === d.LONGITUDE && g === d.LATITUDE) return [c(s), c(o)];
|
|
392
|
+
if (g === d.LONGITUDE && l === d.LATITUDE) return [c(o), c(s)];
|
|
393
|
+
if (l === d.LONGITUDE && !g) return [c(s), o];
|
|
394
|
+
if (l === d.LATITUDE && !g) return [c(o), c(s)];
|
|
395
|
+
if (g === d.LONGITUDE && !l) return [c(o), c(s)];
|
|
396
|
+
if (g === d.LATITUDE && !l) return [c(s), c(o)];
|
|
397
|
+
if (!l && !g)
|
|
356
398
|
return [
|
|
357
399
|
[c(s), c(o)],
|
|
358
400
|
[c(o), c(s)]
|
|
359
401
|
];
|
|
360
402
|
}
|
|
361
|
-
function
|
|
403
|
+
function Ve(e) {
|
|
362
404
|
return !i.arrayOfLength(e, 4) && !i.arrayOfLength(e, 6) ? !1 : e.every(i.number);
|
|
363
405
|
}
|
|
364
|
-
const
|
|
406
|
+
const S = {
|
|
365
407
|
NAME: "name",
|
|
366
408
|
LINK: "link"
|
|
367
409
|
};
|
|
368
|
-
function
|
|
369
|
-
return i.plainObject(e) ? e.type ===
|
|
410
|
+
function Ot(e) {
|
|
411
|
+
return i.plainObject(e) ? e.type === S.NAME ? i.nonEmptyString(e.properties?.name) : e.type === S.LINK ? i.nonEmptyString(e.properties?.href) : !1 : !1;
|
|
370
412
|
}
|
|
371
|
-
const
|
|
413
|
+
const m = {
|
|
372
414
|
POINT: "Point",
|
|
373
415
|
MULTI_POINT: "MultiPoint",
|
|
374
416
|
LINESTRING: "LineString",
|
|
@@ -377,43 +419,43 @@ const f = {
|
|
|
377
419
|
MULTI_POLYGON: "MultiPolygon",
|
|
378
420
|
GEOMETRY_COLLECTION: "GeometryCollection"
|
|
379
421
|
};
|
|
380
|
-
function
|
|
381
|
-
return !i.plainObject(e) || !i.oneOf(e.type, Object.values(
|
|
422
|
+
function P(e) {
|
|
423
|
+
return !i.plainObject(e) || !i.oneOf(e.type, Object.values(m)) ? !1 : e.type === m.GEOMETRY_COLLECTION ? i.array(e.geometries) : i.array(e.coordinates);
|
|
382
424
|
}
|
|
383
425
|
const v = {
|
|
384
426
|
FEATURE: "Feature",
|
|
385
427
|
FEATURE_COLLECTION: "FeatureCollection"
|
|
386
428
|
};
|
|
387
|
-
function
|
|
429
|
+
function je(e) {
|
|
388
430
|
return i.plainObject(e) ? v.FEATURE === e.type : !1;
|
|
389
431
|
}
|
|
390
|
-
function
|
|
432
|
+
function Be(e) {
|
|
391
433
|
return !i.plainObject(e) || e.type !== v.FEATURE_COLLECTION ? !1 : i.array(e.features);
|
|
392
434
|
}
|
|
393
|
-
function
|
|
394
|
-
return i.plainObject(e) ?
|
|
435
|
+
function ie(e) {
|
|
436
|
+
return i.plainObject(e) ? P(e) || je(e) ? !0 : Be(e) : !1;
|
|
395
437
|
}
|
|
396
|
-
function
|
|
438
|
+
function Ye(e) {
|
|
397
439
|
return i.arrayOfLengthBetween(e, 2, 3) ? e.every(i.number) : !1;
|
|
398
440
|
}
|
|
399
|
-
function
|
|
441
|
+
function We(e, t, r) {
|
|
400
442
|
return Math.abs(
|
|
401
443
|
(e[0] * (t[1] - r[1]) + t[0] * (r[1] - e[1]) + r[0] * (e[1] - t[1])) / 2
|
|
402
444
|
);
|
|
403
445
|
}
|
|
404
|
-
function
|
|
446
|
+
function N(e, { tolerance: t = 0, getWeight: r = () => 1 } = {}) {
|
|
405
447
|
if (e.length <= 2) return e;
|
|
406
448
|
const n = e.map((a, p) => ({ coord: a, i: p, area: 1 / 0, removed: !1, prev: null, next: null }));
|
|
407
449
|
for (let a = 0; a < n.length; a++)
|
|
408
450
|
a > 0 && (n[a].prev = n[a - 1]), a < n.length - 1 && (n[a].next = n[a + 1]);
|
|
409
|
-
const s = (a) => !a.prev || !a.next ? 1 / 0 :
|
|
451
|
+
const s = (a) => !a.prev || !a.next ? 1 / 0 : We(a.prev.coord, a.coord, a.next.coord) * r(a.coord, a.i), o = new fe((a, p) => a.area - p.area);
|
|
410
452
|
for (let a = 1; a < n.length - 1; a++)
|
|
411
453
|
n[a].area = s(n[a]), n[a]._currentArea = n[a].area, o.push(n[a]);
|
|
412
|
-
let
|
|
454
|
+
let l = 0;
|
|
413
455
|
for (; o.size() > 0; ) {
|
|
414
456
|
const a = o.pop();
|
|
415
457
|
if (!a.removed && a.area === a._currentArea) {
|
|
416
|
-
if (a.area <
|
|
458
|
+
if (a.area < l ? a.area = l : l = a.area, a.area >= t) break;
|
|
417
459
|
a.removed = !0, a.prev && (a.prev.next = a.next), a.next && (a.next.prev = a.prev), a.prev?.prev && (a.prev.area = s(a.prev), a.prev._currentArea = a.prev.area, o.push(a.prev)), a.next?.next && (a.next.area = s(a.next), a.next._currentArea = a.next.area, o.push(a.next));
|
|
418
460
|
}
|
|
419
461
|
}
|
|
@@ -423,92 +465,98 @@ function S(e, { tolerance: t = 0, getWeight: r = () => 1 } = {}) {
|
|
|
423
465
|
c.removed || g.push(c.coord), c = c.next;
|
|
424
466
|
return g;
|
|
425
467
|
}
|
|
426
|
-
function
|
|
427
|
-
switch (
|
|
428
|
-
{ value: e, validator:
|
|
468
|
+
function H(e, t) {
|
|
469
|
+
switch (u.all([
|
|
470
|
+
{ value: e, validator: P, message: "geometry must be a GeoJson geometry" }
|
|
429
471
|
]), e.type) {
|
|
430
|
-
case
|
|
431
|
-
e.coordinates =
|
|
472
|
+
case m.LINESTRING:
|
|
473
|
+
e.coordinates = N(e.coordinates, t);
|
|
432
474
|
break;
|
|
433
|
-
case
|
|
434
|
-
case
|
|
435
|
-
e.coordinates = e.coordinates.map((r) =>
|
|
475
|
+
case m.POLYGON:
|
|
476
|
+
case m.MULTI_LINESTRING:
|
|
477
|
+
e.coordinates = e.coordinates.map((r) => N(r, t));
|
|
436
478
|
break;
|
|
437
|
-
case
|
|
438
|
-
e.coordinates = e.coordinates.map((r) => r.map((n) =>
|
|
479
|
+
case m.MULTI_POLYGON:
|
|
480
|
+
e.coordinates = e.coordinates.map((r) => r.map((n) => N(n, t)));
|
|
439
481
|
break;
|
|
440
|
-
case
|
|
441
|
-
e.geometries.forEach((r) =>
|
|
482
|
+
case m.GEOMETRY_COLLECTION:
|
|
483
|
+
e.geometries.forEach((r) => H(r, t));
|
|
442
484
|
break;
|
|
443
485
|
}
|
|
444
486
|
return e;
|
|
445
487
|
}
|
|
446
|
-
const
|
|
447
|
-
function
|
|
488
|
+
const Ke = Q(["common-ekosystem", "simplify", "geojson"]);
|
|
489
|
+
function se(e, t) {
|
|
448
490
|
if (e.type === v.FEATURE)
|
|
449
|
-
e.geometry &&
|
|
491
|
+
e.geometry && H(e.geometry, t);
|
|
450
492
|
else if (e.type === v.FEATURE_COLLECTION)
|
|
451
|
-
for (const r of e.features)
|
|
493
|
+
for (const r of e.features) se(r, t);
|
|
452
494
|
else
|
|
453
|
-
|
|
495
|
+
Ke.warn('Unknown feature type "{type}", skipping.', { type: e.type });
|
|
454
496
|
return e;
|
|
455
497
|
}
|
|
456
|
-
function
|
|
457
|
-
return
|
|
458
|
-
{ value: e, validator:
|
|
459
|
-
]), i.oneOf(e.type, Object.values(
|
|
498
|
+
function Tt(e, t) {
|
|
499
|
+
return u.all([
|
|
500
|
+
{ value: e, validator: ie, message: "geoJson must be a GeoJson object" }
|
|
501
|
+
]), i.oneOf(e.type, Object.values(m)) ? H(e, t) : se(e, t);
|
|
460
502
|
}
|
|
461
|
-
function
|
|
462
|
-
|
|
463
|
-
{ value: e, validator:
|
|
503
|
+
function ae(e, t = 7) {
|
|
504
|
+
u.all([
|
|
505
|
+
{ value: e, validator: Ve, message: "bbox must be bounding box" },
|
|
464
506
|
{ value: t, validator: (n) => i.inRange(n, 0, 8), message: "precision must be in range [0, 8]" }
|
|
465
507
|
]);
|
|
466
|
-
const r =
|
|
508
|
+
const r = G[t];
|
|
467
509
|
for (let n = 0; n < e.length; n++)
|
|
468
510
|
e[n] = Math.round(e[n] * r) / r;
|
|
469
511
|
return e;
|
|
470
512
|
}
|
|
471
|
-
function
|
|
472
|
-
|
|
473
|
-
{ value: e, validator:
|
|
513
|
+
function oe(e, t = 7) {
|
|
514
|
+
u.all([
|
|
515
|
+
{ value: e, validator: P, message: "geometry must be a GeoJson geometry" },
|
|
474
516
|
{ value: t, validator: (n) => i.inRange(n, 0, 8), message: "precision must be in range [0, 8]" }
|
|
475
517
|
]);
|
|
476
|
-
const r =
|
|
477
|
-
return r.bbox &&
|
|
518
|
+
const r = me(e, { precision: t, mutate: !0 });
|
|
519
|
+
return r.bbox && ae(r.bbox, t), r;
|
|
478
520
|
}
|
|
479
|
-
const
|
|
480
|
-
function
|
|
521
|
+
const Xe = Q(["common-ekosystem", "truncate", "geojson"]);
|
|
522
|
+
function ue(e, t) {
|
|
481
523
|
if (e.type === v.FEATURE)
|
|
482
|
-
e.geometry &&
|
|
524
|
+
e.geometry && oe(e.geometry, t);
|
|
483
525
|
else if (e.type === v.FEATURE_COLLECTION)
|
|
484
|
-
for (const r of e.features)
|
|
526
|
+
for (const r of e.features) ue(r, t);
|
|
485
527
|
else
|
|
486
|
-
|
|
487
|
-
return e.bbox &&
|
|
528
|
+
Xe.warn('Unknown feature type "{type}", skipping.', { type: e.type });
|
|
529
|
+
return e.bbox && ae(e.bbox, t), e;
|
|
488
530
|
}
|
|
489
|
-
function
|
|
490
|
-
return
|
|
491
|
-
{ value: e, validator:
|
|
531
|
+
function It(e, t = 7) {
|
|
532
|
+
return u.all([
|
|
533
|
+
{ value: e, validator: ie, message: "geoJson must be a valid GeoJson" },
|
|
492
534
|
{ value: t, validator: (r) => i.inRange(r, 0, 8), message: "precision must be in range [0, 8]" }
|
|
493
|
-
]), i.oneOf(e.type, Object.values(
|
|
535
|
+
]), i.oneOf(e.type, Object.values(m)) ? oe(e, t) : ue(e, t);
|
|
494
536
|
}
|
|
495
|
-
function
|
|
496
|
-
|
|
497
|
-
{ value: e, validator:
|
|
537
|
+
function Lt(e, t = 7) {
|
|
538
|
+
u.all([
|
|
539
|
+
{ value: e, validator: Ye, message: "position must be a position" },
|
|
498
540
|
{ value: t, validator: (n) => i.inRange(n, 0, 8), message: "precision must be in range [0, 8]" }
|
|
499
541
|
]);
|
|
500
|
-
const r =
|
|
542
|
+
const r = G[t];
|
|
501
543
|
for (let n = 0; n < e.length; n++)
|
|
502
544
|
e[n] = Math.round(e[n] * r) / r;
|
|
503
545
|
return e;
|
|
504
546
|
}
|
|
505
|
-
function
|
|
547
|
+
function R(e) {
|
|
506
548
|
if (!i.arrayOfLengthBetween(e, 2, 3))
|
|
507
549
|
return {
|
|
508
550
|
valid: !1,
|
|
509
551
|
errors: [{ message: "Invalid coordinates: must be an array of 2 or 3 coordinates" }],
|
|
510
552
|
warnings: []
|
|
511
553
|
};
|
|
554
|
+
if (!i.number(e[0]) || !i.number(e[1]))
|
|
555
|
+
return {
|
|
556
|
+
valid: !1,
|
|
557
|
+
errors: [{ message: "Invalid coordinates: longitude and latitude must be numbers" }],
|
|
558
|
+
warnings: []
|
|
559
|
+
};
|
|
512
560
|
if (!i.inRange(e[0], -180, 180))
|
|
513
561
|
return {
|
|
514
562
|
valid: !1,
|
|
@@ -527,43 +575,52 @@ function D(e) {
|
|
|
527
575
|
errors: [{ message: "Invalid coordinates: altitude must be a number" }],
|
|
528
576
|
warnings: []
|
|
529
577
|
};
|
|
530
|
-
const t = { valid: !0, errors: [], warnings: [] }, r =
|
|
578
|
+
const t = { valid: !0, errors: [], warnings: [] }, r = z(e[0]);
|
|
531
579
|
r > 6 && t.warnings.push({ message: `longitude precision is high (${r} decimals, max recommended: 6)` });
|
|
532
|
-
const n =
|
|
580
|
+
const n = z(e[1]);
|
|
533
581
|
return n > 6 && t.warnings.push({ message: `latitude precision is high (${n} decimals, max recommended: 6)` }), t;
|
|
534
582
|
}
|
|
535
|
-
function
|
|
583
|
+
function ze(e) {
|
|
536
584
|
if (!i.arrayOfLength(e, 4) && !i.arrayOfLength(e, 6))
|
|
537
585
|
return {
|
|
538
586
|
valid: !1,
|
|
539
587
|
errors: [{ message: "Invalid bbox: must be an array of 4 (2D) or 6 (3D) numbers" }],
|
|
540
588
|
warnings: []
|
|
541
589
|
};
|
|
542
|
-
const t = e.length === 4, r = t ? [e[0], e[1]] : [e[0], e[1], e[2]], n = t ? [e[2], e[3]] : [e[3], e[4], e[5]], s =
|
|
590
|
+
const t = e.length === 4, r = t ? [e[0], e[1]] : [e[0], e[1], e[2]], n = t ? [e[2], e[3]] : [e[3], e[4], e[5]], s = R(r);
|
|
543
591
|
if (!s.valid)
|
|
544
592
|
return {
|
|
545
593
|
valid: !1,
|
|
546
|
-
errors: s.errors.map((
|
|
594
|
+
errors: s.errors.map((f) => ({ ...f, message: `Invalid bbox south-west: ${f.message}` })),
|
|
547
595
|
warnings: []
|
|
548
596
|
};
|
|
549
|
-
const o =
|
|
597
|
+
const o = R(n);
|
|
550
598
|
if (!o.valid)
|
|
551
599
|
return {
|
|
552
600
|
valid: !1,
|
|
553
|
-
errors: o.errors.map((
|
|
601
|
+
errors: o.errors.map((f) => ({ ...f, message: `Invalid bbox north-east: ${f.message}` })),
|
|
554
602
|
warnings: []
|
|
555
603
|
};
|
|
556
|
-
const [
|
|
604
|
+
const [l, g] = r, [c, a] = n;
|
|
557
605
|
if (g > a)
|
|
558
606
|
return {
|
|
559
607
|
valid: !1,
|
|
560
608
|
errors: [{ message: `Invalid bbox: south (${g}) must be <= north (${a})` }],
|
|
561
609
|
warnings: []
|
|
562
610
|
};
|
|
611
|
+
if (!t) {
|
|
612
|
+
const f = e[2], B = e[5];
|
|
613
|
+
if (f > B)
|
|
614
|
+
return {
|
|
615
|
+
valid: !1,
|
|
616
|
+
errors: [{ message: `Invalid bbox: min altitude (${f}) must be <= max altitude (${B})` }],
|
|
617
|
+
warnings: []
|
|
618
|
+
};
|
|
619
|
+
}
|
|
563
620
|
const p = { valid: !0, errors: [], warnings: [] };
|
|
564
|
-
return
|
|
621
|
+
return l > c && p.warnings.push({ message: `bbox crosses the antimeridian (west: ${l} > east: ${c})` }), p.warnings.push(...s.warnings.map((f) => ({ ...f, message: `south-west: ${f.message}` }))), p.warnings.push(...o.warnings.map((f) => ({ ...f, message: `north-east: ${f.message}` }))), p;
|
|
565
622
|
}
|
|
566
|
-
function
|
|
623
|
+
function qe(e) {
|
|
567
624
|
if (!i.plainObject(e))
|
|
568
625
|
return {
|
|
569
626
|
valid: !1,
|
|
@@ -571,13 +628,13 @@ function He(e) {
|
|
|
571
628
|
warnings: []
|
|
572
629
|
};
|
|
573
630
|
switch (e.type) {
|
|
574
|
-
case
|
|
631
|
+
case S.NAME:
|
|
575
632
|
return i.nonEmptyString(e.properties?.name) ? { valid: !0, errors: [], warnings: [] } : {
|
|
576
633
|
valid: !1,
|
|
577
634
|
errors: [{ message: "Invalid crs: linked crs must have a non-empty properties.name string" }],
|
|
578
635
|
warnings: []
|
|
579
636
|
};
|
|
580
|
-
case
|
|
637
|
+
case S.LINK:
|
|
581
638
|
return i.nonEmptyString(e.properties?.href) ? { valid: !0, errors: [], warnings: [] } : {
|
|
582
639
|
valid: !1,
|
|
583
640
|
errors: [{ message: "Invalid crs: linked crs must have a non-empty properties.href string" }],
|
|
@@ -591,11 +648,11 @@ function He(e) {
|
|
|
591
648
|
};
|
|
592
649
|
}
|
|
593
650
|
}
|
|
594
|
-
function
|
|
651
|
+
function b() {
|
|
595
652
|
return { Feature: 0, FeatureCollection: 0, geometries: {} };
|
|
596
653
|
}
|
|
597
|
-
function
|
|
598
|
-
const t =
|
|
654
|
+
function Qe(...e) {
|
|
655
|
+
const t = b();
|
|
599
656
|
for (const r of e) {
|
|
600
657
|
const n = r.statistics;
|
|
601
658
|
if (n) {
|
|
@@ -606,41 +663,42 @@ function Ve(...e) {
|
|
|
606
663
|
}
|
|
607
664
|
return t;
|
|
608
665
|
}
|
|
609
|
-
function
|
|
666
|
+
function y(e, t, r = "") {
|
|
610
667
|
const n = {
|
|
611
668
|
valid: !0,
|
|
612
669
|
errors: [],
|
|
613
|
-
warnings: []
|
|
670
|
+
warnings: [],
|
|
671
|
+
statistics: b()
|
|
614
672
|
};
|
|
615
673
|
for (let s = 0; s < e.length; s++) {
|
|
616
|
-
const o = `${r}/${s}`,
|
|
617
|
-
if (!
|
|
618
|
-
n.valid = !1, n.errors = n.errors.concat(
|
|
674
|
+
const o = `${r}/${s}`, l = t(e[s], o, s);
|
|
675
|
+
if (l.statistics && (n.statistics = Qe(n, l)), !l.valid) {
|
|
676
|
+
n.valid = !1, n.errors = n.errors.concat(l.errors.map((g) => ({ ...g, path: g.path || o, index: s })));
|
|
619
677
|
continue;
|
|
620
678
|
}
|
|
621
|
-
i.empty(
|
|
679
|
+
i.empty(l.warnings) || (n.warnings = n.warnings.concat(l.warnings.map((g) => ({ ...g, path: g.path || o, index: s }))));
|
|
622
680
|
}
|
|
623
681
|
return n;
|
|
624
682
|
}
|
|
625
|
-
function
|
|
683
|
+
function q(e, t) {
|
|
626
684
|
if (!i.defined(e.crs)) return t;
|
|
627
|
-
const r =
|
|
685
|
+
const r = qe(e.crs);
|
|
628
686
|
return r.valid || (t.valid = !1, t.errors.push(...r.errors.map((n) => ({ ...n, path: "/crs" })))), t.warnings.push(...r.warnings.map((n) => ({ ...n, path: "/crs" }))), t;
|
|
629
687
|
}
|
|
630
|
-
function
|
|
688
|
+
function D(e, t, r = "") {
|
|
631
689
|
if (!i.defined(e.bbox)) return t;
|
|
632
|
-
const n =
|
|
690
|
+
const n = ze(e.bbox);
|
|
633
691
|
return n.valid || (t.valid = !1, t.errors.push(...n.errors.map((s) => ({ ...s, path: `${r}/bbox` })))), t.warnings.push(...n.warnings.map((s) => ({ ...s, path: `${r}/bbox` }))), t;
|
|
634
692
|
}
|
|
635
|
-
function
|
|
636
|
-
return i.arrayOfLengthAtLeast(e, t) ?
|
|
693
|
+
function V(e, t = 0, r = "") {
|
|
694
|
+
return i.arrayOfLengthAtLeast(e, t) ? y(e, R, r) : {
|
|
637
695
|
valid: !1,
|
|
638
696
|
errors: [{ message: `Invalid coordinates: must have at least ${t} positions`, path: r }],
|
|
639
697
|
warnings: []
|
|
640
698
|
};
|
|
641
699
|
}
|
|
642
|
-
function
|
|
643
|
-
const r =
|
|
700
|
+
function le(e, t = "") {
|
|
701
|
+
const r = V(e, 2, t);
|
|
644
702
|
if (!r.valid) return r;
|
|
645
703
|
for (let n = 0; n < e.length - 1; n++) {
|
|
646
704
|
const s = e[n][0], o = e[n + 1][0];
|
|
@@ -651,46 +709,46 @@ function ne(e, t = "") {
|
|
|
651
709
|
}
|
|
652
710
|
return r;
|
|
653
711
|
}
|
|
654
|
-
function
|
|
655
|
-
return i.nonEmptyArray(e) ?
|
|
712
|
+
function Ze(e, t = "") {
|
|
713
|
+
return i.nonEmptyArray(e) ? y(e, le, t) : {
|
|
656
714
|
valid: !1,
|
|
657
715
|
errors: [{ message: "Invalid MultiLineString: coordinates must be a non empty array", path: t }],
|
|
658
716
|
warnings: []
|
|
659
717
|
};
|
|
660
718
|
}
|
|
661
|
-
function
|
|
662
|
-
const n =
|
|
719
|
+
function Je(e, t, r = "") {
|
|
720
|
+
const n = V(e, 4, r);
|
|
663
721
|
if (!n.valid) return n;
|
|
664
722
|
const s = e[0], o = e[e.length - 1];
|
|
665
723
|
if (s[0] !== o[0] || s[1] !== o[1])
|
|
666
724
|
return n.valid = !1, n.errors.push({ message: "Invalid LinearRing: first and last position must be identical", path: r }), n;
|
|
667
|
-
const g =
|
|
725
|
+
const g = de(e) ? "clockwise" : "counter-clockwise";
|
|
668
726
|
g !== t && n.warnings.push({ message: `Ring must be ${t} but is ${g}`, path: r });
|
|
669
|
-
const c =
|
|
727
|
+
const c = pe({ type: "Polygon", coordinates: [e] });
|
|
670
728
|
return c.features.length > 0 && (n.valid = !1, n.errors.push({ message: `Invalid LinearRing: ${c.features.length} self-intersection(s) detected`, path: r })), n;
|
|
671
729
|
}
|
|
672
|
-
function
|
|
673
|
-
return i.nonEmptyArray(e) ?
|
|
730
|
+
function ce(e, t = "") {
|
|
731
|
+
return i.nonEmptyArray(e) ? y(e, (r, n, s) => Je(r, s === 0 ? "counter-clockwise" : "clockwise", n), t) : {
|
|
674
732
|
valid: !1,
|
|
675
733
|
errors: [{ message: "Invalid Polygon: coordinates must be a non empty array", path: t }],
|
|
676
734
|
warnings: []
|
|
677
735
|
};
|
|
678
736
|
}
|
|
679
|
-
function
|
|
680
|
-
return i.nonEmptyArray(e) ?
|
|
737
|
+
function et(e, t = "") {
|
|
738
|
+
return i.nonEmptyArray(e) ? y(e, (r, n) => ce(r, n), t) : {
|
|
681
739
|
valid: !1,
|
|
682
740
|
errors: [{ message: "Invalid MultiPolygon: coordinates must be a non empty array", path: t }],
|
|
683
741
|
warnings: []
|
|
684
742
|
};
|
|
685
743
|
}
|
|
686
|
-
function
|
|
687
|
-
return i.nonEmptyArray(e) ?
|
|
744
|
+
function tt(e, t = "") {
|
|
745
|
+
return i.nonEmptyArray(e) ? y(e, (r, n) => j(r, n), t) : {
|
|
688
746
|
valid: !1,
|
|
689
747
|
errors: [{ message: "Invalid geometries: geometries must be a non empty array", path: t }],
|
|
690
748
|
warnings: []
|
|
691
749
|
};
|
|
692
750
|
}
|
|
693
|
-
function
|
|
751
|
+
function j(e, t = "") {
|
|
694
752
|
if (!i.nonEmptyObject(e))
|
|
695
753
|
return {
|
|
696
754
|
valid: !1,
|
|
@@ -700,8 +758,8 @@ function k(e, t = "") {
|
|
|
700
758
|
const r = `${t}/coordinates`;
|
|
701
759
|
let n;
|
|
702
760
|
switch (e.type) {
|
|
703
|
-
case
|
|
704
|
-
const s =
|
|
761
|
+
case m.POINT: {
|
|
762
|
+
const s = R(e.coordinates);
|
|
705
763
|
n = {
|
|
706
764
|
valid: s.valid,
|
|
707
765
|
errors: s.errors.map((o) => ({ ...o, path: r })),
|
|
@@ -709,28 +767,28 @@ function k(e, t = "") {
|
|
|
709
767
|
};
|
|
710
768
|
break;
|
|
711
769
|
}
|
|
712
|
-
case
|
|
713
|
-
n =
|
|
770
|
+
case m.MULTI_POINT: {
|
|
771
|
+
n = V(e.coordinates, 0, r);
|
|
714
772
|
break;
|
|
715
773
|
}
|
|
716
|
-
case
|
|
717
|
-
n =
|
|
774
|
+
case m.LINESTRING: {
|
|
775
|
+
n = le(e.coordinates, r);
|
|
718
776
|
break;
|
|
719
777
|
}
|
|
720
|
-
case
|
|
721
|
-
n =
|
|
778
|
+
case m.MULTI_LINESTRING: {
|
|
779
|
+
n = Ze(e.coordinates, r);
|
|
722
780
|
break;
|
|
723
781
|
}
|
|
724
|
-
case
|
|
725
|
-
n =
|
|
782
|
+
case m.POLYGON: {
|
|
783
|
+
n = ce(e.coordinates, r);
|
|
726
784
|
break;
|
|
727
785
|
}
|
|
728
|
-
case
|
|
729
|
-
n =
|
|
786
|
+
case m.MULTI_POLYGON: {
|
|
787
|
+
n = et(e.coordinates, r);
|
|
730
788
|
break;
|
|
731
789
|
}
|
|
732
|
-
case
|
|
733
|
-
n =
|
|
790
|
+
case m.GEOMETRY_COLLECTION: {
|
|
791
|
+
n = tt(e.geometries, `${t}/geometries`);
|
|
734
792
|
break;
|
|
735
793
|
}
|
|
736
794
|
default:
|
|
@@ -740,25 +798,26 @@ function k(e, t = "") {
|
|
|
740
798
|
warnings: []
|
|
741
799
|
};
|
|
742
800
|
}
|
|
743
|
-
return
|
|
801
|
+
return n = D(e, n, t), n.statistics = { geometries: { [e.type]: 1 } }, n;
|
|
744
802
|
}
|
|
745
|
-
function
|
|
803
|
+
function ge(e, t = "") {
|
|
746
804
|
if (!i.nonEmptyObject(e))
|
|
747
805
|
return {
|
|
748
806
|
valid: !1,
|
|
749
807
|
errors: [{ message: "Invalid feature: must be a non empty object", path: t }],
|
|
750
808
|
warnings: [],
|
|
751
|
-
statistics:
|
|
809
|
+
statistics: b()
|
|
752
810
|
};
|
|
753
811
|
if (e.type === v.FEATURE) {
|
|
754
812
|
if (i.nonEmptyObject(e.geometry)) {
|
|
755
|
-
const r =
|
|
813
|
+
const r = j(e.geometry, `${t}/geometry`);
|
|
756
814
|
return {
|
|
757
|
-
...
|
|
815
|
+
...D(e, r, t),
|
|
758
816
|
statistics: {
|
|
759
817
|
Feature: 1,
|
|
760
818
|
FeatureCollection: 0,
|
|
761
|
-
|
|
819
|
+
// Geometry counting is owned by validateGeometry.
|
|
820
|
+
geometries: { ...r.statistics.geometries }
|
|
762
821
|
}
|
|
763
822
|
};
|
|
764
823
|
}
|
|
@@ -771,9 +830,9 @@ function ie(e, t = "") {
|
|
|
771
830
|
}
|
|
772
831
|
if (e.type === v.FEATURE_COLLECTION) {
|
|
773
832
|
if (i.nonEmptyArray(e.features)) {
|
|
774
|
-
const r =
|
|
833
|
+
const r = y(e.features, ge, `${t}/features`);
|
|
775
834
|
return {
|
|
776
|
-
...
|
|
835
|
+
...D(e, r, t),
|
|
777
836
|
statistics: { ...r.statistics, FeatureCollection: r.statistics.FeatureCollection + 1 }
|
|
778
837
|
};
|
|
779
838
|
}
|
|
@@ -781,84 +840,92 @@ function ie(e, t = "") {
|
|
|
781
840
|
valid: !1,
|
|
782
841
|
errors: [{ message: "Invalid FeatureCollection: features must be a non empty array", path: t }],
|
|
783
842
|
warnings: [],
|
|
784
|
-
statistics:
|
|
843
|
+
statistics: b()
|
|
785
844
|
};
|
|
786
845
|
}
|
|
787
846
|
return {
|
|
788
847
|
valid: !1,
|
|
789
848
|
errors: [{ message: `Invalid feature: unknown type: ${e.type}`, path: t }],
|
|
790
849
|
warnings: [],
|
|
791
|
-
statistics:
|
|
850
|
+
statistics: b()
|
|
792
851
|
};
|
|
793
852
|
}
|
|
794
|
-
function
|
|
795
|
-
if (
|
|
853
|
+
function St(e) {
|
|
854
|
+
if (u.that(e, i.nonEmptyObject, "geojson must be a non empty object"), i.oneOf(e.type, Object.values(m))) {
|
|
855
|
+
const t = j(e, ""), r = D(e, t, "");
|
|
796
856
|
return {
|
|
797
|
-
...
|
|
798
|
-
|
|
857
|
+
...q(e, r),
|
|
858
|
+
// Geometry counting is owned by validateGeometry.
|
|
859
|
+
statistics: { Feature: 0, FeatureCollection: 0, geometries: { ...t.statistics.geometries } }
|
|
799
860
|
};
|
|
861
|
+
}
|
|
800
862
|
if (e.type === v.FEATURE || e.type === v.FEATURE_COLLECTION) {
|
|
801
|
-
const t =
|
|
802
|
-
return
|
|
863
|
+
const t = ge(e, "");
|
|
864
|
+
return q(e, t);
|
|
803
865
|
}
|
|
804
866
|
return {
|
|
805
867
|
valid: !1,
|
|
806
|
-
errors: [{ message: "Invalid GeoJson: type must be either a Geometry, a Feature or a FeatureCollection" }],
|
|
868
|
+
errors: [{ message: "Invalid GeoJson: type must be either a Geometry, a Feature or a FeatureCollection", path: "" }],
|
|
807
869
|
warnings: [],
|
|
808
|
-
statistics:
|
|
870
|
+
statistics: b()
|
|
809
871
|
};
|
|
810
872
|
}
|
|
811
873
|
export {
|
|
812
874
|
d as AXES,
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
875
|
+
x as COORDINATE_FORMATS,
|
|
876
|
+
Pe as COORDINATE_MODELS,
|
|
877
|
+
G as COORDINATE_TRUNCATION_FACTORS,
|
|
878
|
+
S as CRS_TYPES,
|
|
817
879
|
v as FEATURE_TYPES,
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
880
|
+
m as GEOMETRY_TYPES,
|
|
881
|
+
ht as convertCoordinate,
|
|
882
|
+
J as getActiveLocales,
|
|
883
|
+
F as getAllDirectionSymbols,
|
|
884
|
+
z as getCoordinatePrecision,
|
|
885
|
+
Re as getDirectionAxis,
|
|
886
|
+
ft as getDirections,
|
|
887
|
+
pt as getEast,
|
|
888
|
+
Ie as getLatitudeSymbols,
|
|
889
|
+
Te as getLocale,
|
|
890
|
+
U as getLocaleByCode,
|
|
891
|
+
Le as getLongitudeSymbols,
|
|
892
|
+
mt as getNorth,
|
|
893
|
+
dt as getSouth,
|
|
894
|
+
vt as getWest,
|
|
895
|
+
X as guessCoordinateAxis,
|
|
896
|
+
ut as isAltitude,
|
|
897
|
+
ve as isAxis,
|
|
831
898
|
E as isDirection,
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
899
|
+
k as isEast,
|
|
900
|
+
M as isLatitude,
|
|
901
|
+
Ve as isLikeBBox,
|
|
902
|
+
Ot as isLikeCRS,
|
|
903
|
+
je as isLikeFeature,
|
|
904
|
+
Be as isLikeFeatureCollection,
|
|
905
|
+
ie as isLikeGeoJson,
|
|
906
|
+
P as isLikeGeometry,
|
|
907
|
+
Ye as isLikePosition,
|
|
908
|
+
Z as isLongitude,
|
|
909
|
+
Se as isNorth,
|
|
910
|
+
ee as isSouth,
|
|
911
|
+
C as isWest,
|
|
912
|
+
lt as listLocales,
|
|
913
|
+
bt as normalizeCoordinate,
|
|
914
|
+
He as parseCoordinate,
|
|
915
|
+
yt as parsePosition,
|
|
916
|
+
ct as registerLocale,
|
|
917
|
+
gt as setLocale,
|
|
918
|
+
Tt as simplifyGeoJson,
|
|
919
|
+
H as simplifyGeometry,
|
|
920
|
+
ae as truncateBBox,
|
|
921
|
+
Et as truncateCoordinate,
|
|
922
|
+
It as truncateGeoJson,
|
|
923
|
+
oe as truncateGeometry,
|
|
924
|
+
Lt as truncatePosition,
|
|
925
|
+
ze as validateBBox,
|
|
926
|
+
qe as validateCRS,
|
|
927
|
+
St as validateGeoJson,
|
|
928
|
+
j as validateGeometry,
|
|
929
|
+
R as validatePosition
|
|
863
930
|
};
|
|
864
931
|
//# sourceMappingURL=index.mjs.map
|