well-known-parser
Version:
A WKT/WKB/EWKT/EWKB/TWKB/GeoJSON parser and serializer
3 lines (2 loc) • 2.34 kB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./well-known-parser3.cjs"),h=require("./well-known-parser2.cjs"),w=require("./well-known-parser12.cjs"),f=require("./well-known-parser13.cjs");class o extends c.Geometry{constructor(t,i,e,s,r){super(),this.x=t,this.y=i,this.z=e,this.m=s,this.srid=r,this.hasZ=typeof this.z<"u",this.hasM=typeof this.m<"u"}static Z(t,i,e,s){const r=new o(t,i,e,void 0,s);return r.hasZ=!0,r}static M(t,i,e,s){const r=new o(t,i,void 0,e,s);return r.hasM=!0,r}static ZM(t,i,e,s,r){const n=new o(t,i,e,s,r);return n.hasZ=!0,n.hasM=!0,n}toWkt(t=!1){return t?this.getWktCoordinate():typeof this.x>"u"&&typeof this.y>"u"&&typeof this.z>"u"&&typeof this.m>"u"?this.getWktType(h.GEOMETRY_TYPES.Point.wkt,!0):this.getWktType(h.GEOMETRY_TYPES.Point.wkt,!1)+"("+this.getWktCoordinate()+")"}getWktCoordinate(){let t=`${this.x} ${this.y}`;return this.hasZ&&(t+=` ${this.z}`),this.hasM&&(t+=` ${this.m}`),t}toWkb(t,i=!1){const e=new w.BinaryWriter(this.getWkbSize(i));return i||(e.writeInt8(1),this.writeWkbType(e,h.GEOMETRY_TYPES.Point.wkb,t)),typeof this.x>"u"&&typeof this.y>"u"?(e.writeDoubleLE(NaN),e.writeDoubleLE(NaN),this.hasZ&&e.writeDoubleLE(NaN),this.hasM&&e.writeDoubleLE(NaN)):(e.writeDoubleLE(this.x),e.writeDoubleLE(this.y),this.hasZ&&this.z!==void 0&&e.writeDoubleLE(this.z),this.hasM&&this.m!==void 0&&e.writeDoubleLE(this.m)),e.buffer}toTwkb(t,i=!1){const e=new w.BinaryWriter(0,!0),s=c.Geometry.getTwkbPrecision(5,0,0),r=typeof this.x>"u"&&typeof this.y>"u";if(i||this.writeTwkbHeader(e,h.GEOMETRY_TYPES.Point.wkb,s,r),r)return e.buffer;const n=this.x*s.xyFactor,u=this.y*s.xyFactor,d=this.hasZ?(this.z??0)*s.zFactor:0,y=this.hasM?(this.m??0)*s.mFactor:0;if(e.writeVarInt(f.encode(n-(t?.x??0))),e.writeVarInt(f.encode(u-(t?.y??0))),this.hasZ){const a=t?.z??0;e.writeVarInt(f.encode(d-a))}if(this.hasM){const a=t?.m??0;e.writeVarInt(f.encode(y-a))}return t&&(t.x=n,t.y=u,this.hasZ&&(t.z=d),this.hasM&&(t.m=y)),e.buffer}getWkbSize(t=!1){let i=16;return t||(i+=5),this.hasZ&&(i+=8),this.hasM&&(i+=8),i}toGeoJSON(t=!1){let i;return typeof this.x>"u"&&typeof this.y>"u"?i=[]:typeof this.z<"u"?i=[this.x,this.y,this.z]:i=[this.x,this.y],t?i:{type:h.GEOMETRY_TYPES.Point.geoJSON,coordinates:i}}}exports.Point=o;
//# sourceMappingURL=well-known-parser4.cjs.map