UNPKG

well-known-parser

Version:

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

62 lines (61 loc) 2.09 kB
import { BinaryWriter as n } from "./well-known-parser12.js"; import { encode as r } from "./well-known-parser13.js"; class M { constructor() { this.srid = void 0, this.hasZ = !1, this.hasM = !1; } toEwkt() { return `SRID=${this.srid};${this.toWkt()}`; } toEwkb() { const t = new n(this.getWkbSize() + 4, !1), i = this.toWkb(); return t.writeInt8(1), t.writeUInt32LE((i.subarray(1, 5).readUInt32LE(0) | 536870912) >>> 0), t.writeUInt32LE(this.srid), t.writeBuffer(i.subarray(5)), t.buffer; } getWktType(t, i) { let e = t; return this.hasZ && this.hasM ? e += " ZM " : this.hasZ ? e += " Z " : this.hasM && (e += " M "), i && !this.hasZ && !this.hasM && (e += " "), i && (e += "EMPTY"), e; } writeWkbType(t, i, e) { let s = 0; typeof this.srid > "u" && (!e || typeof e.srid > "u") ? this.hasZ && this.hasM ? s += 3e3 : this.hasZ ? s += 1e3 : this.hasM && (s += 2e3) : (this.hasZ && (s |= 2147483648), this.hasM && (s |= 1073741824)), t.writeUInt32LE(s + i >>> 0); } static getTwkbPrecision(t, i, e) { return { xy: t, z: i, m: e, xyFactor: Math.pow(10, t), zFactor: Math.pow(10, i), mFactor: Math.pow(10, e) }; } writeTwkbHeader(t, i, e, s) { const a = (r(e.xy) << 4) + i; let o = (this.hasZ || this.hasM ? 1 : 0) << 3; if (o += s ? 16 : 0, t.writeUInt8(a), t.writeUInt8(o), this.hasZ || this.hasM) { let h = 0; this.hasZ && (h |= 1), this.hasM && (h |= 2), this.hasZ && (h |= r(e.z) << 2), this.hasM && (h |= r(e.m) << 5), t.writeUInt8(h); } } toGeoJSON() { throw new Error("Method not implemented."); } // Methods to be implemented by subclasses toWkt() { throw new Error("Method not implemented."); } // eslint-disable-next-line @typescript-eslint/no-unused-vars toWkb(t) { throw new Error("Method not implemented."); } toTwkb() { throw new Error("Method not implemented."); } getWkbSize() { throw new Error("Method not implemented."); } } export { M as Geometry }; //# sourceMappingURL=well-known-parser3.js.map