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