UNPKG

well-known-parser

Version:

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

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