well-known-parser
Version:
A WKT/WKB/EWKT/EWKB/TWKB/GeoJSON parser and serializer
3 lines (2 loc) • 1.72 kB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./well-known-parser3.cjs"),s=require("./well-known-parser2.cjs"),h=require("./well-known-parser4.cjs"),i=require("./well-known-parser12.cjs");class n extends r.Geometry{constructor(t,o){super(),this.polygons=t||[],this.srid=o,this.polygons.length>0&&(this.hasZ=this.polygons[0].hasZ,this.hasM=this.polygons[0].hasM)}static Z(t,o){const e=new n(t,o);return e.hasZ=!0,e}static M(t,o){const e=new n(t,o);return e.hasM=!0,e}static ZM(t,o){const e=new n(t,o);return e.hasZ=!0,e.hasM=!0,e}toWkt(){if(this.polygons.length===0)return this.getWktType(s.GEOMETRY_TYPES.MultiPolygon.wkt,!0);let t=this.getWktType(s.GEOMETRY_TYPES.MultiPolygon.wkt,!1)+"(";for(const o of this.polygons)t+=o.toWkt(!0)+",";return t=t.slice(0,-1),t+=")",t}toWkb(t){const o=new i.BinaryWriter(this.getWkbSize());o.writeInt8(1),this.writeWkbType(o,s.GEOMETRY_TYPES.MultiPolygon.wkb,t),o.writeUInt32LE(this.polygons.length);for(const e of this.polygons)o.writeBuffer(e.toWkb({srid:this.srid}));return o.buffer}toTwkb(){const t=new i.BinaryWriter(0,!0),o=r.Geometry.getTwkbPrecision(5,0,0),e=this.polygons.length===0;if(this.writeTwkbHeader(t,s.GEOMETRY_TYPES.MultiPolygon.wkb,o,e),this.polygons.length>0){t.writeVarInt(this.polygons.length);const l=new h.Point(0,0,0,0);for(const g of this.polygons)t.writeBuffer(g.toTwkb(l,!0))}return t.buffer}getWkbSize(){let t=9;for(let o=0;o<this.polygons.length;o++)t+=this.polygons[o].getWkbSize();return t}toGeoJSON(){const t=[];for(const o of this.polygons)t.push(o.toGeoJSON(!0));return{type:s.GEOMETRY_TYPES.MultiPolygon.geoJSON,coordinates:t}}}exports.MultiPolygon=n;
//# sourceMappingURL=well-known-parser9.cjs.map