UNPKG

well-known-parser

Version:

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

3 lines (2 loc) 1.81 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./well-known-parser3.cjs"),s=require("./well-known-parser2.cjs"),h=require("./well-known-parser12.cjs");class o extends n.Geometry{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 r=new o(e,t);return r.hasZ=!0,r}static M(e,t){const r=new o(e,t);return r.hasM=!0,r}static ZM(e,t){const r=new o(e,t);return r.hasZ=!0,r.hasM=!0,r}toWkt(){if(this.geometries.length===0)return this.getWktType(s.GEOMETRY_TYPES.GeometryCollection.wkt,!0);let e=this.getWktType(s.GEOMETRY_TYPES.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.BinaryWriter(this.getWkbSize());t.writeInt8(1),this.writeWkbType(t,s.GEOMETRY_TYPES.GeometryCollection.wkb,e),t.writeUInt32LE(this.geometries.length);for(let r=0;r<this.geometries.length;r++){const i={srid:this.srid};t.writeBuffer(this.geometries[r].toWkb(i))}return t.buffer}toTwkb(){const e=new h.BinaryWriter(0,!0),t=n.Geometry.getTwkbPrecision(5,0,0),r=this.geometries.length===0;if(this.writeTwkbHeader(e,s.GEOMETRY_TYPES.GeometryCollection.wkb,t,r),this.geometries.length>0){e.writeVarInt(this.geometries.length);for(let i=0;i<this.geometries.length;i++)e.writeBuffer(this.geometries[i].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.GEOMETRY_TYPES.GeometryCollection.geoJSON,geometries:e}}}exports.GeometryCollection=o; //# sourceMappingURL=well-known-parser10.cjs.map