UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) 3.92 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import{property as t,subclass as s}from"../../../core/accessorSupport/decorators.js";import{isIntegerPixelType as i}from"../formats/pixelRangeUtils.js";import n from"./BandArithmeticFunctionArguments.js";import{calculateBandIndex as r,getBandMatrix3 as a}from"./bandIndexUtils.js";import o from"./BaseRasterFunction.js";const c=new Set(["vari","mtvi2","rtvi-core","evi"]);let u=class extends o{constructor(){super(...arguments),this.functionName="BandArithmetic",this.functionArguments=null,this.rasterArgumentNames=["raster"]}_bindSourceRasters(){this.outputPixelType=this._getOutputPixelType("f32");const e=this.sourceRasterInfos[0];if(e.bandCount<2)return{success:!1,supportsGPU:!1,error:"band-arithmetic-function: source raster has insufficient amount of raster bands"};const t=e.clone();t.pixelType=this.outputPixelType,t.bandCount="sultan"===this.functionArguments.method?3:1,this._removeStatsHistColormapVAT(t),t.keyProperties={...t.keyProperties,BandProperties:void 0},this.rasterInfo=t;return{success:!0,supportsGPU:!["custom","gvitm","sultan"].includes(this.functionArguments.method)}}_processPixels(e){const t=e.pixelBlocks?.[0];if(null==t)return t;const{method:s,bandIndexes:i}=this.functionArguments,n=i.split(" ").map(e=>parseFloat(e));if(this.rasterInfo.storageInfo.isBsqTile){const{rawInputBandIds:e}=this,t=c.has(this.functionArguments.method)?3:2,s=n.slice(0,t).map(t=>e.indexOf(t-1));n.splice(0,t,...s)}return r(t,{method:s,bandIndexes:n,equation:i,outputPixelType:this.outputPixelType})}_getWebGLParameters(){const e=this.functionArguments.bandIndexes.split(" ").map(e=>parseFloat(e)-1);2===e.length&&e.push(0);const t=this.isInputBandIdsSwizzled?[0,1,2]:e;let s,n;const r=new Float32Array(3),{method:o}=this.functionArguments;switch(o){case"gndvi":case"nbr":case"ndbi":case"ndvi":case"ndvi-re":case"ndsi":case"ndmi":case"mndwi":s=a([t[0],t[1],0]),n="ndxi";break;case"ndwi":s=a([t[1],t[0],0]),n="ndxi";break;case"sr":case"sr-re":case"iron-oxide":case"ferrous-minerals":case"clay-minerals":s=a([t[0],t[1],0]),n="sr";break;case"ci-g":case"ci-re":s=a([t[0],t[1],0]),n="ci";break;case"savi":s=a([t[0],t[1],0]),n="savi",r[0]=e[2]+1;break;case"tsavi":s=a([t[0],t[1],0]),n="tsavi",r[0]=e[2]+1,r[1]=e[3]+1,r[2]=e[4]+1;break;case"msavi":s=a([t[0],t[1],0]),n="msavi";break;case"gemi":s=a([t[0],t[1],0]),n="gemi";break;case"pvi":s=a([t[0],t[1],0]),n="tsavi",r[0]=e[2]+1,r[1]=e[3]+1;break;case"vari":s=a([t[0],t[1],t[2]]),n="vari";break;case"mtvi2":s=a([t[0],t[1],t[2]]),n="mtvi";break;case"rtvi-core":s=a([t[0],t[1],t[2]]),n="rtvicore";break;case"evi":s=a([t[0],t[1],t[2]]),n="evi";break;case"wndwi":s=a([t[0],t[1],0]),n="wndwi",r[0]=e[3]?e[3]+1:.5;break;case"bai":s=a([t[1],t[0],0]),n="bai";break;default:s=a([0,1,2]),n="custom"}return{bandIndexMat3:s,indexType:n,adjustments:r,isOutputRounded:i(this.outputPixelType)}}_getInputBandIds(e){if("custom"===this.functionArguments.method)return e;const t=this.functionArguments.bandIndexes.split(" ").map(e=>parseFloat(e)-1),s=e.length,i=t.map(e=>e>=s?s-1:e),n=c.has(this.functionArguments.method)?3:2,r=i.slice(0,n).map(t=>e[t]);return 2===r.length&&r.push(0),r}_swizzleBandIds(e){const t=this.functionArguments.bandIndexes.split(" ").map(e=>parseFloat(e)-1);2===t.length&&t.push(0);const{method:s}=this.functionArguments,i=(["vari","mtvi2","rtvi-core","evi"].includes(s)?t.slice(0,3):"bai"===s||"ndwi"===s?[t[1],t[0]]:t.slice(0,2)).map(t=>e.indexOf(t));return i[2]??=i[1],this.isInputBandIdsSwizzled=!0,this.swizzledBandSelection=i,!1}};e([t({json:{write:!0,name:"rasterFunction"}})],u.prototype,"functionName",void 0),e([t({type:n,json:{write:!0,name:"rasterFunctionArguments"}})],u.prototype,"functionArguments",void 0),e([t()],u.prototype,"rasterArgumentNames",void 0),u=e([s("esri.layers.raster.functions.BandArithmeticFunction")],u);const m=u;export{m as default};