UNPKG

well-known-parser

Version:

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

3 lines (2 loc) 1.68 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./well-known-parser3.cjs"),s=require("./well-known-parser2.cjs"),c=require("./well-known-parser4.cjs"),r=require("./well-known-parser12.cjs");class n extends o.Geometry{constructor(t,i){super(),this.points=t||[],this.srid=i,this.points.length>0&&(this.hasZ=this.points[0].hasZ,this.hasM=this.points[0].hasM)}static Z(t,i){const e=new n(t,i);return e.hasZ=!0,e}static M(t,i){const e=new n(t,i);return e.hasM=!0,e}static ZM(t,i){const e=new n(t,i);return e.hasZ=!0,e.hasM=!0,e}toWkt(){if(this.points.length===0)return this.getWktType(s.GEOMETRY_TYPES.MultiPoint.wkt,!0);let t=this.getWktType(s.GEOMETRY_TYPES.MultiPoint.wkt,!1)+"(";for(const i of this.points)t+=i.toWkt(!0)+",";return t=t.slice(0,-1),t+=")",t}toWkb(t){const i=new r.BinaryWriter(this.getWkbSize());i.writeInt8(1),this.writeWkbType(i,s.GEOMETRY_TYPES.MultiPoint.wkb,t),i.writeUInt32LE(this.points.length);for(const e of this.points)i.writeBuffer(e.toWkb({srid:this.srid}));return i.buffer}toTwkb(){const t=new r.BinaryWriter(0,!0),i=o.Geometry.getTwkbPrecision(5,0,0),e=this.points.length===0;if(this.writeTwkbHeader(t,s.GEOMETRY_TYPES.MultiPoint.wkb,i,e),this.points.length>0){t.writeVarInt(this.points.length);const h=new c.Point(0,0,0,0);for(const u of this.points)t.writeBuffer(u.toTwkb(h,!0))}return t.buffer}getWkbSize(){let t=16;return this.hasZ&&(t+=8),this.hasM&&(t+=8),t+=5,9+this.points.length*t}toGeoJSON(){const t=[];for(const i of this.points)t.push(i.toGeoJSON(!0));return{type:s.GEOMETRY_TYPES.MultiPoint.geoJSON,coordinates:t}}}exports.MultiPoint=n; //# sourceMappingURL=well-known-parser7.cjs.map