UNPKG

well-known-parser

Version:

A WKT/WKB/EWKT/EWKB/TWKB/GeoJSON parser and serializer

73 lines (72 loc) 2.36 kB
import { MultiPolygon as a } from "./well-known-parser9.js"; import { Polygon as l } from "./well-known-parser6.js"; import { Point as m } from "./well-known-parser4.js"; import { parsePolygonGeoJSON as y } from "./well-known-parser18.js"; import { parseRelativePointTwkb as d } from "./well-known-parser16.js"; import { parseWkb as M } from "./well-known-parser11.js"; function R(o, r) { const t = new a(); if (t.srid = r.srid, t.hasZ = r.hasZ ?? !1, t.hasM = r.hasM ?? !1, o.isMatch(["EMPTY"])) return t; o.expectGroupStart(); do { o.expectGroupStart(); const s = [], e = []; o.expectGroupStart(); const c = o.matchCoordinates(r); for (const n of c) s.push(n); for (o.expectGroupEnd(); o.isMatch([","]); ) { o.expectGroupStart(); const n = o.matchCoordinates(r), h = []; for (const p of n) h.push(p); e.push(h), o.expectGroupEnd(); } t.polygons.push(new l(s, e)), o.expectGroupEnd(); } while (o.isMatch([","])); return o.expectGroupEnd(), t; } function k(o, r) { const t = new a(); t.srid = r.srid, t.hasZ = r.hasZ ?? !1, t.hasM = r.hasM ?? !1; const s = o.readUInt32(); for (let e = 0; e < s; e++) t.polygons.push(M(o, r)); return t; } function E(o, r) { const t = new a(); if (t.hasZ = r.hasZ ?? !1, t.hasM = r.hasM ?? !1, r.isEmpty) return t; const s = new m(0, 0, r.hasZ ? 0 : void 0, r.hasM ? 0 : void 0), e = o.readVarInt(); for (let c = 0; c < e; c++) { const n = new l(); n.hasZ = r.hasZ ?? !1, n.hasM = r.hasM ?? !1; const h = o.readVarInt(), p = o.readVarInt(); for (let i = 0; i < p; i++) n.exteriorRing.push(d(o, r, s)); for (let i = 1; i < h; i++) { const g = [], u = o.readVarInt(); for (let f = 0; f < u; f++) g.push(d(o, r, s)); n.interiorRings.push(g); } t.polygons.push(n); } return t; } function S(o) { const r = new a(); o.coordinates.length > 0 && o.coordinates[0].length > 0 && o.coordinates[0][0].length > 0 && (r.hasZ = o.coordinates[0][0][0].length > 2); for (let t = 0; t < o.coordinates.length; t++) r.polygons.push(y({ coordinates: o.coordinates[t] })); return r; } export { S as parseMultiPolygonGeoJSON, E as parseMultiPolygonTwkb, k as parseMultiPolygonWkb, R as parseMultiPolygonWkt }; //# sourceMappingURL=well-known-parser21.js.map