@loaders.gl/wkt 4.2.0-alpha.4 → 4.2.0-alpha.5
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 +133 -220
- 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 +77 -58
- 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 +63 -64
- package/dist/lib/utils/binary-writer.js +115 -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 +6 -1
- 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-writer.js +19 -14
- package/dist/workers/wkb-worker.js +3 -1
- package/dist/workers/wkt-worker.js +3 -1
- package/package.json +10 -6
- 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 ae=He((_t,le)=>{le.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:()=>ze,isTWKB:()=>H,isWKB:()=>F,isWKT:()=>G,parseWKBHeader:()=>R});A(k,Ye(ae(),1));var p="4.2.0-alpha.4";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(l){Array.isArray(l)&&r(l,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=z(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=z(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=z(e);return t?{type:"Polygon",coordinates:t}:null}function it(e){if(!f(/^(MULTIPOLYGON)/i,e))return null;g(e);let t=z(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 z(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 V(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(V).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:V,options:{wkt:{}}};function Pe(e){return new TextEncoder().encode(V(e)).buffer}function C(e,t,n){switch(e.type){case"Point":return lt(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 l=0;l<i.length-1;l++){let y=i[l],h=i[l+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 l=o[u],y=o[u+1],h=Se(e,l,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 lt(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 a;(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"})(a||(a={}));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=at(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 at(e,t){let n=new DataView(e),r=R(n),{geometryType:o,dimensions:i,littleEndian:s}=r,c=r.byteOffset;switch(o){case a.Point:return Le(n,c,i,s).geometry;case a.LineString:return ne(n,c,i,s).geometry;case a.Polygon:return Ee(n,c,i,s).geometry;case a.MultiPoint:let h=ft(n,c,i,s);return h.type="Point",h;case a.MultiLineString:let m=yt(n,c,i,s);return m.type="LineString",m;case a.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 l=0;l<o;l++){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(l=>l.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:l}=c;n.push(u.value),r.push(l.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 Uint16Array(i),size:1},primitivePolygonIndices:{value:new Uint16Array(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{constructor(t,n){this.byteOffset=0,this.allowResize=!1,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 ze(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=>Ve(new TextDecoder().decode(e)),parseTextSync:Ve};function Ve(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{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,l=1,y=0,h=1;if(i){let m=e.readUInt8();s=(m&1)===1,c=(m&2)===2,u=w((m&28)>>2),l=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:l,mPrecision:y,mPrecisionFactor:h}}function Et(e,t,n){switch(n){case a.Point:return Tt(e,t);case a.LineString:return Mt(e,t);case a.Polygon:return Ot(e,t);case a.MultiPoint:return xt(e,t);case a.MultiLineString:return Bt(e,t);case a.MultiPolygon:return Wt(e,t);case a.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(),l=[];for(let y=0;y<u;y++)l.push(S(e,t,r));s.push(l)}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 l=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));l.push(h)}o.push(l)}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 zt(e,n,t);case"MultiPoint":return Vt(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,a.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,a.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 zt(e,t,n){let r=n.coordinates,o=r.length===0;if(L(e,t,a.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 Vt(e,t,n){let r=n.coordinates,o=r.length===0;if(L(e,t,a.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,a.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,a.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 l of u)E(e,t,s,l)}}}}function Ft(e,t,n){let{geometries:r}=n,o=r.length===0;if(L(e,t,a.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.4" : "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,9 +833,7 @@ 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",
|
|
@@ -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,7 +884,7 @@ 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 {
|
|
@@ -991,7 +999,17 @@ var BinaryWriter = class {
|
|
|
991
999
|
}
|
|
992
1000
|
};
|
|
993
1001
|
|
|
994
|
-
//
|
|
1002
|
+
// dist/lib/encode-wkb.js
|
|
1003
|
+
var WKB;
|
|
1004
|
+
(function(WKB2) {
|
|
1005
|
+
WKB2[WKB2["Point"] = 1] = "Point";
|
|
1006
|
+
WKB2[WKB2["LineString"] = 2] = "LineString";
|
|
1007
|
+
WKB2[WKB2["Polygon"] = 3] = "Polygon";
|
|
1008
|
+
WKB2[WKB2["MultiPoint"] = 4] = "MultiPoint";
|
|
1009
|
+
WKB2[WKB2["MultiLineString"] = 5] = "MultiLineString";
|
|
1010
|
+
WKB2[WKB2["MultiPolygon"] = 6] = "MultiPolygon";
|
|
1011
|
+
WKB2[WKB2["GeometryCollection"] = 7] = "GeometryCollection";
|
|
1012
|
+
})(WKB || (WKB = {}));
|
|
995
1013
|
function encodeWKB(geometry, options = {}) {
|
|
996
1014
|
if (geometry.type === "Feature") {
|
|
997
1015
|
geometry = geometry.geometry;
|
|
@@ -1040,7 +1058,7 @@ function getGeometrySize(geometry, options) {
|
|
|
1040
1058
|
function encodePoint(coordinates, options) {
|
|
1041
1059
|
const writer = new BinaryWriter(getPointSize(options));
|
|
1042
1060
|
writer.writeInt8(1);
|
|
1043
|
-
writeWkbType(writer,
|
|
1061
|
+
writeWkbType(writer, WKB.Point, options);
|
|
1044
1062
|
if (typeof coordinates[0] === "undefined" && typeof coordinates[1] === "undefined") {
|
|
1045
1063
|
writer.writeDoubleLE(NaN);
|
|
1046
1064
|
writer.writeDoubleLE(NaN);
|
|
@@ -1073,7 +1091,7 @@ function encodeLineString(coordinates, options) {
|
|
|
1073
1091
|
const size = getLineStringSize(coordinates, options);
|
|
1074
1092
|
const writer = new BinaryWriter(size);
|
|
1075
1093
|
writer.writeInt8(1);
|
|
1076
|
-
writeWkbType(writer,
|
|
1094
|
+
writeWkbType(writer, WKB.LineString, options);
|
|
1077
1095
|
writer.writeUInt32LE(coordinates.length);
|
|
1078
1096
|
for (const coordinate of coordinates) {
|
|
1079
1097
|
writeCoordinate(writer, coordinate, options);
|
|
@@ -1087,7 +1105,7 @@ function getLineStringSize(coordinates, options) {
|
|
|
1087
1105
|
function encodePolygon(coordinates, options) {
|
|
1088
1106
|
const writer = new BinaryWriter(getPolygonSize(coordinates, options));
|
|
1089
1107
|
writer.writeInt8(1);
|
|
1090
|
-
writeWkbType(writer,
|
|
1108
|
+
writeWkbType(writer, WKB.Polygon, options);
|
|
1091
1109
|
const [exteriorRing, ...interiorRings] = coordinates;
|
|
1092
1110
|
if (exteriorRing.length > 0) {
|
|
1093
1111
|
writer.writeUInt32LE(1 + interiorRings.length);
|
|
@@ -1122,7 +1140,7 @@ function encodeMultiPoint(multiPoint, options) {
|
|
|
1122
1140
|
const writer = new BinaryWriter(getMultiPointSize(multiPoint, options));
|
|
1123
1141
|
const points = multiPoint.coordinates;
|
|
1124
1142
|
writer.writeInt8(1);
|
|
1125
|
-
writeWkbType(writer,
|
|
1143
|
+
writeWkbType(writer, WKB.MultiPoint, options);
|
|
1126
1144
|
writer.writeUInt32LE(points.length);
|
|
1127
1145
|
for (const point of points) {
|
|
1128
1146
|
const arrayBuffer = encodePoint(point, options);
|
|
@@ -1140,7 +1158,7 @@ function encodeMultiLineString(multiLineString, options) {
|
|
|
1140
1158
|
const writer = new BinaryWriter(getMultiLineStringSize(multiLineString, options));
|
|
1141
1159
|
const lineStrings = multiLineString.coordinates;
|
|
1142
1160
|
writer.writeInt8(1);
|
|
1143
|
-
writeWkbType(writer,
|
|
1161
|
+
writeWkbType(writer, WKB.MultiLineString, options);
|
|
1144
1162
|
writer.writeUInt32LE(lineStrings.length);
|
|
1145
1163
|
for (const lineString of lineStrings) {
|
|
1146
1164
|
const encodedLineString = encodeLineString(lineString, options);
|
|
@@ -1160,7 +1178,7 @@ function encodeMultiPolygon(multiPolygon, options) {
|
|
|
1160
1178
|
const writer = new BinaryWriter(getMultiPolygonSize(multiPolygon, options));
|
|
1161
1179
|
const polygons = multiPolygon.coordinates;
|
|
1162
1180
|
writer.writeInt8(1);
|
|
1163
|
-
writeWkbType(writer,
|
|
1181
|
+
writeWkbType(writer, WKB.MultiPolygon, options);
|
|
1164
1182
|
writer.writeUInt32LE(polygons.length);
|
|
1165
1183
|
for (const polygon of polygons) {
|
|
1166
1184
|
const encodedPolygon = encodePolygon(polygon, options);
|
|
@@ -1179,7 +1197,7 @@ function getMultiPolygonSize(multiPolygon, options) {
|
|
|
1179
1197
|
function encodeGeometryCollection(collection, options) {
|
|
1180
1198
|
const writer = new BinaryWriter(getGeometryCollectionSize(collection, options));
|
|
1181
1199
|
writer.writeInt8(1);
|
|
1182
|
-
writeWkbType(writer,
|
|
1200
|
+
writeWkbType(writer, WKB.GeometryCollection, options);
|
|
1183
1201
|
writer.writeUInt32LE(collection.geometries.length);
|
|
1184
1202
|
for (const geometry of collection.geometries) {
|
|
1185
1203
|
const arrayBuffer = encodeWKB(geometry, options);
|
|
@@ -1226,7 +1244,7 @@ function getCoordinateSize(options) {
|
|
|
1226
1244
|
return coordinateSize;
|
|
1227
1245
|
}
|
|
1228
1246
|
|
|
1229
|
-
//
|
|
1247
|
+
// dist/wkb-writer.js
|
|
1230
1248
|
var WKBWriter = {
|
|
1231
1249
|
name: "WKB (Well Known Binary)",
|
|
1232
1250
|
id: "wkb",
|
|
@@ -1247,7 +1265,7 @@ var WKBWriter = {
|
|
|
1247
1265
|
}
|
|
1248
1266
|
};
|
|
1249
1267
|
|
|
1250
|
-
//
|
|
1268
|
+
// dist/lib/utils/hex-transcoder.js
|
|
1251
1269
|
var alphabet = "0123456789abcdef";
|
|
1252
1270
|
var encodeLookup = [];
|
|
1253
1271
|
var decodeLookup = [];
|
|
@@ -1282,7 +1300,7 @@ function decodeHex(string) {
|
|
|
1282
1300
|
return array;
|
|
1283
1301
|
}
|
|
1284
1302
|
|
|
1285
|
-
//
|
|
1303
|
+
// dist/hex-wkb-loader.js
|
|
1286
1304
|
var HexWKBLoader = {
|
|
1287
1305
|
name: "Hexadecimal WKB",
|
|
1288
1306
|
id: "wkb",
|
|
@@ -1318,7 +1336,7 @@ function isHexWKB(string) {
|
|
|
1318
1336
|
return /^[0-9a-fA-F]+$/.test(string.slice(2));
|
|
1319
1337
|
}
|
|
1320
1338
|
|
|
1321
|
-
//
|
|
1339
|
+
// dist/lib/utils/binary-reader.js
|
|
1322
1340
|
var BinaryReader = class {
|
|
1323
1341
|
constructor(arrayBuffer, isBigEndian = false) {
|
|
1324
1342
|
this.arrayBuffer = arrayBuffer;
|
|
@@ -1380,7 +1398,7 @@ var BinaryReader = class {
|
|
|
1380
1398
|
}
|
|
1381
1399
|
};
|
|
1382
1400
|
|
|
1383
|
-
//
|
|
1401
|
+
// dist/lib/parse-twkb.js
|
|
1384
1402
|
function isTWKB(arrayBuffer) {
|
|
1385
1403
|
const binaryReader = new BinaryReader(arrayBuffer);
|
|
1386
1404
|
const type = binaryReader.readUInt8();
|
|
@@ -1451,19 +1469,19 @@ function parseTWKBHeader(binaryReader) {
|
|
|
1451
1469
|
}
|
|
1452
1470
|
function parseGeometry2(binaryReader, context, geometryType) {
|
|
1453
1471
|
switch (geometryType) {
|
|
1454
|
-
case
|
|
1472
|
+
case WKBGeometryType.Point:
|
|
1455
1473
|
return parsePoint3(binaryReader, context);
|
|
1456
|
-
case
|
|
1474
|
+
case WKBGeometryType.LineString:
|
|
1457
1475
|
return parseLineString3(binaryReader, context);
|
|
1458
|
-
case
|
|
1476
|
+
case WKBGeometryType.Polygon:
|
|
1459
1477
|
return parsePolygon3(binaryReader, context);
|
|
1460
|
-
case
|
|
1478
|
+
case WKBGeometryType.MultiPoint:
|
|
1461
1479
|
return parseMultiPoint3(binaryReader, context);
|
|
1462
|
-
case
|
|
1480
|
+
case WKBGeometryType.MultiLineString:
|
|
1463
1481
|
return parseMultiLineString3(binaryReader, context);
|
|
1464
|
-
case
|
|
1482
|
+
case WKBGeometryType.MultiPolygon:
|
|
1465
1483
|
return parseMultiPolygon3(binaryReader, context);
|
|
1466
|
-
case
|
|
1484
|
+
case WKBGeometryType.GeometryCollection:
|
|
1467
1485
|
return parseGeometryCollection2(binaryReader, context);
|
|
1468
1486
|
default:
|
|
1469
1487
|
throw new Error(`GeometryType ${geometryType} not supported`);
|
|
@@ -1596,7 +1614,7 @@ function parseNextPoint(reader, context, previousPoint) {
|
|
|
1596
1614
|
return previousPoint.slice();
|
|
1597
1615
|
}
|
|
1598
1616
|
|
|
1599
|
-
//
|
|
1617
|
+
// dist/twkb-loader.js
|
|
1600
1618
|
var TWKBWorkerLoader = {
|
|
1601
1619
|
name: "TWKB (Tiny Well-Known Binary)",
|
|
1602
1620
|
id: "twkb",
|
|
@@ -1621,7 +1639,7 @@ var TWKBLoader = {
|
|
|
1621
1639
|
parseSync: parseTWKBGeometry
|
|
1622
1640
|
};
|
|
1623
1641
|
|
|
1624
|
-
//
|
|
1642
|
+
// dist/lib/encode-twkb.js
|
|
1625
1643
|
function encodeTWKB(geometry, options) {
|
|
1626
1644
|
const writer = new BinaryWriter(0, true);
|
|
1627
1645
|
const context = {
|
|
@@ -1654,7 +1672,7 @@ function encodeGeometry(writer, geometry, context) {
|
|
|
1654
1672
|
}
|
|
1655
1673
|
function encodePoint2(writer, context, point) {
|
|
1656
1674
|
const isEmpty = point.coordinates.length === 0 || point[0] === "undefined" || point[1] === "undefined";
|
|
1657
|
-
writeTwkbHeader(writer, context,
|
|
1675
|
+
writeTwkbHeader(writer, context, WKBGeometryType.Point, isEmpty);
|
|
1658
1676
|
if (!isEmpty) {
|
|
1659
1677
|
const previousPoint = [0, 0, 0, 0];
|
|
1660
1678
|
writeTwkbPoint(writer, context, point.coordinates, previousPoint);
|
|
@@ -1663,7 +1681,7 @@ function encodePoint2(writer, context, point) {
|
|
|
1663
1681
|
function encodeLineString2(writer, context, lineString) {
|
|
1664
1682
|
const points = lineString.coordinates;
|
|
1665
1683
|
const isEmpty = points.length === 0;
|
|
1666
|
-
writeTwkbHeader(writer, context,
|
|
1684
|
+
writeTwkbHeader(writer, context, WKBGeometryType.LineString, isEmpty);
|
|
1667
1685
|
if (!isEmpty) {
|
|
1668
1686
|
writer.writeVarInt(points.length);
|
|
1669
1687
|
const previousPoint = [0, 0, 0, 0];
|
|
@@ -1676,7 +1694,7 @@ function encodeLineString2(writer, context, lineString) {
|
|
|
1676
1694
|
function encodePolygon2(writer, context, polygon) {
|
|
1677
1695
|
const polygonRings = polygon.coordinates;
|
|
1678
1696
|
const isEmpty = polygonRings.length === 0;
|
|
1679
|
-
writeTwkbHeader(writer, context,
|
|
1697
|
+
writeTwkbHeader(writer, context, WKBGeometryType.Polygon, isEmpty);
|
|
1680
1698
|
if (!isEmpty) {
|
|
1681
1699
|
writer.writeVarInt(polygonRings.length);
|
|
1682
1700
|
const previousPoint = [0, 0, 0, 0];
|
|
@@ -1692,7 +1710,7 @@ function encodePolygon2(writer, context, polygon) {
|
|
|
1692
1710
|
function encodeMultiPoint2(writer, context, multiPoint) {
|
|
1693
1711
|
const points = multiPoint.coordinates;
|
|
1694
1712
|
const isEmpty = points.length === 0;
|
|
1695
|
-
writeTwkbHeader(writer, context,
|
|
1713
|
+
writeTwkbHeader(writer, context, WKBGeometryType.MultiPoint, isEmpty);
|
|
1696
1714
|
if (!isEmpty) {
|
|
1697
1715
|
writer.writeVarInt(points.length);
|
|
1698
1716
|
const previousPoint = [0, 0, 0, 0];
|
|
@@ -1704,7 +1722,7 @@ function encodeMultiPoint2(writer, context, multiPoint) {
|
|
|
1704
1722
|
function encodeMultiLineString2(writer, context, multiLineStrings) {
|
|
1705
1723
|
const lineStrings = multiLineStrings.coordinates;
|
|
1706
1724
|
const isEmpty = lineStrings.length === 0;
|
|
1707
|
-
writeTwkbHeader(writer, context,
|
|
1725
|
+
writeTwkbHeader(writer, context, WKBGeometryType.MultiLineString, isEmpty);
|
|
1708
1726
|
if (!isEmpty) {
|
|
1709
1727
|
writer.writeVarInt(lineStrings.length);
|
|
1710
1728
|
const previousPoint = [0, 0, 0, 0];
|
|
@@ -1720,7 +1738,7 @@ function encodeMultiLineString2(writer, context, multiLineStrings) {
|
|
|
1720
1738
|
function encodeMultiPolygon2(writer, context, multiPolygon) {
|
|
1721
1739
|
const { coordinates } = multiPolygon;
|
|
1722
1740
|
const isEmpty = coordinates.length === 0;
|
|
1723
|
-
writeTwkbHeader(writer, context,
|
|
1741
|
+
writeTwkbHeader(writer, context, WKBGeometryType.MultiPolygon, isEmpty);
|
|
1724
1742
|
if (!isEmpty) {
|
|
1725
1743
|
const polygons = coordinates;
|
|
1726
1744
|
writer.writeVarInt(polygons.length);
|
|
@@ -1739,7 +1757,7 @@ function encodeMultiPolygon2(writer, context, multiPolygon) {
|
|
|
1739
1757
|
function encodeGeometryCollection2(writer, context, geometryCollection) {
|
|
1740
1758
|
const { geometries } = geometryCollection;
|
|
1741
1759
|
const isEmpty = geometries.length === 0;
|
|
1742
|
-
writeTwkbHeader(writer, context,
|
|
1760
|
+
writeTwkbHeader(writer, context, WKBGeometryType.GeometryCollection, isEmpty);
|
|
1743
1761
|
if (geometries.length > 0) {
|
|
1744
1762
|
writer.writeVarInt(geometries.length);
|
|
1745
1763
|
for (const geometry of geometries) {
|
|
@@ -1796,7 +1814,7 @@ function getTwkbPrecision(xyPrecision, zPrecision, mPrecision) {
|
|
|
1796
1814
|
};
|
|
1797
1815
|
}
|
|
1798
1816
|
|
|
1799
|
-
//
|
|
1817
|
+
// dist/twkb-writer.js
|
|
1800
1818
|
var TWKBWriter = {
|
|
1801
1819
|
name: "TWKB (Tiny Well Known Binary)",
|
|
1802
1820
|
id: "twkb",
|
|
@@ -1812,3 +1830,4 @@ var TWKBWriter = {
|
|
|
1812
1830
|
}
|
|
1813
1831
|
}
|
|
1814
1832
|
};
|
|
1833
|
+
//# sourceMappingURL=index.cjs.map
|