@loaders.gl/wkt 4.2.0-alpha.4 → 4.2.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +137 -218
- package/dist/dist.min.js +10 -0
- package/dist/hex-wkb-loader.d.ts +1 -1
- package/dist/hex-wkb-loader.d.ts.map +1 -1
- package/dist/hex-wkb-loader.js +44 -28
- package/dist/index.cjs +87 -62
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +14 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/lib/encode-twkb.js +158 -143
- package/dist/lib/encode-wkb.js +247 -211
- package/dist/lib/encode-wkt-crs.d.ts +1 -1
- package/dist/lib/encode-wkt-crs.d.ts.map +1 -1
- package/dist/lib/encode-wkt-crs.js +32 -18
- package/dist/lib/encode-wkt.js +35 -27
- package/dist/lib/parse-hex-wkb.js +1 -2
- package/dist/lib/parse-twkb.js +215 -218
- package/dist/lib/parse-wkb-header.js +124 -95
- package/dist/lib/parse-wkb.d.ts +1 -1
- package/dist/lib/parse-wkb.d.ts.map +1 -1
- package/dist/lib/parse-wkb.js +210 -235
- package/dist/lib/parse-wkt-crs.js +110 -86
- package/dist/lib/parse-wkt.js +251 -185
- package/dist/lib/utils/base64-encoder.js +151 -5
- package/dist/lib/utils/binary-reader.js +67 -64
- package/dist/lib/utils/binary-writer.js +117 -109
- package/dist/lib/utils/hex-encoder.js +46 -32
- package/dist/lib/utils/hex-transcoder.js +40 -24
- package/dist/lib/utils/version.js +7 -2
- package/dist/twkb-loader.js +26 -17
- package/dist/twkb-writer.js +18 -13
- package/dist/wkb-loader.js +26 -17
- package/dist/wkb-writer.js +22 -17
- package/dist/wkt-crs-loader.d.ts +1 -1
- package/dist/wkt-crs-loader.d.ts.map +1 -1
- package/dist/wkt-crs-loader.js +22 -15
- package/dist/wkt-crs-writer.d.ts +2 -2
- package/dist/wkt-crs-writer.d.ts.map +1 -1
- package/dist/wkt-crs-writer.js +23 -15
- package/dist/wkt-loader.js +28 -20
- package/dist/wkt-worker.js +4 -2
- package/dist/wkt-writer.js +19 -14
- package/dist/workers/wkb-worker.js +3 -1
- package/dist/workers/wkt-worker.js +3 -1
- package/package.json +11 -6
- package/src/lib/parse-wkb.ts +2 -2
- package/dist/hex-wkb-loader.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/encode-twkb.js.map +0 -1
- package/dist/lib/encode-wkb.js.map +0 -1
- package/dist/lib/encode-wkt-crs.js.map +0 -1
- package/dist/lib/encode-wkt.js.map +0 -1
- package/dist/lib/parse-hex-wkb.js.map +0 -1
- package/dist/lib/parse-twkb.js.map +0 -1
- package/dist/lib/parse-wkb-header.js.map +0 -1
- package/dist/lib/parse-wkb.js.map +0 -1
- package/dist/lib/parse-wkt-crs.js.map +0 -1
- package/dist/lib/parse-wkt.js.map +0 -1
- package/dist/lib/utils/base64-encoder.js.map +0 -1
- package/dist/lib/utils/binary-reader.js.map +0 -1
- package/dist/lib/utils/binary-writer.js.map +0 -1
- package/dist/lib/utils/hex-encoder.js.map +0 -1
- package/dist/lib/utils/hex-transcoder.js.map +0 -1
- package/dist/lib/utils/version.js.map +0 -1
- package/dist/twkb-loader.js.map +0 -1
- package/dist/twkb-writer.js.map +0 -1
- package/dist/wkb-loader.js.map +0 -1
- package/dist/wkb-writer.js.map +0 -1
- package/dist/wkt-crs-loader.js.map +0 -1
- package/dist/wkt-crs-writer.js.map +0 -1
- package/dist/wkt-loader.js.map +0 -1
- package/dist/wkt-writer.js.map +0 -1
- package/dist/workers/wkb-worker.js.map +0 -1
- package/dist/workers/wkt-worker.js.map +0 -1
package/dist/dist.min.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
|
+
if (typeof exports === 'object' && typeof module === 'object')
|
|
3
|
+
module.exports = factory();
|
|
4
|
+
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
|
+
else if (typeof exports === 'object') exports['loaders'] = factory();
|
|
6
|
+
else root['loaders'] = factory();})(globalThis, function () {
|
|
7
|
+
"use strict";var __exports__=(()=>{var _e=Object.create;var K=Object.defineProperty;var $e=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var Ze=Object.getPrototypeOf,je=Object.prototype.hasOwnProperty;var He=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Je=(e,t)=>{for(var n in t)K(e,n,{get:t[n],enumerable:!0})},U=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of De(t))!je.call(e,o)&&o!==n&&K(e,o,{get:()=>t[o],enumerable:!(r=$e(t,o))||r.enumerable});return e},A=(e,t,n)=>(U(e,t,"default"),n&&U(n,t,"default")),Ye=(e,t,n)=>(n=e!=null?_e(Ze(e)):{},U(t||!e||!e.__esModule?K(n,"default",{value:e,enumerable:!0}):n,e)),Xe=e=>U(K({},"__esModule",{value:!0}),e);var le=He((_t,ae)=>{ae.exports=globalThis.loaders});var k={};Je(k,{HexWKBLoader:()=>ve,TWKBLoader:()=>Fe,TWKBWriter:()=>Ne,WKBLoader:()=>O,WKBWorkerLoader:()=>oe,WKBWriter:()=>Ke,WKTCRSLoader:()=>ye,WKTCRSWriter:()=>pe,WKTLoader:()=>we,WKTWorkerLoader:()=>q,WKTWriter:()=>be,decodeHex:()=>j,encodeHex:()=>Ve,isTWKB:()=>H,isWKB:()=>F,isWKT:()=>G,parseWKBHeader:()=>R});A(k,Ye(le(),1));var p="4.2.0-alpha.5";function J(e,t){t?.debug&&console.log(`[wktcrs] parse starting with
|
|
8
|
+
`,e),e=e.replace(/[A-Z][A-Z\d_]+\[/gi,i=>`["${i.substr(0,i.length-1)}",`),e=e.replace(/, ?([A-Z][A-Z\d_]+[,\]])/gi,(i,s)=>{let c=s.substr(0,s.length-1);return`,"${t?.raw?"raw:":""}${c}"${s[s.length-1]}`}),t?.raw&&(e=e.replace(/, {0,2}(-?[\.\d]+)(?=,|\])/g,function(i,s){return`,"${t?.raw?"raw:":""}${s}"`})),t?.debug&&console.log(`[wktcrs] json'd wkt: '${e}'`);let n;try{n=JSON.parse(e)}catch(i){throw console.error(`[wktcrs] failed to parse '${e}'`),i}t?.debug&&console.log(`[wktcrs] json parsed: '${e}'`);function r(i,s){let c=i[0];i.forEach(function(a){Array.isArray(a)&&r(a,i)});let u=`MULTIPLE_${c}`;return u in s?s[u].push(i):c in s?(s[u]=[s[c],i],delete s[c]):s[c]=i,s}let o=r(n,[n]);return t?.debug&&console.log("[wktcrs] parse returning",o),t?.sort&&fe(o,t),o}function fe(e,t){let n=Object.keys(e).filter(o=>!/\d+/.test(o)),r=t?.keywords||[];if(!t?.keywords){let o={};if(Array.isArray(e)){e.forEach(i=>{if(Array.isArray(i)&&i.length>=2&&typeof i[1]=="string"){let s=i[0];o[s]||(o[s]=0),o[s]++}});for(let i in o)o[i]>0&&r.push(i)}}return n.forEach(o=>{e[o]=fe(e[o])}),r.forEach(o=>{let i=[],s=[];e.forEach((c,u)=>{Array.isArray(c)&&c[0]===o&&(i.push(u),s.push(c))}),s.sort((c,u)=>(c=c[1].toString(),u=u[1].toString(),c<u?-1:c>u?1:0)),s.forEach((c,u)=>{e[i[u]]=c})}),e}var ye={name:"WKT CRS (Well-Known Text Coordinate Reference System)",id:"wkt-crs",module:"wkt-crs",version:p,worker:!0,extensions:[],mimeTypes:["text/plain"],category:"json",text:!0,options:{"wkt-crs":{}},parse:async(e,t)=>J(new TextDecoder().decode(e),t?.["wkt-crs"]),parseTextSync:(e,t)=>J(e,t?.["wkt-crs"])};function M(e,t){Array.isArray(e)&&e.length===1&&Array.isArray(e[0])&&(e=e[0]);let[n,...r]=e;return`${n}[${r.map(i=>{if(Array.isArray(i))return M(i,t);if(typeof i=="number")return i.toString();if(typeof i=="string")return i.startsWith("raw:")?i.replace("raw:",""):`"${i}"`;throw new Error(`[wktcrs] unexpected attribute "${i}"`)}).join(",")}]`}var pe={name:"WKT CRS (Well-Known Text Coordinate Reference System)",id:"wkt-crs",module:"wkt-crs",version:p,worker:!0,extensions:[],mimeTypes:["text/plain"],text:!0,options:{"wkt-crs":{}},encode:async(e,t)=>new TextEncoder().encode(M(e,t?.["wkt-crs"])),encodeSync:(e,t)=>new TextEncoder().encode(M(e,t?.["wkt-crs"])),encodeTextSync:(e,t)=>M(e,t?.["wkt-crs"])};var ge=/[-+]?([0-9]*\.[0-9]+|[0-9]+)([eE][-+]?[0-9]+)?/,he=new RegExp("^"+ge.source+"(\\s"+ge.source+"){1,}"),Y=["POINT(","LINESTRING(","POLYGON(","MULTIPOINT(","MULTILINESTRING(","MULTIPOLYGON(","GEOMETRYCOLLECTION("];function G(e){return Y.some(t=>e.startsWith(t))}function X(e,t){return qe(e,t)}function qe(e,t){let n=e.split(";"),r=n.pop(),o=(n.shift()||"").split("=").pop(),s=de({parts:n,_:r,i:0});return t?.wkt?.crs?Qe(s,o):s}function de(e){return et(e)||nt(e)||ot(e)||tt(e)||rt(e)||it(e)||st(e)}function Qe(e,t){if(e&&t?.match(/\d+/)){let n={type:"name",properties:{name:"urn:ogc:def:crs:EPSG::"+t}};e.crs=n}return e}function et(e){if(!f(/^(POINT(\sz)?)/i,e)||(g(e),!f(/^(\()/,e)))return null;let t=me(e);return!t||(g(e),!f(/^(\))/,e))?null:{type:"Point",coordinates:t[0]}}function tt(e){if(!f(/^(MULTIPOINT)/i,e))return null;g(e);let t=e._?.substring(e._?.indexOf("(")+1,e._.length-1).replace(/\(/g,"").replace(/\)/g,"");e._="MULTIPOINT ("+t+")";let n=V(e);return n?(g(e),{type:"MultiPoint",coordinates:n}):null}function nt(e){if(!f(/^(LINESTRING(\sz)?)/i,e)||(g(e),!f(/^(\()/,e)))return null;let t=me(e);return!t||!f(/^(\))/,e)?null:{type:"LineString",coordinates:t}}function rt(e){if(!f(/^(MULTILINESTRING)/i,e))return null;g(e);let t=V(e);return t?(g(e),{type:"MultiLineString",coordinates:t}):null}function ot(e){if(!f(/^(POLYGON(\sz)?)/i,e))return null;g(e);let t=V(e);return t?{type:"Polygon",coordinates:t}:null}function it(e){if(!f(/^(MULTIPOLYGON)/i,e))return null;g(e);let t=V(e);return t?{type:"MultiPolygon",coordinates:t}:null}function st(e){let t=[],n;if(!f(/^(GEOMETRYCOLLECTION)/i,e)||(g(e),!f(/^(\()/,e)))return null;for(;n=de(e);)t.push(n),g(e),f(/^(,)/,e),g(e);return f(/^(\))/,e)?{type:"GeometryCollection",geometries:t}:null}function V(e){g(e);let t=0,n=[],r=[n],o=n,i;for(;i=f(/^(\()/,e)||f(/^(\))/,e)||f(/^(,)/,e)||f(he,e);){if(i==="(")r.push(o),o=[],r[r.length-1].push(o),t++;else if(i===")"){if(o.length===0||(o=r.pop(),!o))return null;if(t--,t===0)break}else if(i===",")o=[],r[r.length-1].push(o);else if(!i.split(/\s/g).some(isNaN))Array.prototype.push.apply(o,i.split(/\s/g).map(parseFloat));else return null;g(e)}return t!==0?null:n}function me(e){let t=[],n,r;for(;r=f(he,e)||f(/^(,)/,e);)r===","?(t.push(n),n=[]):r.split(/\s/g).some(isNaN)||(n||(n=[]),Array.prototype.push.apply(n,r.split(/\s/g).map(parseFloat))),g(e);if(n)t.push(n);else return null;return t.length?t:null}function f(e,t){let n=t._?.substring(t.i).match(e);return n?(t.i+=n[0].length,n[0]):null}function g(e){f(/^\s*/,e)}var q={name:"WKT (Well-Known Text)",id:"wkt",module:"wkt",version:p,worker:!0,extensions:["wkt"],mimeTypes:["text/plain"],category:"geometry",text:!0,tests:Y,testText:G,options:{wkt:{shape:"geojson-geometry",crs:!0}}},we={...q,parse:async(e,t)=>X(new TextDecoder().decode(e),t),parseTextSync:X};function z(e){switch(e.type==="Feature"&&(e=e.geometry),e.type){case"Point":return`POINT ${I(Ie(e.coordinates))}`;case"LineString":return`LINESTRING ${I(Q(e.coordinates))}`;case"Polygon":return`POLYGON ${I(ee(e.coordinates))}`;case"MultiPoint":return`MULTIPOINT ${I(Q(e.coordinates))}`;case"MultiPolygon":return`MULTIPOLYGON ${I(ct(e.coordinates))}`;case"MultiLineString":return`MULTILINESTRING ${I(ee(e.coordinates))}`;case"GeometryCollection":return`GEOMETRYCOLLECTION ${I(e.geometries.map(z).join(", "))}`;default:throw new Error("stringify requires a valid GeoJSON Feature or geometry object as input")}}function Ie(e){return e.join(" ")}function Q(e){return e.map(Ie).join(", ")}function ee(e){return e.map(Q).map(I).join(", ")}function ct(e){return e.map(ee).map(I).join(", ")}function I(e){return`(${e})`}var be={name:"WKT (Well Known Text)",id:"wkt",module:"wkt",version:p,extensions:["wkt"],text:!0,encode:async e=>Pe(e),encodeSync:Pe,encodeTextSync:z,options:{wkt:{}}};function Pe(e){return new TextEncoder().encode(z(e)).buffer}function C(e,t,n){switch(e.type){case"Point":return at(e,t,n);case"LineString":return ut(e,t,n);case"Polygon":return Se(e,t,n);default:let r=e;throw new Error(`Unsupported geometry type: ${r?.type}`)}}function Se(e,t=-1/0,n=1/0){let{positions:r}=e,o=e.polygonIndices.value.filter(u=>u>=t&&u<=n),i=e.primitivePolygonIndices.value.filter(u=>u>=t&&u<=n);if(!(o.length>2)){let u=[];for(let a=0;a<i.length-1;a++){let y=i[a],h=i[a+1],m=v(r,y,h);u.push(m)}return{type:"Polygon",coordinates:u}}let c=[];for(let u=0;u<o.length-1;u++){let a=o[u],y=o[u+1],h=Se(e,a,y).coordinates;c.push(h)}return{type:"MultiPolygon",coordinates:c}}function ut(e,t=-1/0,n=1/0){let{positions:r}=e,o=e.pathIndices.value.filter(c=>c>=t&&c<=n);if(!(o.length>2))return{type:"LineString",coordinates:v(r,o[0],o[1])};let s=[];for(let c=0;c<o.length-1;c++){let u=v(r,o[c],o[c+1]);s.push(u)}return{type:"MultiLineString",coordinates:s}}function at(e,t,n){let{positions:r}=e,o=v(r,t,n);return o.length>1?{type:"MultiPoint",coordinates:o}:{type:"Point",coordinates:o[0]}}function v(e,t,n){t=t||0,n=n||e.value.length/e.size;let r=[];for(let o=t;o<n;o++){let i=Array();for(let s=o*e.size;s<(o+1)*e.size;s++)i.push(Number(e.value[s]));r.push(i)}return r}var l;(function(e){e[e.Point=1]="Point",e[e.LineString=2]="LineString",e[e.Polygon=3]="Polygon",e[e.MultiPoint=4]="MultiPoint",e[e.MultiLineString=5]="MultiLineString",e[e.MultiPolygon=6]="MultiPolygon",e[e.GeometryCollection=7]="GeometryCollection"})(l||(l={}));function F(e){let t=new DataView(e),n=0,r=t.getUint8(n);if(n+=1,r>1)return!1;let o=r===1,i=t.getUint32(n,o);n+=4;let s=i&7;if(s===0||s>7)return!1;let c=i-s;if(c===0||c===1e3||c===2e3||c===3e3)return!0;if(c&536870911)return!1;if(c&536870912){let u=t.getUint32(n,o);if(n+=4,u>1e4)return!1}return!0}function R(e,t){let n=Object.assign(t||{},{type:"wkb",geometryType:1,dimensions:2,coordinates:"xy",littleEndian:!0,byteOffset:0});n.littleEndian=e.getUint8(n.byteOffset)===1,n.byteOffset++;let r=e.getUint32(n.byteOffset,n.littleEndian);n.byteOffset+=4,n.geometryType=r&7;let o=(r-n.geometryType)/1e3;switch(o){case 0:break;case 1:n.type="iso-wkb",n.dimensions=3,n.coordinates="xyz";break;case 2:n.type="iso-wkb",n.dimensions=3,n.coordinates="xym";break;case 3:n.type="iso-wkb",n.dimensions=4,n.coordinates="xyzm";break;default:throw new Error(`WKB: Unsupported iso-wkb type: ${o}`)}let i=r&2147483648,s=r&1073741824,c=r&536870912;return i&&s?(n.type="ewkb",n.dimensions=4,n.coordinates="xyzm"):i?(n.type="ewkb",n.dimensions=3,n.coordinates="xyz"):s&&(n.type="ewkb",n.dimensions=3,n.coordinates="xym"),c&&(n.type="ewkb",n.srid=e.getUint32(n.byteOffset,n.littleEndian),n.byteOffset+=4),n}function te(e,t){let n=lt(e,t),r=t?.wkb?.shape||"binary-geometry";switch(r){case"binary-geometry":return n;case"geojson-geometry":return C(n);case"geometry":return console.error('WKBLoader: "geometry" shape is deprecated, use "binary-geometry" instead'),C(n);default:throw new Error(r)}}function lt(e,t){let n=new DataView(e),r=R(n),{geometryType:o,dimensions:i,littleEndian:s}=r,c=r.byteOffset;switch(o){case l.Point:return Le(n,c,i,s).geometry;case l.LineString:return ne(n,c,i,s).geometry;case l.Polygon:return Ee(n,c,i,s).geometry;case l.MultiPoint:let h=ft(n,c,i,s);return h.type="Point",h;case l.MultiLineString:let m=yt(n,c,i,s);return m.type="LineString",m;case l.MultiPolygon:let T=pt(n,c,i,s);return T.type="Polygon",T;default:throw new Error(`WKB: Unsupported geometry type: ${o}`)}}function Le(e,t,n,r){let o=new Float64Array(n);for(let i=0;i<n;i++)o[i]=e.getFloat64(t,r),t+=8;return{geometry:{type:"Point",positions:{value:o,size:n}},offset:t}}function ne(e,t,n,r){let o=e.getUint32(t,r);t+=4;let i=new Float64Array(o*n);for(let c=0;c<o*n;c++)i[c]=e.getFloat64(t,r),t+=8;let s=[0];return o>0&&s.push(o),{geometry:{type:"LineString",positions:{value:i,size:n},pathIndices:{value:new Uint16Array(s),size:1}},offset:t}}var re=e=>t=>e+=t;function Ee(e,t,n,r){let o=e.getUint32(t,r);t+=4;let i=[];for(let a=0;a<o;a++){let y=ne(e,t,n,r),{positions:h}=y.geometry;t=y.offset,i.push(h.value)}let s=new Float64Array(N(i).buffer),c=[0];s.length>0&&c.push(s.length/n);let u=i.map(a=>a.length/n).map(re(0));return u.unshift(0),{geometry:{type:"Polygon",positions:{value:s,size:n},polygonIndices:{value:new Uint16Array(c),size:1},primitivePolygonIndices:{value:new Uint16Array(u),size:1}},offset:t}}function ft(e,t,n,r){let o=e.getUint32(t,r);t+=4;let i=[];for(let s=0;s<o;s++){let c=e.getUint8(t)===1;if(t++,e.getUint32(t,c)%1e3!==1)throw new Error("WKB: Inner geometries of MultiPoint not of type Point");t+=4;let u=Le(e,t,n,c);t=u.offset,i.push(u.geometry)}return gt(i,n)}function yt(e,t,n,r){let o=e.getUint32(t,r);t+=4;let i=[];for(let s=0;s<o;s++){let c=e.getUint8(t)===1;if(t++,e.getUint32(t,c)%1e3!==2)throw new Error("WKB: Inner geometries of MultiLineString not of type LineString");t+=4;let u=ne(e,t,n,c);t=u.offset,i.push(u.geometry)}return ht(i,n)}function pt(e,t,n,r){let o=e.getUint32(t,r);t+=4;let i=[];for(let s=0;s<o;s++){let c=e.getUint8(t)===1;if(t++,e.getUint32(t,c)%1e3!==3)throw new Error("WKB: Inner geometries of MultiPolygon not of type Polygon");t+=4;let u=Ee(e,t,n,c);t=u.offset,i.push(u.geometry)}return dt(i,n)}function gt(e,t){let n=e.map(o=>o.positions.value);return{type:"Point",positions:{value:new Float64Array(N(n).buffer),size:t}}}function ht(e,t){let n=e.map(i=>i.positions.value),r=new Float64Array(N(n).buffer),o=n.map(i=>i.length/t).map(re(0));return o.unshift(0),{type:"LineString",positions:{value:r,size:t},pathIndices:{value:new Uint16Array(o),size:1}}}function dt(e,t){let n=[],r=[];for(let c of e){let{positions:u,primitivePolygonIndices:a}=c;n.push(u.value),r.push(a.value)}let o=new Float64Array(N(n).buffer),i=n.map(c=>c.length/t).map(re(0));i.unshift(0);let s=[0];for(let c of r)s.push(...c.filter(u=>u>0).map(u=>u+s[s.length-1]));return{type:"Polygon",positions:{value:o,size:t},polygonIndices:{value:new Uint32Array(i),size:1},primitivePolygonIndices:{value:new Uint32Array(s),size:1}}}function N(e){let t=0;for(let o=0;o<e.length;++o)t+=e[o].byteLength;let n=new Uint8Array(t),r=0;for(let o=0;o<e.length;++o){let i=new Uint8Array(e[o].buffer);t=i.length;for(let s=0;s<t;++s)n[r++]=i[s]}return n}var oe={name:"WKB",id:"wkb",module:"wkt",version:p,worker:!0,category:"geometry",extensions:["wkb"],mimeTypes:[],tests:[F],options:{wkb:{shape:"binary-geometry"}}},O={...oe,parse:async e=>te(e),parseSync:te};var d=class{arrayBuffer;dataView;byteOffset=0;allowResize=!1;constructor(t,n){this.arrayBuffer=new ArrayBuffer(t),this.dataView=new DataView(this.arrayBuffer),this.byteOffset=0,this.allowResize=n||!1}writeUInt8(t){this._ensureSize(1),this.dataView.setUint8(this.byteOffset,t),this.byteOffset+=1}writeUInt16LE(t){this._ensureSize(2),this.dataView.setUint16(this.byteOffset,t,!0),this.byteOffset+=2}writeUInt16BE(t){this._ensureSize(2),this.dataView.setUint16(this.byteOffset,t,!1),this.byteOffset+=2}writeUInt32LE(t){this._ensureSize(4),this.dataView.setUint32(this.byteOffset,t,!0),this.byteOffset+=4}writeUInt32BE(t){this._ensureSize(4),this.dataView.setUint32(this.byteOffset,t,!1),this.byteOffset+=4}writeInt8(t){this._ensureSize(1),this.dataView.setInt8(this.byteOffset,t),this.byteOffset+=1}writeInt16LE(t){this._ensureSize(2),this.dataView.setInt16(this.byteOffset,t,!0),this.byteOffset+=2}writeInt16BE(t){this._ensureSize(2),this.dataView.setInt16(this.byteOffset,t,!1),this.byteOffset+=2}writeInt32LE(t){this._ensureSize(4),this.dataView.setInt32(this.byteOffset,t,!0),this.byteOffset+=4}writeInt32BE(t){this._ensureSize(4),this.dataView.setInt32(this.byteOffset,t,!1),this.byteOffset+=4}writeFloatLE(t){this._ensureSize(4),this.dataView.setFloat32(this.byteOffset,t,!0),this.byteOffset+=4}writeFloatBE(t){this._ensureSize(4),this.dataView.setFloat32(this.byteOffset,t,!1),this.byteOffset+=4}writeDoubleLE(t){this._ensureSize(8),this.dataView.setFloat64(this.byteOffset,t,!0),this.byteOffset+=8}writeDoubleBE(t){this._ensureSize(8),this.dataView.setFloat64(this.byteOffset,t,!1),this.byteOffset+=8}writeVarInt(t){let n=1;for(;t&4294967168;)this.writeUInt8(t&127|128),t>>>=7,n++;return this.writeUInt8(t&127),n}writeBuffer(t){this._ensureSize(t.byteLength),new Uint8Array(this.arrayBuffer).set(new Uint8Array(t),this.byteOffset),this.byteOffset+=t.byteLength}_ensureSize(t){if(this.arrayBuffer.byteLength<this.byteOffset+t)if(this.allowResize){let n=new ArrayBuffer(this.byteOffset+t);new Uint8Array(n).set(new Uint8Array(this.arrayBuffer)),this.arrayBuffer=n}else throw new Error("BinaryWriter overflow")}};var P;(function(e){e[e.Point=1]="Point",e[e.LineString=2]="LineString",e[e.Polygon=3]="Polygon",e[e.MultiPoint=4]="MultiPoint",e[e.MultiLineString=5]="MultiLineString",e[e.MultiPolygon=6]="MultiPolygon",e[e.GeometryCollection=7]="GeometryCollection"})(P||(P={}));function $(e,t={}){switch(e.type==="Feature"&&(e=e.geometry),e.type){case"Point":return Te(e.coordinates,t);case"LineString":return Oe(e.coordinates,t);case"Polygon":return xe(e.coordinates,t);case"MultiPoint":return wt(e,t);case"MultiPolygon":return Pt(e,t);case"MultiLineString":return It(e,t);case"GeometryCollection":return bt(e,t);default:let n=e;throw new Error(`Unhandled case: ${n}`)}}function mt(e,t){switch(e.type){case"Point":return Me(t);case"LineString":return ie(e.coordinates,t);case"Polygon":return se(e.coordinates,t);case"MultiPoint":return Be(e,t);case"MultiPolygon":return ke(e,t);case"MultiLineString":return We(e,t);case"GeometryCollection":return Ue(e,t);default:let n=e;throw new Error(`Unhandled case: ${n}`)}}function Te(e,t){let n=new d(Me(t));return n.writeInt8(1),b(n,P.Point,t),typeof e[0]>"u"&&typeof e[1]>"u"?(n.writeDoubleLE(NaN),n.writeDoubleLE(NaN),t.hasZ&&n.writeDoubleLE(NaN),t.hasM&&n.writeDoubleLE(NaN)):_(n,e,t),n.arrayBuffer}function _(e,t,n){e.writeDoubleLE(t[0]),e.writeDoubleLE(t[1]),n.hasZ&&e.writeDoubleLE(t[2]),n.hasM&&e.writeDoubleLE(t[3])}function Me(e){let t=D(e);return 1+4+t}function Oe(e,t){let n=ie(e,t),r=new d(n);r.writeInt8(1),b(r,P.LineString,t),r.writeUInt32LE(e.length);for(let o of e)_(r,o,t);return r.arrayBuffer}function ie(e,t){let n=D(t);return 1+4+4+e.length*n}function xe(e,t){let n=new d(se(e,t));n.writeInt8(1),b(n,P.Polygon,t);let[r,...o]=e;r.length>0?(n.writeUInt32LE(1+o.length),n.writeUInt32LE(r.length)):n.writeUInt32LE(0);for(let i of r)_(n,i,t);for(let i of o){n.writeUInt32LE(i.length);for(let s of i)_(n,s,t)}return n.arrayBuffer}function se(e,t){let n=D(t),[r,...o]=e,i=1+4+4;r.length>0&&(i+=4+r.length*n);for(let s of o)i+=4+s.length*n;return i}function wt(e,t){let n=new d(Be(e,t)),r=e.coordinates;n.writeInt8(1),b(n,P.MultiPoint,t),n.writeUInt32LE(r.length);for(let o of r){let i=Te(o,t);n.writeBuffer(i)}return n.arrayBuffer}function Be(e,t){let n=D(t),r=e.coordinates;return n+=5,1+4+4+r.length*n}function It(e,t){let n=new d(We(e,t)),r=e.coordinates;n.writeInt8(1),b(n,P.MultiLineString,t),n.writeUInt32LE(r.length);for(let o of r){let i=Oe(o,t);n.writeBuffer(i)}return n.arrayBuffer}function We(e,t){let n=9,r=e.coordinates;for(let o of r)n+=ie(o,t);return n}function Pt(e,t){let n=new d(ke(e,t)),r=e.coordinates;n.writeInt8(1),b(n,P.MultiPolygon,t),n.writeUInt32LE(r.length);for(let o of r){let i=xe(o,t);n.writeBuffer(i)}return n.arrayBuffer}function ke(e,t){let n=9,r=e.coordinates;for(let o of r)n+=se(o,t);return n}function bt(e,t){let n=new d(Ue(e,t));n.writeInt8(1),b(n,P.GeometryCollection,t),n.writeUInt32LE(e.geometries.length);for(let r of e.geometries){let o=$(r,t);n.writeBuffer(o)}return n.arrayBuffer}function Ue(e,t){let n=9;for(let r of e.geometries)n+=mt(r,t);return n}function b(e,t,n){let{hasZ:r,hasM:o,srid:i}=n,s=0;i?(r&&(s|=2147483648),o&&(s|=1073741824)):r&&o?s+=3e3:r?s+=1e3:o&&(s+=2e3),e.writeUInt32LE(s+t>>>0)}function D(e){let t=16;return e.hasZ&&(t+=8),e.hasM&&(t+=8),t}var Ke={name:"WKB (Well Known Binary)",id:"wkb",module:"wkt",version:p,extensions:["wkb"],options:{wkb:{hasZ:!1,hasM:!1}},async encode(e,t){return $(e,t?.wkb)},encodeSync(e,t){return $(e,t?.wkb)}};var Ae="0123456789abcdef",Ge=[],Z=[];for(let e=0;e<256;e++)Ge[e]=Ae[e>>4&15]+Ae[e&15],e<16&&(e<10?Z[48+e]=e:Z[97-10+e]=e);function Ve(e){let t=e.length,n="",r=0;for(;r<t;)n+=Ge[e[r++]];return n}function j(e){let t=e.length>>1,n=t<<1,r=new Uint8Array(t),o=0,i=0;for(;i<n;)r[o++]=Z[e.charCodeAt(i++)]<<4|Z[e.charCodeAt(i++)];return r}var ve={name:"Hexadecimal WKB",id:"wkb",module:"wkt",version:p,worker:!0,category:"geometry",extensions:["wkb"],mimeTypes:[],options:O.options,text:!0,testText:St,parse:async e=>ze(new TextDecoder().decode(e)),parseTextSync:ze};function ze(e,t){let n=j(e);return O.parseSync?.(n.buffer,t)}function St(e){return!e||e.length<10||e.length%2!==0||!e.startsWith("00")&&!e.startsWith("01")?!1:/^[0-9a-fA-F]+$/.test(e.slice(2))}var x=class{arrayBuffer;dataView;byteOffset;littleEndian;constructor(t,n=!1){this.arrayBuffer=t,this.dataView=new DataView(t),this.byteOffset=0,this.littleEndian=!n}readUInt8(){let t=this.dataView.getUint8(this.byteOffset);return this.byteOffset+=1,t}readUInt16(){let t=this.dataView.getUint16(this.byteOffset,this.littleEndian);return this.byteOffset+=2,t}readUInt32(){let t=this.dataView.getUint32(this.byteOffset,this.littleEndian);return this.byteOffset+=4,t}readInt8(){let t=this.dataView.getInt8(this.byteOffset);return this.byteOffset+=1,t}readInt16(){let t=this.dataView.getInt16(this.byteOffset,this.littleEndian);return this.byteOffset+=2,t}readInt32(){let t=this.dataView.getInt32(this.byteOffset,this.littleEndian);return this.byteOffset+=4,t}readFloat(){let t=this.dataView.getFloat32(this.byteOffset,this.littleEndian);return this.byteOffset+=4,t}readDouble(){let t=this.dataView.getFloat64(this.byteOffset,this.littleEndian);return this.byteOffset+=8,t}readVarInt(){let t=0,n=0,r;do r=this.dataView.getUint8(this.byteOffset+n),t+=(r&127)<<7*n,n++;while(r>=128);return this.byteOffset+=n,t}};function H(e){let r=new x(e).readUInt8()&15;return!(r<1||r>7)}function ce(e){let t=new x(e),n=Lt(t);if(n.hasSizeAttribute&&t.readVarInt(),n.hasBoundingBox){let r=2;n.hasZ&&r++,n.hasM&&r++;for(let o=0;o<r;o++)t.readVarInt(),t.readVarInt()}return Et(t,n,n.geometryType)}function Lt(e){let t=e.readUInt8(),n=e.readUInt8(),r=t&15,o=w(t>>4),i=Boolean(n>>3&1),s=!1,c=!1,u=0,a=1,y=0,h=1;if(i){let m=e.readUInt8();s=(m&1)===1,c=(m&2)===2,u=w((m&28)>>2),a=Math.pow(10,u),y=w((m&224)>>5),h=Math.pow(10,y)}return{geometryType:r,precision:o,precisionFactor:Math.pow(10,o),hasBoundingBox:Boolean(n>>0&1),hasSizeAttribute:Boolean(n>>1&1),hasIdList:Boolean(n>>2&1),hasExtendedPrecision:i,isEmpty:Boolean(n>>4&1),hasZ:s,hasM:c,zPrecision:u,zPrecisionFactor:a,mPrecision:y,mPrecisionFactor:h}}function Et(e,t,n){switch(n){case l.Point:return Tt(e,t);case l.LineString:return Mt(e,t);case l.Polygon:return Ot(e,t);case l.MultiPoint:return xt(e,t);case l.MultiLineString:return Bt(e,t);case l.MultiPolygon:return Wt(e,t);case l.GeometryCollection:return kt(e,t);default:throw new Error(`GeometryType ${n} not supported`)}}function Tt(e,t){return t.isEmpty?{type:"Point",coordinates:[]}:{type:"Point",coordinates:Ut(e,t)}}function Mt(e,t){if(t.isEmpty)return{type:"LineString",coordinates:[]};let n=e.readVarInt(),r=B(t),o=[];for(let i=0;i<n;i++)o.push(S(e,t,r));return{type:"LineString",coordinates:o}}function Ot(e,t){if(t.isEmpty)return{type:"Polygon",coordinates:[]};let n=e.readVarInt(),r=B(t),o=e.readVarInt(),i=[];for(let c=0;c<o;c++)i.push(S(e,t,r));let s=[i];for(let c=1;c<n;c++){let u=e.readVarInt(),a=[];for(let y=0;y<u;y++)a.push(S(e,t,r));s.push(a)}return{type:"Polygon",coordinates:s}}function xt(e,t){if(t.isEmpty)return{type:"MultiPoint",coordinates:[]};let n=B(t),r=e.readVarInt(),o=[];for(let i=0;i<r;i++)o.push(S(e,t,n));return{type:"MultiPoint",coordinates:o}}function Bt(e,t){if(t.isEmpty)return{type:"MultiLineString",coordinates:[]};let n=B(t),r=e.readVarInt(),o=[];for(let i=0;i<r;i++){let s=e.readVarInt(),c=[];for(let u=0;u<s;u++)c.push(S(e,t,n));o.push(c)}return{type:"MultiLineString",coordinates:o}}function Wt(e,t){if(t.isEmpty)return{type:"MultiPolygon",coordinates:[]};let n=B(t),r=e.readVarInt(),o=[];for(let i=0;i<r;i++){let s=e.readVarInt(),c=e.readVarInt(),u=[];for(let y=0;y<c;y++)u.push(S(e,t,n));let a=u?[u]:[];for(let y=1;y<s;y++){let h=[],m=e.readVarInt();for(let T=0;T<m;T++)h.push(S(e,t,n));a.push(h)}o.push(a)}return{type:"MultiPolygon",coordinates:o}}function kt(e,t){return{type:"GeometryCollection",geometries:[]}}function w(e){return e>>1^-(e&1)}function Ce(e,t,n,r){return n!==void 0?r!==void 0?[e,t,n,r]:[e,t,n]:[e,t]}function B(e){return Ce(0,0,e.hasZ?0:void 0,e.hasM?0:void 0)}function Ut(e,t){let n=w(e.readVarInt())/t.precisionFactor,r=w(e.readVarInt())/t.precisionFactor,o=t.hasZ?w(e.readVarInt())/t.zPrecisionFactor:void 0,i=t.hasM?w(e.readVarInt())/t.mPrecisionFactor:void 0;return Ce(n,r,o,i)}function S(e,t,n){return n[0]+=w(e.readVarInt())/t.precisionFactor,n[1]+=w(e.readVarInt())/t.precisionFactor,t.hasZ&&(n[2]+=w(e.readVarInt())/t.zPrecisionFactor),t.hasM&&(n[3]+=w(e.readVarInt())/t.mPrecisionFactor),n.slice()}var Kt={name:"TWKB (Tiny Well-Known Binary)",id:"twkb",module:"wkt",version:p,worker:!0,category:"geometry",extensions:["twkb"],mimeTypes:[],tests:[H],options:{wkb:{shape:"binary-geometry"}}},Fe={...Kt,parse:async e=>ce(e),parseSync:ce};function ue(e,t){let n=new d(0,!0),r={...Rt(5,0,0),hasZ:t?.hasZ,hasM:t?.hasM};return Re(n,e,r),n.arrayBuffer}function Re(e,t,n){switch(t.type){case"Point":return At(e,n,t);case"LineString":return Gt(e,n,t);case"Polygon":return Vt(e,n,t);case"MultiPoint":return zt(e,n,t);case"MultiLineString":return vt(e,n,t);case"MultiPolygon":return Ct(e,n,t);case"GeometryCollection":return Ft(e,n,t);default:throw new Error("unsupported geometry type")}}function At(e,t,n){let r=n.coordinates.length===0||n[0]==="undefined"||n[1]==="undefined";if(L(e,t,l.Point,r),!r){let o=[0,0,0,0];E(e,t,n.coordinates,o)}}function Gt(e,t,n){let r=n.coordinates,o=r.length===0;if(L(e,t,l.LineString,o),!o){e.writeVarInt(r.length);let i=[0,0,0,0];for(let s of r)E(e,t,s,i)}return e.arrayBuffer}function Vt(e,t,n){let r=n.coordinates,o=r.length===0;if(L(e,t,l.Polygon,o),!o){e.writeVarInt(r.length);let i=[0,0,0,0];for(let s of r){e.writeVarInt(s.length);for(let c of s)E(e,t,i,c)}}return e.arrayBuffer}function zt(e,t,n){let r=n.coordinates,o=r.length===0;if(L(e,t,l.MultiPoint,o),!o){e.writeVarInt(r.length);let i=[0,0,0,0];for(let s=0;s<r.length;s++)E(e,t,i,r[s])}}function vt(e,t,n){let r=n.coordinates,o=r.length===0;if(L(e,t,l.MultiLineString,o),!o){e.writeVarInt(r.length);let i=[0,0,0,0];for(let s of r){e.writeVarInt(s.length);for(let c of s)E(e,t,i,c)}}return e.arrayBuffer}function Ct(e,t,n){let{coordinates:r}=n,o=r.length===0;if(L(e,t,l.MultiPolygon,o),!o){let i=r;e.writeVarInt(i.length);let s=[0,0,0,0];for(let c of i){e.writeVarInt(c.length);for(let u of c){e.writeVarInt(u.length);for(let a of u)E(e,t,s,a)}}}}function Ft(e,t,n){let{geometries:r}=n,o=r.length===0;if(L(e,t,l.GeometryCollection,o),r.length>0){e.writeVarInt(r.length);for(let i of r)Re(e,i,t)}}function L(e,t,n,r){let o=(W(t.xy)<<4)+n,i=t.hasZ||t.hasM?1<<3:0;if(i+=r?1<<4:0,e.writeUInt8(o),e.writeUInt8(i),t.hasZ||t.hasM){let s=0;t.hasZ&&(s|=1),t.hasM&&(s|=2),e.writeUInt8(s)}}function E(e,t,n,r){let o=n[0]*t.xyFactor,i=n[1]*t.xyFactor,s=n[2]*t.zFactor,c=n[3]*t.mFactor;e.writeVarInt(W(o-r[0])),e.writeVarInt(W(i-r[1])),t.hasZ&&e.writeVarInt(W(s-r[2])),t.hasM&&e.writeVarInt(W(c-r[3])),r[0]=o,r[1]=i,r[2]=s,r[3]=c}function W(e){return e<<1^e>>31}function Rt(e,t,n){return{xy:e,z:t,m:n,xyFactor:Math.pow(10,e),zFactor:Math.pow(10,t),mFactor:Math.pow(10,n)}}var Ne={name:"TWKB (Tiny Well Known Binary)",id:"twkb",module:"wkt",version:p,extensions:["twkb"],encode:async(e,t)=>ue(e,t?.twkb),encodeSync:(e,t)=>ue(e,t?.twkb),options:{twkb:{hasZ:!1,hasM:!1}}};return Xe(k);})();
|
|
9
|
+
return __exports__;
|
|
10
|
+
});
|
package/dist/hex-wkb-loader.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LoaderWithParser } from '@loaders.gl/loader-utils';
|
|
2
2
|
import { BinaryGeometry } from '@loaders.gl/schema';
|
|
3
|
-
import type { WKBLoaderOptions } from
|
|
3
|
+
import type { WKBLoaderOptions } from "./wkb-loader.js";
|
|
4
4
|
export type HexWKBLoaderOptions = WKBLoaderOptions;
|
|
5
5
|
/**
|
|
6
6
|
* Worker loader for Hex-encoded WKB (Well-Known Binary)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hex-wkb-loader.d.ts","sourceRoot":"","sources":["../src/hex-wkb-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAElD,OAAO,KAAK,EAAC,gBAAgB,EAAC,
|
|
1
|
+
{"version":3,"file":"hex-wkb-loader.d.ts","sourceRoot":"","sources":["../src/hex-wkb-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAElD,OAAO,KAAK,EAAC,gBAAgB,EAAC,wBAAqB;AAKnD,MAAM,MAAM,mBAAmB,GAAG,gBAAgB,CAAC;AAEnD;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,gBAAgB,CAAC,cAAc,EAAE,KAAK,EAAE,mBAAmB,CAerF,CAAC;AASF;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAcvD"}
|
package/dist/hex-wkb-loader.js
CHANGED
|
@@ -1,37 +1,53 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { WKBLoader } from "./wkb-loader.js";
|
|
2
5
|
import { VERSION } from "./lib/utils/version.js";
|
|
3
6
|
import { decodeHex } from "./lib/utils/hex-transcoder.js";
|
|
7
|
+
/**
|
|
8
|
+
* Worker loader for Hex-encoded WKB (Well-Known Binary)
|
|
9
|
+
*/
|
|
4
10
|
export const HexWKBLoader = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
name: 'Hexadecimal WKB',
|
|
12
|
+
id: 'wkb',
|
|
13
|
+
module: 'wkt',
|
|
14
|
+
version: VERSION,
|
|
15
|
+
worker: true,
|
|
16
|
+
category: 'geometry',
|
|
17
|
+
extensions: ['wkb'],
|
|
18
|
+
mimeTypes: [],
|
|
19
|
+
options: WKBLoader.options,
|
|
20
|
+
text: true,
|
|
21
|
+
testText: isHexWKB,
|
|
22
|
+
// TODO - encoding here seems wasteful - extend hex transcoder?
|
|
23
|
+
parse: async (arrayBuffer) => parseHexWKB(new TextDecoder().decode(arrayBuffer)),
|
|
24
|
+
parseTextSync: parseHexWKB
|
|
18
25
|
};
|
|
19
26
|
function parseHexWKB(text, options) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
const uint8Array = decodeHex(text);
|
|
28
|
+
const binaryGeometry = WKBLoader.parseSync?.(uint8Array.buffer, options);
|
|
29
|
+
// @ts-expect-error
|
|
30
|
+
return binaryGeometry;
|
|
24
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Check if string is a valid Well-known binary (WKB) in HEX format
|
|
34
|
+
* https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry
|
|
35
|
+
*
|
|
36
|
+
* @param str input string
|
|
37
|
+
* @returns true if string is a valid WKB in HEX format
|
|
38
|
+
*/
|
|
25
39
|
export function isHexWKB(string) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
if (!string) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
// check if the length of the string is even and is at least 10 characters long
|
|
44
|
+
if (string.length < 10 || string.length % 2 !== 0) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
// check if first two characters are 00 or 01
|
|
48
|
+
if (!string.startsWith('00') && !string.startsWith('01')) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
// check if the rest of the string is a valid hex
|
|
52
|
+
return /^[0-9a-fA-F]+$/.test(string.slice(2));
|
|
36
53
|
}
|
|
37
|
-
//# sourceMappingURL=hex-wkb-loader.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -17,9 +17,9 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
//
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
20
|
+
// dist/index.js
|
|
21
|
+
var dist_exports = {};
|
|
22
|
+
__export(dist_exports, {
|
|
23
23
|
HexWKBLoader: () => HexWKBLoader,
|
|
24
24
|
TWKBLoader: () => TWKBLoader,
|
|
25
25
|
TWKBWriter: () => TWKBWriter,
|
|
@@ -38,12 +38,12 @@ __export(src_exports, {
|
|
|
38
38
|
isWKT: () => isWKT,
|
|
39
39
|
parseWKBHeader: () => parseWKBHeader
|
|
40
40
|
});
|
|
41
|
-
module.exports = __toCommonJS(
|
|
41
|
+
module.exports = __toCommonJS(dist_exports);
|
|
42
42
|
|
|
43
|
-
//
|
|
44
|
-
var VERSION =
|
|
43
|
+
// dist/lib/utils/version.js
|
|
44
|
+
var VERSION = true ? "4.2.0-alpha.5" : "latest";
|
|
45
45
|
|
|
46
|
-
//
|
|
46
|
+
// dist/lib/parse-wkt-crs.js
|
|
47
47
|
function parseWKTCRS(wkt, options) {
|
|
48
48
|
if (options == null ? void 0 : options.debug) {
|
|
49
49
|
console.log("[wktcrs] parse starting with\n", wkt);
|
|
@@ -142,7 +142,7 @@ function sort(data, options) {
|
|
|
142
142
|
return data;
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
//
|
|
145
|
+
// dist/wkt-crs-loader.js
|
|
146
146
|
var WKTCRSLoader = {
|
|
147
147
|
name: "WKT CRS (Well-Known Text Coordinate Reference System)",
|
|
148
148
|
id: "wkt-crs",
|
|
@@ -160,7 +160,7 @@ var WKTCRSLoader = {
|
|
|
160
160
|
parseTextSync: (string, options) => parseWKTCRS(string, options == null ? void 0 : options["wkt-crs"])
|
|
161
161
|
};
|
|
162
162
|
|
|
163
|
-
//
|
|
163
|
+
// dist/lib/encode-wkt-crs.js
|
|
164
164
|
function encodeWKTCRS(wkt, options) {
|
|
165
165
|
if (Array.isArray(wkt) && wkt.length === 1 && Array.isArray(wkt[0])) {
|
|
166
166
|
wkt = wkt[0];
|
|
@@ -182,7 +182,7 @@ function encodeWKTCRS(wkt, options) {
|
|
|
182
182
|
return str;
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
//
|
|
185
|
+
// dist/wkt-crs-writer.js
|
|
186
186
|
var WKTCRSWriter = {
|
|
187
187
|
name: "WKT CRS (Well-Known Text Coordinate Reference System)",
|
|
188
188
|
id: "wkt-crs",
|
|
@@ -201,7 +201,7 @@ var WKTCRSWriter = {
|
|
|
201
201
|
encodeTextSync: (wktcrs, options) => encodeWKTCRS(wktcrs, options == null ? void 0 : options["wkt-crs"])
|
|
202
202
|
};
|
|
203
203
|
|
|
204
|
-
//
|
|
204
|
+
// dist/lib/parse-wkt.js
|
|
205
205
|
var numberRegexp = /[-+]?([0-9]*\.[0-9]+|[0-9]+)([eE][-+]?[0-9]+)?/;
|
|
206
206
|
var tuples = new RegExp("^" + numberRegexp.source + "(\\s" + numberRegexp.source + "){1,}");
|
|
207
207
|
var WKT_MAGIC_STRINGS = [
|
|
@@ -445,7 +445,7 @@ function white(state) {
|
|
|
445
445
|
$(/^\s*/, state);
|
|
446
446
|
}
|
|
447
447
|
|
|
448
|
-
//
|
|
448
|
+
// dist/wkt-loader.js
|
|
449
449
|
var WKTWorkerLoader = {
|
|
450
450
|
name: "WKT (Well-Known Text)",
|
|
451
451
|
id: "wkt",
|
|
@@ -471,7 +471,7 @@ var WKTLoader = {
|
|
|
471
471
|
parseTextSync: parseWKT
|
|
472
472
|
};
|
|
473
473
|
|
|
474
|
-
//
|
|
474
|
+
// dist/lib/encode-wkt.js
|
|
475
475
|
function encodeWKT(geometry) {
|
|
476
476
|
if (geometry.type === "Feature") {
|
|
477
477
|
geometry = geometry.geometry;
|
|
@@ -511,7 +511,7 @@ function wrapParens(s) {
|
|
|
511
511
|
return `(${s})`;
|
|
512
512
|
}
|
|
513
513
|
|
|
514
|
-
//
|
|
514
|
+
// dist/wkt-writer.js
|
|
515
515
|
var WKTWriter = {
|
|
516
516
|
name: "WKT (Well Known Text)",
|
|
517
517
|
id: "wkt",
|
|
@@ -530,14 +530,24 @@ function encodeWKTSync(geometry) {
|
|
|
530
530
|
return new TextEncoder().encode(encodeWKT(geometry)).buffer;
|
|
531
531
|
}
|
|
532
532
|
|
|
533
|
-
//
|
|
533
|
+
// dist/lib/parse-wkb.js
|
|
534
534
|
var import_gis = require("@loaders.gl/gis");
|
|
535
535
|
|
|
536
|
-
//
|
|
536
|
+
// dist/lib/parse-wkb-header.js
|
|
537
537
|
var EWKB_FLAG_Z = 2147483648;
|
|
538
538
|
var EWKB_FLAG_M = 1073741824;
|
|
539
539
|
var EWKB_FLAG_SRID = 536870912;
|
|
540
540
|
var MAX_SRID = 1e4;
|
|
541
|
+
var WKBGeometryType;
|
|
542
|
+
(function(WKBGeometryType2) {
|
|
543
|
+
WKBGeometryType2[WKBGeometryType2["Point"] = 1] = "Point";
|
|
544
|
+
WKBGeometryType2[WKBGeometryType2["LineString"] = 2] = "LineString";
|
|
545
|
+
WKBGeometryType2[WKBGeometryType2["Polygon"] = 3] = "Polygon";
|
|
546
|
+
WKBGeometryType2[WKBGeometryType2["MultiPoint"] = 4] = "MultiPoint";
|
|
547
|
+
WKBGeometryType2[WKBGeometryType2["MultiLineString"] = 5] = "MultiLineString";
|
|
548
|
+
WKBGeometryType2[WKBGeometryType2["MultiPolygon"] = 6] = "MultiPolygon";
|
|
549
|
+
WKBGeometryType2[WKBGeometryType2["GeometryCollection"] = 7] = "GeometryCollection";
|
|
550
|
+
})(WKBGeometryType || (WKBGeometryType = {}));
|
|
541
551
|
function isWKB(arrayBuffer) {
|
|
542
552
|
const dataView = new DataView(arrayBuffer);
|
|
543
553
|
let byteOffset = 0;
|
|
@@ -629,7 +639,7 @@ function parseWKBHeader(dataView, target) {
|
|
|
629
639
|
return wkbHeader;
|
|
630
640
|
}
|
|
631
641
|
|
|
632
|
-
//
|
|
642
|
+
// dist/lib/parse-wkb.js
|
|
633
643
|
function parseWKB(arrayBuffer, options) {
|
|
634
644
|
var _a;
|
|
635
645
|
const binaryGeometry = parseWKBToBinary(arrayBuffer, options);
|
|
@@ -652,24 +662,24 @@ function parseWKBToBinary(arrayBuffer, options) {
|
|
|
652
662
|
const { geometryType, dimensions, littleEndian } = wkbHeader;
|
|
653
663
|
const offset = wkbHeader.byteOffset;
|
|
654
664
|
switch (geometryType) {
|
|
655
|
-
case
|
|
665
|
+
case WKBGeometryType.Point:
|
|
656
666
|
const point = parsePoint2(dataView, offset, dimensions, littleEndian);
|
|
657
667
|
return point.geometry;
|
|
658
|
-
case
|
|
668
|
+
case WKBGeometryType.LineString:
|
|
659
669
|
const line = parseLineString2(dataView, offset, dimensions, littleEndian);
|
|
660
670
|
return line.geometry;
|
|
661
|
-
case
|
|
671
|
+
case WKBGeometryType.Polygon:
|
|
662
672
|
const polygon = parsePolygon2(dataView, offset, dimensions, littleEndian);
|
|
663
673
|
return polygon.geometry;
|
|
664
|
-
case
|
|
674
|
+
case WKBGeometryType.MultiPoint:
|
|
665
675
|
const multiPoint = parseMultiPoint2(dataView, offset, dimensions, littleEndian);
|
|
666
676
|
multiPoint.type = "Point";
|
|
667
677
|
return multiPoint;
|
|
668
|
-
case
|
|
678
|
+
case WKBGeometryType.MultiLineString:
|
|
669
679
|
const multiLine = parseMultiLineString2(dataView, offset, dimensions, littleEndian);
|
|
670
680
|
multiLine.type = "LineString";
|
|
671
681
|
return multiLine;
|
|
672
|
-
case
|
|
682
|
+
case WKBGeometryType.MultiPolygon:
|
|
673
683
|
const multiPolygon = parseMultiPolygon2(dataView, offset, dimensions, littleEndian);
|
|
674
684
|
multiPolygon.type = "Polygon";
|
|
675
685
|
return multiPolygon;
|
|
@@ -823,15 +833,13 @@ function concatenateBinaryPolygonGeometries(binaryPolygonGeometries, dimension)
|
|
|
823
833
|
polygonIndices.unshift(0);
|
|
824
834
|
const primitivePolygonIndices = [0];
|
|
825
835
|
for (const primitivePolygon of primitivePolygons) {
|
|
826
|
-
primitivePolygonIndices.push(
|
|
827
|
-
...primitivePolygon.filter((x) => x > 0).map((x) => x + primitivePolygonIndices[primitivePolygonIndices.length - 1])
|
|
828
|
-
);
|
|
836
|
+
primitivePolygonIndices.push(...primitivePolygon.filter((x) => x > 0).map((x) => x + primitivePolygonIndices[primitivePolygonIndices.length - 1]));
|
|
829
837
|
}
|
|
830
838
|
return {
|
|
831
839
|
type: "Polygon",
|
|
832
840
|
positions: { value: concatenatedPositions, size: dimension },
|
|
833
|
-
polygonIndices: { value: new
|
|
834
|
-
primitivePolygonIndices: { value: new
|
|
841
|
+
polygonIndices: { value: new Uint32Array(polygonIndices), size: 1 },
|
|
842
|
+
primitivePolygonIndices: { value: new Uint32Array(primitivePolygonIndices), size: 1 }
|
|
835
843
|
};
|
|
836
844
|
}
|
|
837
845
|
function concatTypedArrays(arrays) {
|
|
@@ -851,7 +859,7 @@ function concatTypedArrays(arrays) {
|
|
|
851
859
|
return buffer;
|
|
852
860
|
}
|
|
853
861
|
|
|
854
|
-
//
|
|
862
|
+
// dist/wkb-loader.js
|
|
855
863
|
var WKBWorkerLoader = {
|
|
856
864
|
name: "WKB",
|
|
857
865
|
id: "wkb",
|
|
@@ -876,13 +884,15 @@ var WKBLoader = {
|
|
|
876
884
|
parseSync: parseWKB
|
|
877
885
|
};
|
|
878
886
|
|
|
879
|
-
//
|
|
887
|
+
// dist/lib/utils/binary-writer.js
|
|
880
888
|
var LE = true;
|
|
881
889
|
var BE = false;
|
|
882
890
|
var BinaryWriter = class {
|
|
891
|
+
arrayBuffer;
|
|
892
|
+
dataView;
|
|
893
|
+
byteOffset = 0;
|
|
894
|
+
allowResize = false;
|
|
883
895
|
constructor(size, allowResize) {
|
|
884
|
-
this.byteOffset = 0;
|
|
885
|
-
this.allowResize = false;
|
|
886
896
|
this.arrayBuffer = new ArrayBuffer(size);
|
|
887
897
|
this.dataView = new DataView(this.arrayBuffer);
|
|
888
898
|
this.byteOffset = 0;
|
|
@@ -991,7 +1001,17 @@ var BinaryWriter = class {
|
|
|
991
1001
|
}
|
|
992
1002
|
};
|
|
993
1003
|
|
|
994
|
-
//
|
|
1004
|
+
// dist/lib/encode-wkb.js
|
|
1005
|
+
var WKB;
|
|
1006
|
+
(function(WKB2) {
|
|
1007
|
+
WKB2[WKB2["Point"] = 1] = "Point";
|
|
1008
|
+
WKB2[WKB2["LineString"] = 2] = "LineString";
|
|
1009
|
+
WKB2[WKB2["Polygon"] = 3] = "Polygon";
|
|
1010
|
+
WKB2[WKB2["MultiPoint"] = 4] = "MultiPoint";
|
|
1011
|
+
WKB2[WKB2["MultiLineString"] = 5] = "MultiLineString";
|
|
1012
|
+
WKB2[WKB2["MultiPolygon"] = 6] = "MultiPolygon";
|
|
1013
|
+
WKB2[WKB2["GeometryCollection"] = 7] = "GeometryCollection";
|
|
1014
|
+
})(WKB || (WKB = {}));
|
|
995
1015
|
function encodeWKB(geometry, options = {}) {
|
|
996
1016
|
if (geometry.type === "Feature") {
|
|
997
1017
|
geometry = geometry.geometry;
|
|
@@ -1040,7 +1060,7 @@ function getGeometrySize(geometry, options) {
|
|
|
1040
1060
|
function encodePoint(coordinates, options) {
|
|
1041
1061
|
const writer = new BinaryWriter(getPointSize(options));
|
|
1042
1062
|
writer.writeInt8(1);
|
|
1043
|
-
writeWkbType(writer,
|
|
1063
|
+
writeWkbType(writer, WKB.Point, options);
|
|
1044
1064
|
if (typeof coordinates[0] === "undefined" && typeof coordinates[1] === "undefined") {
|
|
1045
1065
|
writer.writeDoubleLE(NaN);
|
|
1046
1066
|
writer.writeDoubleLE(NaN);
|
|
@@ -1073,7 +1093,7 @@ function encodeLineString(coordinates, options) {
|
|
|
1073
1093
|
const size = getLineStringSize(coordinates, options);
|
|
1074
1094
|
const writer = new BinaryWriter(size);
|
|
1075
1095
|
writer.writeInt8(1);
|
|
1076
|
-
writeWkbType(writer,
|
|
1096
|
+
writeWkbType(writer, WKB.LineString, options);
|
|
1077
1097
|
writer.writeUInt32LE(coordinates.length);
|
|
1078
1098
|
for (const coordinate of coordinates) {
|
|
1079
1099
|
writeCoordinate(writer, coordinate, options);
|
|
@@ -1087,7 +1107,7 @@ function getLineStringSize(coordinates, options) {
|
|
|
1087
1107
|
function encodePolygon(coordinates, options) {
|
|
1088
1108
|
const writer = new BinaryWriter(getPolygonSize(coordinates, options));
|
|
1089
1109
|
writer.writeInt8(1);
|
|
1090
|
-
writeWkbType(writer,
|
|
1110
|
+
writeWkbType(writer, WKB.Polygon, options);
|
|
1091
1111
|
const [exteriorRing, ...interiorRings] = coordinates;
|
|
1092
1112
|
if (exteriorRing.length > 0) {
|
|
1093
1113
|
writer.writeUInt32LE(1 + interiorRings.length);
|
|
@@ -1122,7 +1142,7 @@ function encodeMultiPoint(multiPoint, options) {
|
|
|
1122
1142
|
const writer = new BinaryWriter(getMultiPointSize(multiPoint, options));
|
|
1123
1143
|
const points = multiPoint.coordinates;
|
|
1124
1144
|
writer.writeInt8(1);
|
|
1125
|
-
writeWkbType(writer,
|
|
1145
|
+
writeWkbType(writer, WKB.MultiPoint, options);
|
|
1126
1146
|
writer.writeUInt32LE(points.length);
|
|
1127
1147
|
for (const point of points) {
|
|
1128
1148
|
const arrayBuffer = encodePoint(point, options);
|
|
@@ -1140,7 +1160,7 @@ function encodeMultiLineString(multiLineString, options) {
|
|
|
1140
1160
|
const writer = new BinaryWriter(getMultiLineStringSize(multiLineString, options));
|
|
1141
1161
|
const lineStrings = multiLineString.coordinates;
|
|
1142
1162
|
writer.writeInt8(1);
|
|
1143
|
-
writeWkbType(writer,
|
|
1163
|
+
writeWkbType(writer, WKB.MultiLineString, options);
|
|
1144
1164
|
writer.writeUInt32LE(lineStrings.length);
|
|
1145
1165
|
for (const lineString of lineStrings) {
|
|
1146
1166
|
const encodedLineString = encodeLineString(lineString, options);
|
|
@@ -1160,7 +1180,7 @@ function encodeMultiPolygon(multiPolygon, options) {
|
|
|
1160
1180
|
const writer = new BinaryWriter(getMultiPolygonSize(multiPolygon, options));
|
|
1161
1181
|
const polygons = multiPolygon.coordinates;
|
|
1162
1182
|
writer.writeInt8(1);
|
|
1163
|
-
writeWkbType(writer,
|
|
1183
|
+
writeWkbType(writer, WKB.MultiPolygon, options);
|
|
1164
1184
|
writer.writeUInt32LE(polygons.length);
|
|
1165
1185
|
for (const polygon of polygons) {
|
|
1166
1186
|
const encodedPolygon = encodePolygon(polygon, options);
|
|
@@ -1179,7 +1199,7 @@ function getMultiPolygonSize(multiPolygon, options) {
|
|
|
1179
1199
|
function encodeGeometryCollection(collection, options) {
|
|
1180
1200
|
const writer = new BinaryWriter(getGeometryCollectionSize(collection, options));
|
|
1181
1201
|
writer.writeInt8(1);
|
|
1182
|
-
writeWkbType(writer,
|
|
1202
|
+
writeWkbType(writer, WKB.GeometryCollection, options);
|
|
1183
1203
|
writer.writeUInt32LE(collection.geometries.length);
|
|
1184
1204
|
for (const geometry of collection.geometries) {
|
|
1185
1205
|
const arrayBuffer = encodeWKB(geometry, options);
|
|
@@ -1226,7 +1246,7 @@ function getCoordinateSize(options) {
|
|
|
1226
1246
|
return coordinateSize;
|
|
1227
1247
|
}
|
|
1228
1248
|
|
|
1229
|
-
//
|
|
1249
|
+
// dist/wkb-writer.js
|
|
1230
1250
|
var WKBWriter = {
|
|
1231
1251
|
name: "WKB (Well Known Binary)",
|
|
1232
1252
|
id: "wkb",
|
|
@@ -1247,7 +1267,7 @@ var WKBWriter = {
|
|
|
1247
1267
|
}
|
|
1248
1268
|
};
|
|
1249
1269
|
|
|
1250
|
-
//
|
|
1270
|
+
// dist/lib/utils/hex-transcoder.js
|
|
1251
1271
|
var alphabet = "0123456789abcdef";
|
|
1252
1272
|
var encodeLookup = [];
|
|
1253
1273
|
var decodeLookup = [];
|
|
@@ -1282,7 +1302,7 @@ function decodeHex(string) {
|
|
|
1282
1302
|
return array;
|
|
1283
1303
|
}
|
|
1284
1304
|
|
|
1285
|
-
//
|
|
1305
|
+
// dist/hex-wkb-loader.js
|
|
1286
1306
|
var HexWKBLoader = {
|
|
1287
1307
|
name: "Hexadecimal WKB",
|
|
1288
1308
|
id: "wkb",
|
|
@@ -1318,8 +1338,12 @@ function isHexWKB(string) {
|
|
|
1318
1338
|
return /^[0-9a-fA-F]+$/.test(string.slice(2));
|
|
1319
1339
|
}
|
|
1320
1340
|
|
|
1321
|
-
//
|
|
1341
|
+
// dist/lib/utils/binary-reader.js
|
|
1322
1342
|
var BinaryReader = class {
|
|
1343
|
+
arrayBuffer;
|
|
1344
|
+
dataView;
|
|
1345
|
+
byteOffset;
|
|
1346
|
+
littleEndian;
|
|
1323
1347
|
constructor(arrayBuffer, isBigEndian = false) {
|
|
1324
1348
|
this.arrayBuffer = arrayBuffer;
|
|
1325
1349
|
this.dataView = new DataView(arrayBuffer);
|
|
@@ -1380,7 +1404,7 @@ var BinaryReader = class {
|
|
|
1380
1404
|
}
|
|
1381
1405
|
};
|
|
1382
1406
|
|
|
1383
|
-
//
|
|
1407
|
+
// dist/lib/parse-twkb.js
|
|
1384
1408
|
function isTWKB(arrayBuffer) {
|
|
1385
1409
|
const binaryReader = new BinaryReader(arrayBuffer);
|
|
1386
1410
|
const type = binaryReader.readUInt8();
|
|
@@ -1451,19 +1475,19 @@ function parseTWKBHeader(binaryReader) {
|
|
|
1451
1475
|
}
|
|
1452
1476
|
function parseGeometry2(binaryReader, context, geometryType) {
|
|
1453
1477
|
switch (geometryType) {
|
|
1454
|
-
case
|
|
1478
|
+
case WKBGeometryType.Point:
|
|
1455
1479
|
return parsePoint3(binaryReader, context);
|
|
1456
|
-
case
|
|
1480
|
+
case WKBGeometryType.LineString:
|
|
1457
1481
|
return parseLineString3(binaryReader, context);
|
|
1458
|
-
case
|
|
1482
|
+
case WKBGeometryType.Polygon:
|
|
1459
1483
|
return parsePolygon3(binaryReader, context);
|
|
1460
|
-
case
|
|
1484
|
+
case WKBGeometryType.MultiPoint:
|
|
1461
1485
|
return parseMultiPoint3(binaryReader, context);
|
|
1462
|
-
case
|
|
1486
|
+
case WKBGeometryType.MultiLineString:
|
|
1463
1487
|
return parseMultiLineString3(binaryReader, context);
|
|
1464
|
-
case
|
|
1488
|
+
case WKBGeometryType.MultiPolygon:
|
|
1465
1489
|
return parseMultiPolygon3(binaryReader, context);
|
|
1466
|
-
case
|
|
1490
|
+
case WKBGeometryType.GeometryCollection:
|
|
1467
1491
|
return parseGeometryCollection2(binaryReader, context);
|
|
1468
1492
|
default:
|
|
1469
1493
|
throw new Error(`GeometryType ${geometryType} not supported`);
|
|
@@ -1596,7 +1620,7 @@ function parseNextPoint(reader, context, previousPoint) {
|
|
|
1596
1620
|
return previousPoint.slice();
|
|
1597
1621
|
}
|
|
1598
1622
|
|
|
1599
|
-
//
|
|
1623
|
+
// dist/twkb-loader.js
|
|
1600
1624
|
var TWKBWorkerLoader = {
|
|
1601
1625
|
name: "TWKB (Tiny Well-Known Binary)",
|
|
1602
1626
|
id: "twkb",
|
|
@@ -1621,7 +1645,7 @@ var TWKBLoader = {
|
|
|
1621
1645
|
parseSync: parseTWKBGeometry
|
|
1622
1646
|
};
|
|
1623
1647
|
|
|
1624
|
-
//
|
|
1648
|
+
// dist/lib/encode-twkb.js
|
|
1625
1649
|
function encodeTWKB(geometry, options) {
|
|
1626
1650
|
const writer = new BinaryWriter(0, true);
|
|
1627
1651
|
const context = {
|
|
@@ -1654,7 +1678,7 @@ function encodeGeometry(writer, geometry, context) {
|
|
|
1654
1678
|
}
|
|
1655
1679
|
function encodePoint2(writer, context, point) {
|
|
1656
1680
|
const isEmpty = point.coordinates.length === 0 || point[0] === "undefined" || point[1] === "undefined";
|
|
1657
|
-
writeTwkbHeader(writer, context,
|
|
1681
|
+
writeTwkbHeader(writer, context, WKBGeometryType.Point, isEmpty);
|
|
1658
1682
|
if (!isEmpty) {
|
|
1659
1683
|
const previousPoint = [0, 0, 0, 0];
|
|
1660
1684
|
writeTwkbPoint(writer, context, point.coordinates, previousPoint);
|
|
@@ -1663,7 +1687,7 @@ function encodePoint2(writer, context, point) {
|
|
|
1663
1687
|
function encodeLineString2(writer, context, lineString) {
|
|
1664
1688
|
const points = lineString.coordinates;
|
|
1665
1689
|
const isEmpty = points.length === 0;
|
|
1666
|
-
writeTwkbHeader(writer, context,
|
|
1690
|
+
writeTwkbHeader(writer, context, WKBGeometryType.LineString, isEmpty);
|
|
1667
1691
|
if (!isEmpty) {
|
|
1668
1692
|
writer.writeVarInt(points.length);
|
|
1669
1693
|
const previousPoint = [0, 0, 0, 0];
|
|
@@ -1676,7 +1700,7 @@ function encodeLineString2(writer, context, lineString) {
|
|
|
1676
1700
|
function encodePolygon2(writer, context, polygon) {
|
|
1677
1701
|
const polygonRings = polygon.coordinates;
|
|
1678
1702
|
const isEmpty = polygonRings.length === 0;
|
|
1679
|
-
writeTwkbHeader(writer, context,
|
|
1703
|
+
writeTwkbHeader(writer, context, WKBGeometryType.Polygon, isEmpty);
|
|
1680
1704
|
if (!isEmpty) {
|
|
1681
1705
|
writer.writeVarInt(polygonRings.length);
|
|
1682
1706
|
const previousPoint = [0, 0, 0, 0];
|
|
@@ -1692,7 +1716,7 @@ function encodePolygon2(writer, context, polygon) {
|
|
|
1692
1716
|
function encodeMultiPoint2(writer, context, multiPoint) {
|
|
1693
1717
|
const points = multiPoint.coordinates;
|
|
1694
1718
|
const isEmpty = points.length === 0;
|
|
1695
|
-
writeTwkbHeader(writer, context,
|
|
1719
|
+
writeTwkbHeader(writer, context, WKBGeometryType.MultiPoint, isEmpty);
|
|
1696
1720
|
if (!isEmpty) {
|
|
1697
1721
|
writer.writeVarInt(points.length);
|
|
1698
1722
|
const previousPoint = [0, 0, 0, 0];
|
|
@@ -1704,7 +1728,7 @@ function encodeMultiPoint2(writer, context, multiPoint) {
|
|
|
1704
1728
|
function encodeMultiLineString2(writer, context, multiLineStrings) {
|
|
1705
1729
|
const lineStrings = multiLineStrings.coordinates;
|
|
1706
1730
|
const isEmpty = lineStrings.length === 0;
|
|
1707
|
-
writeTwkbHeader(writer, context,
|
|
1731
|
+
writeTwkbHeader(writer, context, WKBGeometryType.MultiLineString, isEmpty);
|
|
1708
1732
|
if (!isEmpty) {
|
|
1709
1733
|
writer.writeVarInt(lineStrings.length);
|
|
1710
1734
|
const previousPoint = [0, 0, 0, 0];
|
|
@@ -1720,7 +1744,7 @@ function encodeMultiLineString2(writer, context, multiLineStrings) {
|
|
|
1720
1744
|
function encodeMultiPolygon2(writer, context, multiPolygon) {
|
|
1721
1745
|
const { coordinates } = multiPolygon;
|
|
1722
1746
|
const isEmpty = coordinates.length === 0;
|
|
1723
|
-
writeTwkbHeader(writer, context,
|
|
1747
|
+
writeTwkbHeader(writer, context, WKBGeometryType.MultiPolygon, isEmpty);
|
|
1724
1748
|
if (!isEmpty) {
|
|
1725
1749
|
const polygons = coordinates;
|
|
1726
1750
|
writer.writeVarInt(polygons.length);
|
|
@@ -1739,7 +1763,7 @@ function encodeMultiPolygon2(writer, context, multiPolygon) {
|
|
|
1739
1763
|
function encodeGeometryCollection2(writer, context, geometryCollection) {
|
|
1740
1764
|
const { geometries } = geometryCollection;
|
|
1741
1765
|
const isEmpty = geometries.length === 0;
|
|
1742
|
-
writeTwkbHeader(writer, context,
|
|
1766
|
+
writeTwkbHeader(writer, context, WKBGeometryType.GeometryCollection, isEmpty);
|
|
1743
1767
|
if (geometries.length > 0) {
|
|
1744
1768
|
writer.writeVarInt(geometries.length);
|
|
1745
1769
|
for (const geometry of geometries) {
|
|
@@ -1796,7 +1820,7 @@ function getTwkbPrecision(xyPrecision, zPrecision, mPrecision) {
|
|
|
1796
1820
|
};
|
|
1797
1821
|
}
|
|
1798
1822
|
|
|
1799
|
-
//
|
|
1823
|
+
// dist/twkb-writer.js
|
|
1800
1824
|
var TWKBWriter = {
|
|
1801
1825
|
name: "TWKB (Tiny Well Known Binary)",
|
|
1802
1826
|
id: "twkb",
|
|
@@ -1812,3 +1836,4 @@ var TWKBWriter = {
|
|
|
1812
1836
|
}
|
|
1813
1837
|
}
|
|
1814
1838
|
};
|
|
1839
|
+
//# sourceMappingURL=index.cjs.map
|