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