text: !function(r,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("loam",[],e):"object"==typeof exports?exports.loam=e():r.loam=e()}(self,(function(){return(()=>{"use strict";var r={170:(r,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(r){var e={PNG:"png",JPEG:"jpg",GTiff:"tif"};if(!r.includes("-of"))return"tif";var t=r[r.indexOf("-of")+1];return Object.keys(e).includes(t)?e[t]:t},r.exports=e.default},925:(r,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(){for(var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:32,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"0123456789abcdefghijklmnopqrstuvwxyz",t="",a=r;a>0;a--)t+=e[Math.floor(Math.random()*e.length)];return t},r.exports=e.default},985:(r,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var a=t(290);function o(r,e){for(var t=0;t<e.length;t++){var a=e[t];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(r,a.key,a)}}var n=function(){function r(e){if(function(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}(this,r),!(0,a.isArrayAllStrings)(e))throw new Error("All items in the argument list must be strings");this.args=e}var e,t;return e=r,(t=[{key:"allocate",value:function(){var r=this,e=Uint32Array.from(r.args.map((function(r){return Module._malloc(Module.lengthBytesUTF8(r)+1)})).concat([0]));r.args.forEach((function(r,t){Module.stringToUTF8(r,e[t],Module.lengthBytesUTF8(r)+1)}));var t=Module._malloc(e.length*e.BYTES_PER_ELEMENT);Module.HEAPU32.set(e,t/e.BYTES_PER_ELEMENT),r.argPtrsArray=e,r.argPtrsArrayPtr=t}},{key:"deallocate",value:function(){var r=this;Module._free(r.argPtrsArrayPtr),r.argPtrsArray.subarray(0,r.argPtrsArray.length-1).forEach((function(r){return Module._free(r)})),delete r.argPtrsArray,delete r.argPtrsArrayPtr}}])&&o(e.prototype,t),r}();e.default=n,r.exports=e.default},290:(r,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.isArrayAllStrings=function(r){return r.every((function(r){return"string"==typeof r}))}},606:(r,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(r,e){return function(t,a,o){var n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];r(t);var l=[];n&&(l=FS.readFile(o,{encoding:"binary"})),FS.unmount(a),FS.rmdir(a);var u=e.CPLGetLastErrorType();if(u===e.CPLErr.CEFatal){var s=e.CPLGetLastErrorMsg();throw new Error("Error in GDALClose: "+s)}return l}},r.exports=e.default},932:(r,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(r,e,t){return function(l,s){var i=s[0],d=s[1],f=s.slice(2);if(!i||!u.hasOwnProperty(i))throw new Error("mode must be one of {Object.keys(DEMProcessingModes)}");if(i===u["color-relief"]&&!d)throw new Error('A color definition array must be provided if `mode` is "color-relief"');if(i!==u["color-relief"]&&d&&d.length>0)throw new Error('A color definition array should not be provided if `mode` is not "color-relief"');var E=null;i===u["color-relief"]&&(E=t+(0,a.default)()+".txt",FS.writeFile(E,d.join("\n")));var c=new n.default(f);c.allocate();var L=Module.ccall("GDALDEMProcessingOptionsNew","number",["number","number"],[c.argPtrsArrayPtr,null]),P=e.CPLGetLastErrorType();if(P===e.CPLErr.CEFailure||P===e.CPLErr.CEFatal){E&&FS.unlink(E),c.deallocate();var m=e.CPLGetLastErrorMsg();throw new Error("Error in GDALDEMProcessing: "+m)}var M=t+(0,a.default)();FS.mkdir(M),FS.mount(MEMFS,{},M);var p=(0,a.default)(8)+"."+(0,o.default)(f),C=M+"/"+p,b=Module._malloc(Int32Array.BYTES_PER_ELEMENT);Module.setValue(b,0,"i32");var v=r(C,l,i,E,L,b),y=e.CPLGetLastErrorType();function G(){E&&FS.unlink(E),Module.ccall("GDALDEMProcessingOptionsFree",null,["number"],[L]),Module._free(b),c.deallocate()}if(y===e.CPLErr.CEFailure||y===e.CPLErr.CEFatal){G();var g=e.CPLGetLastErrorMsg();throw new Error("Error in GDALDEMProcessing: "+g)}var _={datasetPtr:v,filePath:C,directory:M,filename:p};return G(),_}};var a=l(t(925)),o=l(t(170)),n=l(t(985));function l(r){return r&&r.__esModule?r:{default:r}}var u=Object.freeze({hillshade:"hillshade",slope:"slope",aspect:"aspect","color-relief":"color-relief",TRI:"TRI",TPI:"TPI",roughness:"roughness"});r.exports=e.default},694:(r,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(r,e){return function(t){var a=Module._malloc(6*Float64Array.BYTES_PER_ELEMENT);r(t,a);var o=Module.HEAPF64.subarray(a/Float64Array.BYTES_PER_ELEMENT,a/Float64Array.BYTES_PER_ELEMENT+6),n=e.CPLGetLastErrorType();if(n===e.CPLErr.CEFailure||n===e.CPLErr.CEFatal){Module._free(a);var l=e.CPLGetLastErrorMsg();throw new Error("Error in GDALGetGeoTransform: "+l)}var u=Array.from(o);return Module._free(a),u}},r.exports=e.default},136:(r,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(r,e){return function(t){var a=r(t),o=e.CPLGetLastErrorType();if(o===e.CPLErr.CEFailure||o===e.CPLErr.CEFatal){var n=e.CPLGetLastErrorMsg();throw new Error("Error in GDALGetProjectionRef: "+n)}return a}},r.exports=e.default},24:(r,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(r,e){return function(t){var a=r(t),o=e.CPLGetLastErrorType();if(o===e.CPLErr.CEFailure||o===e.CPLErr.CEFatal){var n=e.CPLGetLastErrorMsg();throw new Error("Error in GDALGetRasterCount: "+n)}return a}},r.exports=e.default},981:(r,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(r,e){return function(t){var a=r(t),o=e.CPLGetLastErrorType();if(o===e.CPLErr.CEFailure||o===e.CPLErr.CEFatal){var n=e.CPLGetLastErrorMsg();throw new Error("Error in GDALGetRasterXSize: "+n)}return a}},r.exports=e.default},857:(r,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(r,e){return function(t){var a=r(t),o=e.CPLGetLastErrorType();if(o===e.CPLErr.CEFailure||o===e.CPLErr.CEFatal){var n=e.CPLGetLastErrorMsg();throw Error("Error in GDALGetRasterYSize: "+n)}return a}},r.exports=e.default},901:(r,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(r,e,t){return function(a){var n,l=t+(0,o.default)();FS.mkdir(l),a instanceof File?(n=a.name,FS.mount(WORKERFS,{files:[a]},l)):a instanceof Blob&&(n="geotiff.tif",FS.mount(WORKERFS,{blobs:[{name:n,data:a}]},l));var u=l+"/"+n,s=r(u),i=e.CPLGetLastErrorType();if(i===e.CPLErr.CEFailure||i===e.CPLErr.CEFatal){FS.unmount(l),FS.rmdir(l);var d=e.CPLGetLastErrorMsg();throw new Error("Error in GDALOpen: "+d)}return{datasetPtr:s,filePath:u,directory:l,filename:n}}};var a,o=(a=t(925))&&a.__esModule?a:{default:a};r.exports=e.default},653:(r,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(r,e,t){return function(l,u){var s=new n.default(u),i=t+(0,a.default)()+".geojson";FS.writeFile(i,JSON.stringify(l));var d=Module.ccall("GDALOpenEx","number",["string"],[i]);s.allocate();var f=Module.ccall("GDALRasterizeOptionsNew","number",["number","number"],[s.argPtrsArrayPtr,null]),E=e.CPLGetLastErrorType();if(E===e.CPLErr.CEFailure||E===e.CPLErr.CEFatal){Module.ccall("GDALClose","number",["number"],d),FS.unlink(i),s.deallocate();var c=e.CPLGetLastErrorMsg();throw new Error("Error in GDALRasterize: "+c)}var L=t+(0,a.default)();FS.mkdir(L),FS.mount(MEMFS,{},L);var P=(0,a.default)(8)+"."+(0,o.default)(u),m=L+"/"+P,M=Module._malloc(Int32Array.BYTES_PER_ELEMENT);Module.setValue(M,0,"i32");var p=r(m,0,d,f,M),C=e.CPLGetLastErrorType();function b(){Module.ccall("GDALClose","number",["number"],d),FS.unlink(i),Module.ccall("GDALRasterizeOptionsFree",null,["number"],[f]),Module._free(M),s.deallocate()}if(C===e.CPLErr.CEFailure||C===e.CPLErr.CEFatal){b();var v=e.CPLGetLastErrorMsg();throw new Error("Error in GDALRasterize: "+v)}var y={datasetPtr:p,filePath:m,directory:L,filename:P};return b(),y}};var a=l(t(925)),o=l(t(170)),n=l(t(985));function l(r){return r&&r.__esModule?r:{default:r}}r.exports=e.default},656:(r,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(r,e,t){return function(l,u){var s=new n.default(u);s.allocate();var i=Module.ccall("GDALTranslateOptionsNew","number",["number","number"],[s.argPtrsArrayPtr,null]),d=e.CPLGetLastErrorType();if(d===e.CPLErr.CEFailure||d===e.CPLErr.CEFatal){s.deallocate();var f=e.CPLGetLastErrorMsg();throw new Error("Error in GDALTranslate: "+f)}var E=t+(0,a.default)();FS.mkdir(E),FS.mount(MEMFS,{},E);var c=(0,a.default)(8)+"."+(0,o.default)(u),L=E+"/"+c,P=Module._malloc(Int32Array.BYTES_PER_ELEMENT);Module.setValue(P,0,"i32");var m=r(L,l,i,P),M=e.CPLGetLastErrorType();function p(){Module.ccall("GDALTranslateOptionsFree",null,["number"],[i]),Module._free(P),s.deallocate()}if(M===e.CPLErr.CEFailure||M===e.CPLErr.CEFatal){p();var C=e.CPLGetLastErrorMsg();throw new Error("Error in GDALTranslate: "+C)}var b={datasetPtr:m,filePath:L,directory:E,filename:c};return p(),b}};var a=l(t(925)),o=l(t(170)),n=l(t(985));function l(r){return r&&r.__esModule?r:{default:r}}r.exports=e.default},940:(r,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(r,e,t){return function(l,u){var s=new n.default(u);s.allocate();var i=Module.ccall("GDALWarpAppOptionsNew","number",["number","number"],[s.argPtrsArrayPtr,null]),d=e.CPLGetLastErrorType();if(d===e.CPLErr.CEFailure||d===e.CPLErr.CEFatal){s.deallocate();var f=e.CPLGetLastErrorMsg();throw new Error("Error in GDALWarp: "+f)}var E=t+(0,a.default)();FS.mkdir(E),FS.mount(MEMFS,{},E);var c=(0,a.default)(8)+"."+(0,o.default)(u),L=E+"/"+c,P=Module._malloc(Int32Array.BYTES_PER_ELEMENT);Module.setValue(P,0,"i32");var m=Module._malloc(4);Module.setValue(m,l,"*");var M=r(L,0,1,m,i,P);function p(){Module.ccall("GDALWarpAppOptionsFree",null,["number"],[i]),Module._free(P),s.deallocate()}var C=e.CPLGetLastErrorType();if(C===e.CPLErr.CEFailure||C===e.CPLErr.CEFatal){p();var b=e.CPLGetLastErrorMsg();throw new Error("Error in GDALWarp: "+b)}var v={datasetPtr:M,filePath:L,directory:E,filename:c};return p(),v}};var a=l(t(925)),o=l(t(170)),n=l(t(985));function l(r){return r&&r.__esModule?r:{default:r}}r.exports=e.default},240:(r,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(r,e,t,a){if(t.length!==a.length)throw new Error("Got mismatched numbers of x and y coordinates.");var o=Module.cwrap("OSRNewSpatialReference","number",["string"]),n=Module.cwrap("OCTNewCoordinateTransformation","number",["number","number"]),l=Module.cwrap("OCTTransform","number",["number","number","number","number","number"]),u=o(r),s=o(e),i=n(u,s),d=Module._malloc(t.length*t.BYTES_PER_ELEMENT),f=Module._malloc(a.length*a.BYTES_PER_ELEMENT);Module.HEAPF64.set(t,d/t.BYTES_PER_ELEMENT),Module.HEAPF64.set(a,f/a.BYTES_PER_ELEMENT),l(i,t.length,d,f,null);var E=Array.from(Module.HEAPF64.subarray(d/t.BYTES_PER_ELEMENT,d/t.BYTES_PER_ELEMENT+t.length)),c=Array.from(Module.HEAPF64.subarray(f/a.BYTES_PER_ELEMENT,f/a.BYTES_PER_ELEMENT+a.length)),L=E.map((function(r,e){return[r,c[e]]}));return Module._free(d),Module._free(f),Module.ccall("OSRDestroySpatialReference","number",["number"],[u]),Module.ccall("OSRDestroySpatialReference","number",["number"],[s]),Module.ccall("OCTDestroyCoordinateTransformation","number",["number"],[i]),L},r.exports=e.default}},e={};function t(a){var o=e[a];if(void 0!==o)return o.exports;var n=e[a]={exports:{}};return r[a](n,n.exports,t),n.exports}return(()=>{var r=c(t(901)),e=c(t(653)),a=c(t(606)),o=c(t(932)),n=c(t(24)),l=c(t(981)),u=c(t(857)),s=c(t(136)),i=c(t(694)),d=c(t(656)),f=c(t(940)),E=c(t(240));function c(r){return r&&r.__esModule?r:{default:r}}var L="/",P=!1,m={},M={CPLErr:{CENone:0,CEDebug:1,CEWarning:2,CEFailure:3,CEFatal:4},CPLErrorReset:null,CPLGetLastErrorMsg:null,CPLGetLastErrorNo:null,CPLGetLastErrorType:null};self.Module={print:function(r){console.log("stdout: "+r)},printErr:function(r){console.log("stderr: "+r)},onRuntimeInitialized:function(){self.Module.ccall("GDALAllRegister",null,[],[]),M.CPLErrorReset=self.Module.cwrap("CPLErrorReset",null,[]),M.CPLGetLastErrorMsg=self.Module.cwrap("CPLGetLastErrorMsg","string",[]),M.CPLGetLastErrorNo=self.Module.cwrap("CPLGetLastErrorNo","number",[]),M.CPLGetLastErrorType=self.Module.cwrap("CPLGetLastErrorType","number",[]);var t=addFunction(self.Module.cwrap("CPLQuietErrorHandler",null,["number","number","string"]),"viii");self.Module.ccall("CPLSetErrorHandler","number",["number"],[t]),m.GDALOpen=(0,r.default)(self.Module.cwrap("GDALOpen","number",["string"]),M,L),m.GDALRasterize=(0,e.default)(self.Module.cwrap("GDALRasterize","number",["string","number","number","number","number"]),M,L),m.GDALClose=(0,a.default)(self.Module.cwrap("GDALClose","number",["number"]),M),m.GDALGetRasterCount=(0,n.default)(self.Module.cwrap("GDALGetRasterCount","number",["number"]),M),m.GDALGetRasterXSize=(0,l.default)(self.Module.cwrap("GDALGetRasterXSize","number",["number"]),M),m.GDALGetRasterYSize=(0,u.default)(self.Module.cwrap("GDALGetRasterYSize","number",["number"]),M),m.GDALGetProjectionRef=(0,s.default)(self.Module.cwrap("GDALGetProjectionRef","string",["number"]),M),m.GDALGetGeoTransform=(0,i.default)(self.Module.cwrap("GDALGetGeoTransform","number",["number","number"]),M),m.GDALTranslate=(0,d.default)(self.Module.cwrap("GDALTranslate","number",["string","number","number","number"]),M,L),m.GDALWarp=(0,f.default)(self.Module.cwrap("GDALWarp","number",["string","number","number","number","number","number"]),M,L),m.GDALDEMProcessing=(0,o.default)(self.Module.cwrap("GDALDEMProcessing","number",["string","number","string","string","number","number"]),M,L),m.LoamFlushFS=function(){var r=FS.lookupPath(L).node.contents;return Object.values(r).forEach((function(r){FS.unmount(FS.getPath(r)),FS.rmdir(FS.getPath(r))})),!0},m.LoamReproject=E.default,P=!0,postMessage({ready:!0})}},onmessage=function(r){if(P)try{var e;if("func"in r.data&&"args"in r.data)e=function(r,e){if(r in m)return m[r].apply(m,function(r){if(Array.isArray(r)){for(var e=0,t=new Array(r.length);e<r.length;e++)t[e]=r[e];return t}}(t=e)||function(r){if(Symbol.iterator in Object(r)||"[object Arguments]"===Object.prototype.toString.call(r))return Array.from(r)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}());var t;throw new Error("Function ".concat(r," was not found"))}(r.data.func,r.data.args);else{if(!("accessor"in r.data)||!("dataset"in r.data))return void postMessage({success:!1,message:"Worker could not parse message: either func + args or accessor + dataset is required",id:r.data.id});e=function(r,e){var t,a=m[e.source.func](e.source.src,e.source.args),o=a,n=!0,l=!1,u=void 0;try{for(var s,i=e.operations[Symbol.iterator]();!(n=(s=i.next()).done);n=!0){var d=s.value,f=d.func,E=d.args;o=m[f](a.datasetPtr,E),m.GDALClose(a.datasetPtr,a.directory,a.filePath),a=o}}catch(r){l=!0,u=r}finally{try{n||null==i.return||i.return()}finally{if(l)throw u}}return"LoamReadBytes"===r?t=m.GDALClose(o.datasetPtr,o.directory,o.filePath,!0):r?(t=m[r](o.datasetPtr),m.GDALClose(o.datasetPtr,o.directory,o.filePath,!1)):m.GDALClose(o.datasetPtr,o.directory,o.filePath,!1),t}(r.data.accessor,r.data.dataset)}postMessage({success:!0,result:e,id:r.data.id})}catch(e){postMessage({success:!1,message:e.message,id:r.data.id})}else postMessage({success:!1,message:"Runtime not yet initialized",id:r.data.id})}})(),{}})()}));