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 s=require("./well-known-parser3.cjs"),n=require("./well-known-parser2.cjs"),f=require("./well-known-parser4.cjs"),o=require("./well-known-parser12.cjs");class r extends s.Geometry{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.GEOMETRY_TYPES.LineString.wkt,!0):this.getWktType(n.GEOMETRY_TYPES.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.BinaryWriter(this.getWkbSize());e.writeInt8(1),this.writeWkbType(e,n.GEOMETRY_TYPES.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 f.Point(0,0,0,0),e=!1){const i=new o.BinaryWriter(0,!0),h=s.Geometry.getTwkbPrecision(5,0,0),u=this.points.length===0;if(e||this.writeTwkbHeader(i,n.GEOMETRY_TYPES.LineString.wkb,h,u),this.points.length>0){i.writeVarInt(this.points.length);for(const c of this.points)i.writeBuffer(c.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.GEOMETRY_TYPES.LineString.geoJSON,coordinates:e}}}exports.LineString=r;
//# sourceMappingURL=well-known-parser5.cjs.map