@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.98 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{_ as t}from"../../../chunks/tslib.es6.js";import{property as n}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as e}from"../../../core/accessorSupport/decorators/subclass.js";import{getBandMatrix3 as s}from"./bandIndexUtils.js";import r from"./BaseRasterFunction.js";import o from"./ExtractBandFunctionArguments.js";import{MissingBandAction as a}from"./pixelUtils.js";let i=class extends r{constructor(){super(...arguments),this.functionName="ExtractBand",this.functionArguments=null,this.rasterArgumentNames=["raster"]}_bindSourceRasters(){const{functionArguments:t,sourceRasterInfos:n}=this,e=n[0],{method:s,bandNames:r,bandWavelengths:o,bandIds:i,missingBandAction:l}=t,h=r?.length&&("name"===s||"id"!==s&&!i?.length),d=o?.length&&("wavelength"===s||"id"!==s&&!i?.length),g=l===a.fail,p=h?u(e,r):d?m(e,o,this.functionArguments,g):c(e,i,g);if(null==p){return{success:!1,supportsGPU:!1,error:`extract-band-function: Invalid ${h?"band names":d?"band wavelengths":"band ids"} for the imagery data source`}}this.functionArguments.bandIds=p,this.functionArguments.method="id",this.outputPixelType=this._getOutputPixelType("f32");const f=e.clone();f.pixelType=this.outputPixelType,f.bandCount=p.length;const{statistics:b,histograms:x}=f;null!=b&&b.length&&(f.statistics=p.map((t=>b[t]||b[b.length-1]))),null!=x&&x.length&&(f.histograms=p.map((t=>x[t]||x[x.length-1]))),f.multidimensionalInfo&&f.multidimensionalInfo.variables.forEach((t=>{const{statistics:n,histograms:e}=t;null!=n&&n.length&&(t.statistics=p.map((t=>n[t]||n[n.length-1]))),null!=e&&e.length&&(t.histograms=p.map((t=>e[t]||e[e.length-1])))}));let I=f.keyProperties?.BandProperties;I?.length&&(I=p.map((t=>t>=I.length?I[I.length-1]:I[t])),f.keyProperties={...f.keyProperties,BandProperties:I}),this.rasterInfo=f;return{success:!0,supportsGPU:f.bandCount<=3}}_processPixels(t){const n=t.pixelBlocks?.[0];if(null==n)return null;const e=n.pixels.length,s=this.functionArguments.bandIds.map((t=>t>=e?e-1:t));return n.extractBands(s)}_getWebGLParameters(){let t;if(this.isInputBandIdsSwizzled)t=this.swizzledBandSelection.length?this.swizzledBandSelection:[0,1,2];else{t=[...this.functionArguments.bandIds],0===t.length?t=[0,1,2]:t.length<3&&(t[1]=t[1]??t[0],t[2]=t[2]??t[1]);for(let n=0;n<3;n++)t[n]=Math.min(t[n],2)}return{bandIndexMat3:s(t)}}_getInputBandIds(t){const n=t.length;return this.functionArguments.bandIds.map((t=>t>=n?n-1:t)).map((n=>t[n]))}};t([n({json:{write:!0,name:"rasterFunction"}})],i.prototype,"functionName",void 0),t([n({type:o,json:{write:!0,name:"rasterFunctionArguments"}})],i.prototype,"functionArguments",void 0),t([n()],i.prototype,"rasterArgumentNames",void 0),i=t([e("esri.layers.support.rasterFunctions.ExtractBandFunction")],i);const l=i;function u(t,n){const e=t.bandInfos.map((({name:t})=>t.toLowerCase())),s=[];for(let r=0;r<n.length;r++){const t=n[r].toLowerCase();let o=e.indexOf(t);if(-1===o&&"nearinfrared"===t&&(o=e.findIndex((t=>t.startsWith("nearinfrared_1"))),-1===o&&(o=e.findIndex((t=>t.startsWith("nearinfrared"))))),-1===o)return null;s.push(o)}return s}function c(t,n,e){const{bandCount:s}=t;return!n?.length||e&&n.some((t=>t<0||t>=s))?null:n}function m(t,n,{wavelengthMatchTolerance:e},s){const{bandInfos:r}=t,o=[];for(let i=0;i<r.length;i++){const{minWavelength:t,maxWavelength:n}=r[i];if(!t||!n)return null;o.push({minWavelength:t,maxWavelength:n})}const a=[];for(let i=0;i<n.length;i++){const t=n[i];let r=!1,l=-1,u=Number.MAX_VALUE;for(let n=0;n<o.length;n++){const e=o[n],s=t>=e.minWavelength&&t<=e.maxWavelength,a=Math.abs(t-(e.minWavelength+e.maxWavelength)/2);s?a<u&&(r=!0,l=n,u=a):!r&&a<u&&(l=n,u=a)}if(!r&&e&&u<e&&(r=!0),!r&&s)return null;a.push(l)}return a}export{l as default};