@kalisio/common-geospatial 0.9.0 → 0.10.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/README.md +9 -3
- package/dist/foundation/index.cjs +2 -0
- package/dist/foundation/index.cjs.map +1 -0
- package/dist/foundation/index.mjs +77 -0
- package/dist/foundation/index.mjs.map +1 -0
- package/dist/geojson-CJ6QZ9pN.js +647 -0
- package/dist/geojson-CJ6QZ9pN.js.map +1 -0
- package/dist/geojson-QgqoCFjn.cjs +2 -0
- package/dist/geojson-QgqoCFjn.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +99 -1919
- package/dist/index.mjs.map +1 -1
- package/dist/io/index.cjs +11 -0
- package/dist/io/index.cjs.map +1 -0
- package/dist/io/index.mjs +539 -0
- package/dist/io/index.mjs.map +1 -0
- package/dist/line-CcfAx7LP.js +16 -0
- package/dist/line-CcfAx7LP.js.map +1 -0
- package/dist/line-Doxbvzns.cjs +2 -0
- package/dist/line-Doxbvzns.cjs.map +1 -0
- package/dist/operators/index.cjs +2 -0
- package/dist/operators/index.cjs.map +1 -0
- package/dist/operators/index.mjs +28 -0
- package/dist/operators/index.mjs.map +1 -0
- package/dist/ring-Cks2pGr8.js +1334 -0
- package/dist/ring-Cks2pGr8.js.map +1 -0
- package/dist/ring-CnFBeolv.cjs +2 -0
- package/dist/ring-CnFBeolv.cjs.map +1 -0
- package/dist/truncate-Cb17e4VI.cjs +2 -0
- package/dist/truncate-Cb17e4VI.cjs.map +1 -0
- package/dist/truncate-Cs8jmwOi.js +139 -0
- package/dist/truncate-Cs8jmwOi.js.map +1 -0
- package/package.json +22 -3
|
@@ -0,0 +1,647 @@
|
|
|
1
|
+
import { coordAll as g } from "@turf/meta";
|
|
2
|
+
import { ag as a, S as ie, aj as L, ah as v, ak as C, d as P, am as te, f as se, a7 as X, a8 as K, F as z, D as T, W as ae, a1 as oe, x as ce, X as le, l as b, G as ue, N as fe } from "./ring-Cks2pGr8.js";
|
|
3
|
+
import de from "@turf/buffer";
|
|
4
|
+
import { Heap as Ie } from "heap-js";
|
|
5
|
+
const R = {
|
|
6
|
+
NAME: "name",
|
|
7
|
+
LINK: "link"
|
|
8
|
+
}, d = {
|
|
9
|
+
POINT: "Point",
|
|
10
|
+
MULTI_POINT: "MultiPoint",
|
|
11
|
+
LINESTRING: "LineString",
|
|
12
|
+
MULTI_LINESTRING: "MultiLineString",
|
|
13
|
+
POLYGON: "Polygon",
|
|
14
|
+
MULTI_POLYGON: "MultiPolygon",
|
|
15
|
+
GEOMETRY_COLLECTION: "GeometryCollection"
|
|
16
|
+
}, N = {
|
|
17
|
+
FEATURE: "Feature",
|
|
18
|
+
FEATURE_COLLECTION: "FeatureCollection"
|
|
19
|
+
};
|
|
20
|
+
function be(e) {
|
|
21
|
+
return a.plainObject(e) ? e.type === R.NAME ? a.nonEmptyString(e.properties?.name) : e.type === R.LINK ? a.nonEmptyString(e.properties?.href) : !1 : !1;
|
|
22
|
+
}
|
|
23
|
+
function Be(e) {
|
|
24
|
+
return ie(e);
|
|
25
|
+
}
|
|
26
|
+
function xe(e) {
|
|
27
|
+
return !a.arrayOfLength(e, 4) && !a.arrayOfLength(e, 6) ? !1 : e.every(a.number);
|
|
28
|
+
}
|
|
29
|
+
function Ee(e) {
|
|
30
|
+
return !a.plainObject(e) || !a.oneOf(e.type, Object.values(d)) ? !1 : e.type === d.GEOMETRY_COLLECTION ? a.array(e.geometries) : a.array(e.coordinates);
|
|
31
|
+
}
|
|
32
|
+
function Oe(e) {
|
|
33
|
+
return a.plainObject(e) && e.type === N.FEATURE;
|
|
34
|
+
}
|
|
35
|
+
function Ne(e) {
|
|
36
|
+
return a.plainObject(e) && e.type === N.FEATURE_COLLECTION && a.array(e.features);
|
|
37
|
+
}
|
|
38
|
+
function Le(e) {
|
|
39
|
+
return Oe(e) || Ne(e);
|
|
40
|
+
}
|
|
41
|
+
function U(e) {
|
|
42
|
+
return Le(e) || Ee(e);
|
|
43
|
+
}
|
|
44
|
+
const Te = {
|
|
45
|
+
ignore3D: L(a.boolean)
|
|
46
|
+
};
|
|
47
|
+
function He(e, r = {}) {
|
|
48
|
+
if (v.all([
|
|
49
|
+
{ value: e, validator: U, message: "geoJson must be a GeoJson object" },
|
|
50
|
+
{ value: r, validator: (i) => C.schema(i, Te), message: "options must be a valid options object" }
|
|
51
|
+
]), e.type === N.FEATURE)
|
|
52
|
+
return e.geometry ? P(g(e.geometry), r) : null;
|
|
53
|
+
if (e.type === N.FEATURE_COLLECTION) {
|
|
54
|
+
const i = g(e);
|
|
55
|
+
return i.length ? P(i, r) : null;
|
|
56
|
+
}
|
|
57
|
+
return P(g(e), r);
|
|
58
|
+
}
|
|
59
|
+
const s = Object.freeze(
|
|
60
|
+
Object.fromEntries(
|
|
61
|
+
Object.keys(te.VALIDATION).map((e) => [e, e])
|
|
62
|
+
)
|
|
63
|
+
), pe = [d.POLYGON, d.MULTI_POLYGON], _e = [
|
|
64
|
+
d.LINESTRING,
|
|
65
|
+
d.MULTI_LINESTRING,
|
|
66
|
+
d.POLYGON,
|
|
67
|
+
d.MULTI_POLYGON
|
|
68
|
+
], w = [
|
|
69
|
+
s.INVALID_WINDING_ORDER,
|
|
70
|
+
s.SELF_INTERSECTION,
|
|
71
|
+
s.HOLE_INTERSECTS_SHELL,
|
|
72
|
+
s.DUPLICATE_POSITION
|
|
73
|
+
], Se = {
|
|
74
|
+
validation: a.nonEmptyObject,
|
|
75
|
+
windingOrder: L(a.boolean),
|
|
76
|
+
selfIntersection: L(a.boolean),
|
|
77
|
+
holeIntersectsShell: L(a.boolean),
|
|
78
|
+
duplicatePosition: L(a.boolean),
|
|
79
|
+
precision: L(a.positive)
|
|
80
|
+
};
|
|
81
|
+
function B(e, r) {
|
|
82
|
+
return z(e) !== r ? (e.reverse(), !0) : !1;
|
|
83
|
+
}
|
|
84
|
+
function x(e) {
|
|
85
|
+
let r = !1;
|
|
86
|
+
B(e[0], !1) && (r = !0);
|
|
87
|
+
for (let i = 1; i < e.length; i++)
|
|
88
|
+
B(e[i], !0) && (r = !0);
|
|
89
|
+
return r;
|
|
90
|
+
}
|
|
91
|
+
function ve(e) {
|
|
92
|
+
if (e.type === d.POLYGON)
|
|
93
|
+
return x(e.coordinates);
|
|
94
|
+
let r = !1;
|
|
95
|
+
for (const i of e.coordinates)
|
|
96
|
+
x(i) && (r = !0);
|
|
97
|
+
return r;
|
|
98
|
+
}
|
|
99
|
+
function me(e) {
|
|
100
|
+
return e.type === d.POLYGON ? e.coordinates : e.coordinates.flat(1);
|
|
101
|
+
}
|
|
102
|
+
function Re(e) {
|
|
103
|
+
return e.type === d.POLYGON ? [e.coordinates] : e.coordinates;
|
|
104
|
+
}
|
|
105
|
+
function H(e) {
|
|
106
|
+
return me(e).some((r) => X(r).length > 0);
|
|
107
|
+
}
|
|
108
|
+
function $(e) {
|
|
109
|
+
return Re(e).some((r) => {
|
|
110
|
+
const i = r[0];
|
|
111
|
+
for (let n = 1; n < r.length; n++)
|
|
112
|
+
if (K(i, r[n])) return !0;
|
|
113
|
+
return !1;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function Ae(e) {
|
|
117
|
+
const i = de({ type: "Feature", properties: {}, geometry: e }, 0);
|
|
118
|
+
return i ? { type: i.geometry.type, coordinates: i.geometry.coordinates } : null;
|
|
119
|
+
}
|
|
120
|
+
function Ce(e, r) {
|
|
121
|
+
let i = !1;
|
|
122
|
+
const n = (t) => {
|
|
123
|
+
const c = t.length, o = se(t, { precision: r });
|
|
124
|
+
return o.length !== c && (i = !0), o;
|
|
125
|
+
};
|
|
126
|
+
switch (e.type) {
|
|
127
|
+
case d.LINESTRING:
|
|
128
|
+
e.coordinates = n(e.coordinates);
|
|
129
|
+
break;
|
|
130
|
+
case d.MULTI_LINESTRING:
|
|
131
|
+
e.coordinates = e.coordinates.map(n);
|
|
132
|
+
break;
|
|
133
|
+
case d.POLYGON:
|
|
134
|
+
e.coordinates = e.coordinates.map(n);
|
|
135
|
+
break;
|
|
136
|
+
case d.MULTI_POLYGON:
|
|
137
|
+
e.coordinates = e.coordinates.map((t) => t.map(n));
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
return i;
|
|
141
|
+
}
|
|
142
|
+
function ge(e, r) {
|
|
143
|
+
const i = r.selfIntersection, n = r.holeIntersectsShell;
|
|
144
|
+
if (!i && !n) return [];
|
|
145
|
+
const t = i && H(e), c = n && $(e), o = [];
|
|
146
|
+
if (i && !t && o.push(s.SELF_INTERSECTION), n && !c && o.push(s.HOLE_INTERSECTS_SHELL), !t && !c) return o;
|
|
147
|
+
const l = Ae(e);
|
|
148
|
+
return !l || t && H(l) || c && $(l) || (e.type = l.type, e.coordinates = l.coordinates, t && o.push(s.SELF_INTERSECTION), c && o.push(s.HOLE_INTERSECTS_SHELL)), o;
|
|
149
|
+
}
|
|
150
|
+
function Pe(e, r) {
|
|
151
|
+
const i = [], n = r.precision ?? T;
|
|
152
|
+
if (r.duplicatePosition && _e.includes(e.type) && Ce(e, n) && i.push({ code: s.DUPLICATE_POSITION }), !pe.includes(e.type))
|
|
153
|
+
return { fixed: e, corrections: i };
|
|
154
|
+
r.windingOrder && ve(e) && i.push({ code: s.INVALID_WINDING_ORDER });
|
|
155
|
+
for (const t of ge(e, r))
|
|
156
|
+
i.push({ code: t });
|
|
157
|
+
return { fixed: e, corrections: i };
|
|
158
|
+
}
|
|
159
|
+
function D(e, r) {
|
|
160
|
+
return e.filter((i) => i.path === r || i.path?.startsWith(`${r}/`));
|
|
161
|
+
}
|
|
162
|
+
function y(e, r, i, n) {
|
|
163
|
+
const t = {
|
|
164
|
+
windingOrder: n.windingOrder !== !1 && r.some((I) => I.code === s.INVALID_WINDING_ORDER),
|
|
165
|
+
selfIntersection: n.selfIntersection !== !1 && r.some((I) => I.code === s.SELF_INTERSECTION),
|
|
166
|
+
holeIntersectsShell: n.holeIntersectsShell !== !1 && r.some((I) => I.code === s.HOLE_INTERSECTS_SHELL),
|
|
167
|
+
duplicatePosition: n.duplicatePosition !== !1 && r.some((I) => I.code === s.DUPLICATE_POSITION),
|
|
168
|
+
precision: n.precision
|
|
169
|
+
}, c = t.windingOrder || t.selfIntersection || t.holeIntersectsShell || t.duplicatePosition ? Pe(e, t) : { corrections: [] }, o = new Set(c.corrections.map((I) => I.code)), l = c.corrections.map((I) => ({ ...I, path: i })), E = r.filter((I) => !o.has(I.code));
|
|
170
|
+
return { corrections: l, unfixed: E };
|
|
171
|
+
}
|
|
172
|
+
function $e(e, r) {
|
|
173
|
+
v.all([
|
|
174
|
+
{
|
|
175
|
+
value: e,
|
|
176
|
+
validator: U,
|
|
177
|
+
message: "geoJson must be a GeoJson object"
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
value: r,
|
|
181
|
+
validator: (l) => C.schema(l, Se),
|
|
182
|
+
message: "options must be a valid options object, with a mandatory validation result"
|
|
183
|
+
}
|
|
184
|
+
]);
|
|
185
|
+
const i = [...r.validation.errors, ...r.validation.warnings], n = i.filter((l) => w.includes(l.code)), t = i.filter((l) => !w.includes(l.code));
|
|
186
|
+
if (n.length === 0) return { fixed: e, corrections: [], unfixed: t };
|
|
187
|
+
if (e.type === N.FEATURE_COLLECTION) {
|
|
188
|
+
const l = [];
|
|
189
|
+
return e.features.forEach((E, I) => {
|
|
190
|
+
const u = `/features/${I}/geometry`, f = D(n, u);
|
|
191
|
+
if (f.length === 0) return;
|
|
192
|
+
const _ = y(E.geometry, f, u, r);
|
|
193
|
+
l.push(..._.corrections), t.push(..._.unfixed);
|
|
194
|
+
}), { fixed: e, corrections: l, unfixed: t };
|
|
195
|
+
}
|
|
196
|
+
if (e.type === N.FEATURE) {
|
|
197
|
+
const l = D(n, "/geometry"), E = y(e.geometry, l, "/geometry", r);
|
|
198
|
+
return { fixed: e, corrections: E.corrections, unfixed: [...t, ...E.unfixed] };
|
|
199
|
+
}
|
|
200
|
+
const c = D(n, ""), o = y(e, c, "", r);
|
|
201
|
+
return { fixed: e, corrections: o.corrections, unfixed: [...t, ...o.unfixed] };
|
|
202
|
+
}
|
|
203
|
+
function je(e) {
|
|
204
|
+
return v.all([
|
|
205
|
+
{
|
|
206
|
+
value: e,
|
|
207
|
+
validator: a.nonEmptyObject,
|
|
208
|
+
message: "validation must be a non-empty object"
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
value: e?.errors,
|
|
212
|
+
validator: a.array,
|
|
213
|
+
message: "validation.errors must be an array"
|
|
214
|
+
}
|
|
215
|
+
]), e.errors.length === 0 ? !1 : e.errors.every(
|
|
216
|
+
(r) => w.includes(r.code)
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
const De = {
|
|
220
|
+
tolerance: L(a.number),
|
|
221
|
+
getWeight: L(a.function)
|
|
222
|
+
};
|
|
223
|
+
function ye(e, r, i) {
|
|
224
|
+
return Math.abs(
|
|
225
|
+
(e[0] * (r[1] - i[1]) + r[0] * (i[1] - e[1]) + i[0] * (e[1] - r[1])) / 2
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
function G(e, { tolerance: r = 0, getWeight: i = () => 1 } = {}) {
|
|
229
|
+
if (e.length <= 2) return e;
|
|
230
|
+
const n = e.map((u, f) => ({ coord: u, i: f, area: 1 / 0, removed: !1, prev: null, next: null }));
|
|
231
|
+
for (let u = 0; u < n.length; u++)
|
|
232
|
+
u > 0 && (n[u].prev = n[u - 1]), u < n.length - 1 && (n[u].next = n[u + 1]);
|
|
233
|
+
const t = (u) => !u.prev || !u.next ? 1 / 0 : ye(u.prev.coord, u.coord, u.next.coord) * i(u.coord, u.i), c = new Ie((u, f) => u.area - f.area), o = (u) => {
|
|
234
|
+
u.area = t(u), c.push({ node: u, area: u.area });
|
|
235
|
+
};
|
|
236
|
+
for (let u = 1; u < n.length - 1; u++) o(n[u]);
|
|
237
|
+
let l = 0;
|
|
238
|
+
for (; c.size() > 0; ) {
|
|
239
|
+
const u = c.pop(), f = u.node;
|
|
240
|
+
if (!f.removed && u.area === f.area) {
|
|
241
|
+
if (f.area < l ? f.area = l : l = f.area, f.area >= r) break;
|
|
242
|
+
f.removed = !0, f.prev && (f.prev.next = f.next), f.next && (f.next.prev = f.prev), f.prev?.prev && o(f.prev), f.next?.next && o(f.next);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const E = [];
|
|
246
|
+
let I = n[0];
|
|
247
|
+
for (; I; )
|
|
248
|
+
I.removed || E.push(I.coord), I = I.next;
|
|
249
|
+
return E;
|
|
250
|
+
}
|
|
251
|
+
function h(e, r = {}) {
|
|
252
|
+
if (v.all([
|
|
253
|
+
{ value: e, validator: U, message: "geoJson must be a GeoJson object" },
|
|
254
|
+
{ value: r, validator: (i) => C.schema(i, De), message: "options must be a valid options object" }
|
|
255
|
+
]), e.type === N.FEATURE)
|
|
256
|
+
return e.geometry && h(e.geometry, r), e;
|
|
257
|
+
if (e.type === N.FEATURE_COLLECTION) {
|
|
258
|
+
for (const i of e.features) h(i, r);
|
|
259
|
+
return e;
|
|
260
|
+
}
|
|
261
|
+
switch (e.type) {
|
|
262
|
+
case d.LINESTRING:
|
|
263
|
+
e.coordinates = G(e.coordinates, r);
|
|
264
|
+
break;
|
|
265
|
+
case d.POLYGON:
|
|
266
|
+
case d.MULTI_LINESTRING:
|
|
267
|
+
e.coordinates = e.coordinates.map((i) => G(i, r));
|
|
268
|
+
break;
|
|
269
|
+
case d.MULTI_POLYGON:
|
|
270
|
+
e.coordinates = e.coordinates.map((i) => i.map((n) => G(n, r)));
|
|
271
|
+
break;
|
|
272
|
+
case d.GEOMETRY_COLLECTION:
|
|
273
|
+
e.geometries.forEach((i) => h(i, r));
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
return e;
|
|
277
|
+
}
|
|
278
|
+
const j = "/crs";
|
|
279
|
+
function q(e, r = "", i = {}) {
|
|
280
|
+
if (!a.defined(e))
|
|
281
|
+
return r === j ? (i.geodesic = !0, { crs: ae, valid: !0 }) : { valid: !0 };
|
|
282
|
+
if (r !== j)
|
|
283
|
+
return {
|
|
284
|
+
valid: !1,
|
|
285
|
+
errors: [{ code: s.UNSUPPORTED_NESTED_CRS, path: r }],
|
|
286
|
+
warnings: []
|
|
287
|
+
};
|
|
288
|
+
if (!a.plainObject(e))
|
|
289
|
+
return {
|
|
290
|
+
valid: !1,
|
|
291
|
+
errors: [{ code: s.INVALID_CRS_OBJECT, path: r }],
|
|
292
|
+
warnings: []
|
|
293
|
+
};
|
|
294
|
+
switch (e.type) {
|
|
295
|
+
case R.NAME: {
|
|
296
|
+
if (!a.nonEmptyString(e.properties?.name))
|
|
297
|
+
return {
|
|
298
|
+
valid: !1,
|
|
299
|
+
errors: [{ code: s.INVALID_CRS_NAME, path: r }],
|
|
300
|
+
warnings: []
|
|
301
|
+
};
|
|
302
|
+
const n = oe(e.properties.name);
|
|
303
|
+
return ce(n) ? (i.geodesic = le(n), {
|
|
304
|
+
crs: n,
|
|
305
|
+
valid: !0,
|
|
306
|
+
errors: [],
|
|
307
|
+
warnings: []
|
|
308
|
+
}) : {
|
|
309
|
+
valid: !1,
|
|
310
|
+
errors: [{
|
|
311
|
+
code: s.UNSUPPORTED_CRS,
|
|
312
|
+
path: r,
|
|
313
|
+
params: { name: e.properties.name }
|
|
314
|
+
}],
|
|
315
|
+
warnings: []
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
case R.LINK:
|
|
319
|
+
return a.nonEmptyString(e.properties?.href) ? {
|
|
320
|
+
valid: !1,
|
|
321
|
+
errors: [{ code: s.UNSUPPORTED_LINK_CRS, path: r }],
|
|
322
|
+
warnings: []
|
|
323
|
+
} : {
|
|
324
|
+
valid: !1,
|
|
325
|
+
errors: [{ code: s.INVALID_CRS_LINK, path: r }],
|
|
326
|
+
warnings: []
|
|
327
|
+
};
|
|
328
|
+
default:
|
|
329
|
+
return {
|
|
330
|
+
valid: !1,
|
|
331
|
+
errors: [{
|
|
332
|
+
code: s.INVALID_CRS_TYPE,
|
|
333
|
+
path: r,
|
|
334
|
+
params: { type: e.type }
|
|
335
|
+
}],
|
|
336
|
+
warnings: []
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
function A(e, r = "", i = {}) {
|
|
341
|
+
const n = i.geodesic;
|
|
342
|
+
if (!a.arrayOfLengthBetween(e, 2, 3))
|
|
343
|
+
return {
|
|
344
|
+
valid: !1,
|
|
345
|
+
errors: [{ code: s.INVALID_POSITION_LENGTH, path: r }],
|
|
346
|
+
warnings: []
|
|
347
|
+
};
|
|
348
|
+
if (!a.number(e[0]) || !a.number(e[1]))
|
|
349
|
+
return {
|
|
350
|
+
valid: !1,
|
|
351
|
+
errors: [{ code: s.INVALID_POSITION_COORDINATES, path: r }],
|
|
352
|
+
warnings: []
|
|
353
|
+
};
|
|
354
|
+
if (n) {
|
|
355
|
+
if (!a.inRange(e[0], -180, 180))
|
|
356
|
+
return {
|
|
357
|
+
valid: !1,
|
|
358
|
+
errors: [{ code: s.INVALID_LONGITUDE_RANGE, path: r, params: { value: e[0] } }],
|
|
359
|
+
warnings: []
|
|
360
|
+
};
|
|
361
|
+
if (!a.inRange(e[1], -90, 90))
|
|
362
|
+
return {
|
|
363
|
+
valid: !1,
|
|
364
|
+
errors: [{ code: s.INVALID_LATITUDE_RANGE, path: r, params: { value: e[1] } }],
|
|
365
|
+
warnings: []
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
if (e.length === 3 && !a.number(e[2]))
|
|
369
|
+
return {
|
|
370
|
+
valid: !1,
|
|
371
|
+
errors: [{ code: s.INVALID_ALTITUDE, path: r }],
|
|
372
|
+
warnings: []
|
|
373
|
+
};
|
|
374
|
+
const t = { valid: !0, errors: [], warnings: [] };
|
|
375
|
+
if (n) {
|
|
376
|
+
const c = i.precision ?? T, o = b(e[0]);
|
|
377
|
+
o > c && t.warnings.push({ code: s.EXCESSIVE_LONGITUDE_PRECISION, path: r, params: { precision: o, max: c } });
|
|
378
|
+
const l = b(e[1]);
|
|
379
|
+
l > c && t.warnings.push({ code: s.EXCESSIVE_LATITUDE_PRECISION, path: r, params: { precision: l, max: c } });
|
|
380
|
+
}
|
|
381
|
+
return t;
|
|
382
|
+
}
|
|
383
|
+
function Q(e, r = "", i = {}) {
|
|
384
|
+
const n = i?.geodesic;
|
|
385
|
+
if (!a.defined(e))
|
|
386
|
+
return {
|
|
387
|
+
valid: !0
|
|
388
|
+
};
|
|
389
|
+
if (!a.arrayOfLength(e, 4) && !a.arrayOfLength(e, 6))
|
|
390
|
+
return {
|
|
391
|
+
valid: !1,
|
|
392
|
+
errors: [{ code: s.INVALID_BBOX_LENGTH, path: r }],
|
|
393
|
+
warnings: []
|
|
394
|
+
};
|
|
395
|
+
const t = e.length === 4, c = t ? [e[0], e[1]] : [e[0], e[1], e[2]], o = t ? [e[2], e[3]] : [e[3], e[4], e[5]], l = A(c, `${r}/min`, i);
|
|
396
|
+
if (!l.valid)
|
|
397
|
+
return { valid: !1, errors: l.errors, warnings: [] };
|
|
398
|
+
const E = A(o, `${r}/max`, i);
|
|
399
|
+
if (!E.valid)
|
|
400
|
+
return { valid: !1, errors: E.errors, warnings: [] };
|
|
401
|
+
const [I, u] = c, [f, _] = o;
|
|
402
|
+
if (u > _)
|
|
403
|
+
return {
|
|
404
|
+
valid: !1,
|
|
405
|
+
errors: [{ code: s.INVALID_BBOX_LATITUDE_ORDER, path: r, params: { south: u, north: _ } }],
|
|
406
|
+
warnings: []
|
|
407
|
+
};
|
|
408
|
+
if (!n && I > f)
|
|
409
|
+
return {
|
|
410
|
+
valid: !1,
|
|
411
|
+
errors: [{ code: s.INVALID_BBOX_LONGITUDE_ORDER, path: r, params: { west: I, east: f } }],
|
|
412
|
+
warnings: []
|
|
413
|
+
};
|
|
414
|
+
if (!t) {
|
|
415
|
+
const k = e[2], V = e[5];
|
|
416
|
+
if (k > V)
|
|
417
|
+
return {
|
|
418
|
+
valid: !1,
|
|
419
|
+
errors: [{ code: s.INVALID_BBOX_ALTITUDE_ORDER, path: r, params: { minAlt: k, maxAlt: V } }],
|
|
420
|
+
warnings: []
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
const m = { valid: !0, errors: [], warnings: [] };
|
|
424
|
+
return n && I > f && m.warnings.push({ code: s.BBOX_ANTIMERIDIAN_CROSSING, path: r, params: { west: I, east: f } }), m.warnings.push(...l.warnings), m.warnings.push(...E.warnings), m;
|
|
425
|
+
}
|
|
426
|
+
function M() {
|
|
427
|
+
return { Feature: 0, FeatureCollection: 0, geometries: {} };
|
|
428
|
+
}
|
|
429
|
+
function S() {
|
|
430
|
+
return {
|
|
431
|
+
crs: void 0,
|
|
432
|
+
valid: !0,
|
|
433
|
+
errors: [],
|
|
434
|
+
warnings: [],
|
|
435
|
+
statistics: M()
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
function Z(...e) {
|
|
439
|
+
const r = M();
|
|
440
|
+
for (const i of e) {
|
|
441
|
+
const n = i.statistics;
|
|
442
|
+
if (n) {
|
|
443
|
+
r.Feature += n.Feature ?? 0, r.FeatureCollection += n.FeatureCollection ?? 0;
|
|
444
|
+
for (const [t, c] of Object.entries(n.geometries ?? {}))
|
|
445
|
+
r.geometries[t] = (r.geometries[t] ?? 0) + c;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
return r;
|
|
449
|
+
}
|
|
450
|
+
function O(e, ...r) {
|
|
451
|
+
for (const i of r)
|
|
452
|
+
e.valid = e.valid && (i.valid ?? !0), i.errors && e.errors.push(...i.errors), i.warnings && e.warnings.push(...i.warnings), i.crs !== void 0 && (e.crs = i.crs);
|
|
453
|
+
return e.statistics = Z(e, ...r), e;
|
|
454
|
+
}
|
|
455
|
+
function p(e, r, i = "") {
|
|
456
|
+
const n = {
|
|
457
|
+
valid: !0,
|
|
458
|
+
errors: [],
|
|
459
|
+
warnings: [],
|
|
460
|
+
statistics: M()
|
|
461
|
+
};
|
|
462
|
+
for (let t = 0; t < e.length; t++) {
|
|
463
|
+
const c = `${i}/${t}`, o = r(e[t], c, t);
|
|
464
|
+
o.statistics && (n.statistics = Z(n, o)), o.valid || (n.valid = !1, n.errors = n.errors.concat(o.errors.map((l) => ({ ...l, path: l.path || c, index: t })))), a.empty(o.warnings) || (n.warnings = n.warnings.concat(o.warnings.map((l) => ({ ...l, path: l.path || c, index: t }))));
|
|
465
|
+
}
|
|
466
|
+
return n;
|
|
467
|
+
}
|
|
468
|
+
function W(e, r = 0, i = T) {
|
|
469
|
+
for (let n = r; n < e.length - 1; n++)
|
|
470
|
+
if (fe(e[n], e[n + 1], { precision: i })) return n;
|
|
471
|
+
return -1;
|
|
472
|
+
}
|
|
473
|
+
function J(e, r, i, n = T) {
|
|
474
|
+
let t = W(e, 0, n);
|
|
475
|
+
for (; t !== -1; )
|
|
476
|
+
i.push({ code: s.DUPLICATE_POSITION, path: `${r}/${t}` }), t = W(e, t + 1, n);
|
|
477
|
+
}
|
|
478
|
+
function F(e, r = 0, i = "", n = {}) {
|
|
479
|
+
return a.arrayOfLengthAtLeast(e, r) ? p(e, (t, c) => A(t, c, n), i) : {
|
|
480
|
+
valid: !1,
|
|
481
|
+
errors: [{ code: s.INVALID_COORDINATES_LENGTH, path: i, params: { minimumLength: r } }],
|
|
482
|
+
warnings: []
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
function ee(e, r = "", i = {}) {
|
|
486
|
+
const n = F(e, 2, r, i);
|
|
487
|
+
if (!n.valid) return n;
|
|
488
|
+
if (J(e, r, n.warnings, i.precision ?? T), i.geodesic ?? !0)
|
|
489
|
+
for (let t = 0; t < e.length - 1; t++) {
|
|
490
|
+
const c = e[t][0], o = e[t + 1][0];
|
|
491
|
+
Math.abs(o - c) > 180 && n.warnings.push({ code: s.ANTIMERIDIAN_CROSSING, path: `${r}/${t}` });
|
|
492
|
+
}
|
|
493
|
+
return n;
|
|
494
|
+
}
|
|
495
|
+
function Ge(e, r = "", i = {}) {
|
|
496
|
+
return a.nonEmptyArray(e) ? p(e, (n, t) => ee(n, t, i), r) : {
|
|
497
|
+
valid: !1,
|
|
498
|
+
errors: [{ code: s.INVALID_MULTI_LINESTRING_COORDINATES, path: r }],
|
|
499
|
+
warnings: []
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
function he(e, r, i = "", n = {}) {
|
|
503
|
+
const t = n.precision ?? T, c = n.geodesic ?? !0, o = F(e, 4, i, n);
|
|
504
|
+
if (!o.valid) return o;
|
|
505
|
+
if (!ue(e, { precision: t }))
|
|
506
|
+
return o.valid = !1, o.errors.push({ code: s.RING_NOT_CLOSED, path: i }), o;
|
|
507
|
+
if (J(e, i, o.warnings, t), c) {
|
|
508
|
+
const l = z(e) ? "clockwise" : "counter-clockwise";
|
|
509
|
+
l !== r && (o.valid = !1, o.errors.push({
|
|
510
|
+
code: s.INVALID_WINDING_ORDER,
|
|
511
|
+
path: i,
|
|
512
|
+
params: { expected: r, actual: l }
|
|
513
|
+
}));
|
|
514
|
+
const E = X(e);
|
|
515
|
+
E.length > 0 && (o.valid = !1, o.errors.push({
|
|
516
|
+
code: s.SELF_INTERSECTION,
|
|
517
|
+
path: i,
|
|
518
|
+
params: { count: E.length }
|
|
519
|
+
}));
|
|
520
|
+
}
|
|
521
|
+
return o;
|
|
522
|
+
}
|
|
523
|
+
function re(e, r = "", i = {}) {
|
|
524
|
+
if (!a.nonEmptyArray(e))
|
|
525
|
+
return {
|
|
526
|
+
valid: !1,
|
|
527
|
+
errors: [{ code: s.INVALID_POLYGON_COORDINATES, path: r }],
|
|
528
|
+
warnings: []
|
|
529
|
+
};
|
|
530
|
+
const n = p(e, (t, c, o) => he(t, o === 0 ? "counter-clockwise" : "clockwise", c, i), r);
|
|
531
|
+
if ((i.geodesic ?? !0) && n.valid && e.length > 1) {
|
|
532
|
+
const t = e[0];
|
|
533
|
+
for (let c = 1; c < e.length; c++)
|
|
534
|
+
K(t, e[c]) && (n.valid = !1, n.errors.push({ code: s.HOLE_INTERSECTS_SHELL, path: `${r}/${c}` }));
|
|
535
|
+
}
|
|
536
|
+
return n;
|
|
537
|
+
}
|
|
538
|
+
function we(e, r = "", i = {}) {
|
|
539
|
+
return a.nonEmptyArray(e) ? p(e, (n, t) => re(n, t, i), r) : {
|
|
540
|
+
valid: !1,
|
|
541
|
+
errors: [{ code: s.INVALID_MULTIPOLYGON_COORDINATES, path: r }],
|
|
542
|
+
warnings: []
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
function Ue(e, r = "", i = {}) {
|
|
546
|
+
return a.nonEmptyArray(e) ? p(e, (n, t) => Y(n, t, i), r) : {
|
|
547
|
+
valid: !1,
|
|
548
|
+
errors: [{ code: s.INVALID_GEOMETRYCOLLECTION_GEOMETRIES, path: r }],
|
|
549
|
+
warnings: []
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
function Y(e, r = "", i = {}) {
|
|
553
|
+
let n = S();
|
|
554
|
+
if (!a.nonEmptyObject(e))
|
|
555
|
+
return n.valid = !1, n.errors.push({ code: s.INVALID_GEOMETRY, path: r }), n;
|
|
556
|
+
n = O(n, q(e.crs, `${r}/crs`, i)), n = O(n, Q(e.bbox, `${r}/bbox`, i));
|
|
557
|
+
const t = `${r}/coordinates`;
|
|
558
|
+
switch (e.type) {
|
|
559
|
+
case d.POINT:
|
|
560
|
+
n = O(n, A(e.coordinates, t, i));
|
|
561
|
+
break;
|
|
562
|
+
case d.MULTI_POINT:
|
|
563
|
+
n = O(n, F(e.coordinates, 0, t, i));
|
|
564
|
+
break;
|
|
565
|
+
case d.LINESTRING:
|
|
566
|
+
n = O(n, ee(e.coordinates, t, i));
|
|
567
|
+
break;
|
|
568
|
+
case d.MULTI_LINESTRING:
|
|
569
|
+
n = O(n, Ge(e.coordinates, t, i));
|
|
570
|
+
break;
|
|
571
|
+
case d.POLYGON:
|
|
572
|
+
n = O(n, re(e.coordinates, t, i));
|
|
573
|
+
break;
|
|
574
|
+
case d.MULTI_POLYGON:
|
|
575
|
+
n = O(n, we(e.coordinates, t, i));
|
|
576
|
+
break;
|
|
577
|
+
case d.GEOMETRY_COLLECTION:
|
|
578
|
+
n = O(n, Ue(e.geometries, `${r}/geometries`, i));
|
|
579
|
+
break;
|
|
580
|
+
default:
|
|
581
|
+
return n.valid = !1, n.errors.push({ code: s.INVALID_GEOMETRY_TYPE, path: r, params: { type: e.type } }), n;
|
|
582
|
+
}
|
|
583
|
+
return n.statistics = { Feature: 0, FeatureCollection: 0, geometries: { [e.type]: 1 } }, n;
|
|
584
|
+
}
|
|
585
|
+
const Me = {
|
|
586
|
+
precision: L(a.positiveInteger)
|
|
587
|
+
};
|
|
588
|
+
function ne(e, r, i) {
|
|
589
|
+
let n = S();
|
|
590
|
+
return a.nonEmptyObject(e) ? (n = O(n, q(e.crs, `${r}/crs`, i)), n = O(n, Q(e.bbox, `${r}/bbox`, i)), e.type === N.FEATURE ? (n.statistics.Feature++, a.nonEmptyObject(e.geometry) ? n = O(n, Y(e.geometry, `${r}/geometry`, i)) : n.warnings.push({
|
|
591
|
+
code: s.MISSING_GEOMETRY,
|
|
592
|
+
path: r
|
|
593
|
+
}), n) : (n.statistics.FeatureCollection++, a.nonEmptyArray(e.features) ? n = O(n, p(e.features, (t, c) => ne(t, c, i), `${r}/features`)) : a.array(e.features) || (n.valid = !1, n.errors.push({
|
|
594
|
+
code: s.INVALID_FEATURES_ARRAY,
|
|
595
|
+
path: r
|
|
596
|
+
})), n)) : (n.valid = !1, n.errors.push({
|
|
597
|
+
code: s.EMPTY_OBJECT,
|
|
598
|
+
path: r
|
|
599
|
+
}), n);
|
|
600
|
+
}
|
|
601
|
+
function We(e, r = {}) {
|
|
602
|
+
v.that(r, (n) => C.schema(n, Me), "options must be a valid options object");
|
|
603
|
+
const { precision: i = T } = r;
|
|
604
|
+
return a.plainObject(e) ? a.emptyObject(e) ? {
|
|
605
|
+
...S(),
|
|
606
|
+
valid: !1,
|
|
607
|
+
errors: [{
|
|
608
|
+
code: s.EMPTY_OBJECT,
|
|
609
|
+
path: ""
|
|
610
|
+
}]
|
|
611
|
+
} : e.type === N.FEATURE || e.type === N.FEATURE_COLLECTION ? ne(e, "", { precision: i }) : a.oneOf(e.type, Object.values(d)) ? Y(e, "", { precision: i }) : {
|
|
612
|
+
...S(),
|
|
613
|
+
valid: !1,
|
|
614
|
+
errors: [{
|
|
615
|
+
code: s.UNKNOWN_TYPE,
|
|
616
|
+
path: "",
|
|
617
|
+
params: { type: e.type }
|
|
618
|
+
}]
|
|
619
|
+
} : {
|
|
620
|
+
...S(),
|
|
621
|
+
valid: !1,
|
|
622
|
+
errors: [{
|
|
623
|
+
code: s.INVALID_CONTENT,
|
|
624
|
+
path: ""
|
|
625
|
+
}]
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
export {
|
|
629
|
+
R as C,
|
|
630
|
+
N as F,
|
|
631
|
+
d as G,
|
|
632
|
+
s as V,
|
|
633
|
+
xe as a,
|
|
634
|
+
be as b,
|
|
635
|
+
He as c,
|
|
636
|
+
Oe as d,
|
|
637
|
+
Ne as e,
|
|
638
|
+
$e as f,
|
|
639
|
+
Le as g,
|
|
640
|
+
U as h,
|
|
641
|
+
je as i,
|
|
642
|
+
Ee as j,
|
|
643
|
+
Be as k,
|
|
644
|
+
h as s,
|
|
645
|
+
We as v
|
|
646
|
+
};
|
|
647
|
+
//# sourceMappingURL=geojson-CJ6QZ9pN.js.map
|