UNPKG

well-known-parser

Version:

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

66 lines (65 loc) 2.01 kB
import { Geometry as r } from "./well-known-parser3.js"; import { GEOMETRY_TYPES as e } from "./well-known-parser2.js"; import { Point as g } from "./well-known-parser4.js"; import { BinaryWriter as i } from "./well-known-parser12.js"; class n extends r { constructor(t, o) { super(), this.polygons = t || [], this.srid = o, this.polygons.length > 0 && (this.hasZ = this.polygons[0].hasZ, this.hasM = this.polygons[0].hasM); } static Z(t, o) { const s = new n(t, o); return s.hasZ = !0, s; } static M(t, o) { const s = new n(t, o); return s.hasM = !0, s; } static ZM(t, o) { const s = new n(t, o); return s.hasZ = !0, s.hasM = !0, s; } toWkt() { if (this.polygons.length === 0) return this.getWktType(e.MultiPolygon.wkt, !0); let t = this.getWktType(e.MultiPolygon.wkt, !1) + "("; for (const o of this.polygons) t += o.toWkt(!0) + ","; return t = t.slice(0, -1), t += ")", t; } toWkb(t) { const o = new i(this.getWkbSize()); o.writeInt8(1), this.writeWkbType(o, e.MultiPolygon.wkb, t), o.writeUInt32LE(this.polygons.length); for (const s of this.polygons) o.writeBuffer(s.toWkb({ srid: this.srid })); return o.buffer; } toTwkb() { const t = new i(0, !0), o = r.getTwkbPrecision(5, 0, 0), s = this.polygons.length === 0; if (this.writeTwkbHeader(t, e.MultiPolygon.wkb, o, s), this.polygons.length > 0) { t.writeVarInt(this.polygons.length); const l = new g(0, 0, 0, 0); for (const h of this.polygons) t.writeBuffer(h.toTwkb(l, !0)); } return t.buffer; } getWkbSize() { let t = 9; for (let o = 0; o < this.polygons.length; o++) t += this.polygons[o].getWkbSize(); return t; } toGeoJSON() { const t = []; for (const o of this.polygons) t.push(o.toGeoJSON(!0)); return { type: e.MultiPolygon.geoJSON, coordinates: t }; } } export { n as MultiPolygon }; //# sourceMappingURL=well-known-parser9.js.map