UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 4.23 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{getPixelValueRange as n,isIntegerPixelType as r}from"../formats/pixelRangeUtils.js";import a from"./BaseRasterFunction.js";import{computeChange as o}from"./changeDetectionUtils.js";import i from"./ComputeChangeFunctionArguments.js";import u from"../../support/Field.js";let l=class extends a{constructor(){super(...arguments),this.functionName="ComputeChange",this.functionArguments=null,this.rasterArgumentNames=["raster","raster2"]}_bindSourceRasters(){const{method:e}=this.functionArguments,t=this.sourceRasterInfos[0].clone();if(this.outputPixelType=this._getOutputPixelType(t.pixelType),t.pixelType=this.outputPixelType,this._removeStatsHistColormapVAT(t),"categorical"===e){const e=this.sourceRasterInfos.map(e=>e.attributeTable),s=this._getFieldNames(e,"value"),n=e.map(e=>this._getClassFieldName(e));if(null==s[0]||null==s[1]||null==n[0]||null==n[1])return{success:!1,supportsGPU:!1,error:"both inputs must have proper attribute table with value and class fields"};this._updateAttributeTable(t,s,n)}t.bandCount=1,this.rasterInfo=t;return{success:!0,supportsGPU:"difference"===e||"relative-difference"===e}}_processPixels(e){const{pixelBlocks:t}=e;if(null==t?.[0]||null==t?.[1])return null;const{method:s}=this.functionArguments;return o(t,s,this.outputPixelType,this._categoryConfig)}_getWebGLParameters(){const e=this.outputPixelType??"f32";let[t,s]=n(e);const a=r(e);return a&&(t-=1e-4,s+=1e-4),{method:this.functionArguments.method,domainRange:[t,s],isOutputRounded:a}}_updateAttributeTable(e,t,s){const n=this.sourceRasterInfos.map(e=>e.attributeTable),r=n.map((e,s)=>e.features.map(e=>e.attributes[t[s]])),a=n.map((e,t)=>e.features.map(e=>e.attributes[s[t]])),o=r.map(e=>{const t=[];return e.forEach((e,s)=>t[e]=s),t}),{keepMethod:i}=this.functionArguments;this._categoryConfig={categoryIndexLookups:o,classNames:a,keepMethod:i};const l=n[0].clone();l.fields=[new u({name:"OID",type:"oid"}),new u({name:"Value",type:"integer"}),new u({name:"ClassName",type:"string"}),new u({name:"Class_From",type:"string"}),new u({name:"Class_To",type:"string"})];const m=this._getFieldNames(n,"red"),p=this._getFieldNames(n,"green"),c=this._getFieldNames(n,"blue"),f=[],d=2===m.length&&2===p.length&&2===c.length;d&&(f.push(...n.map((e,t)=>e.features.map(e=>[e.attributes[m[t]],e.attributes[p[t]],e.attributes[c[t]]]))),l.fields.push(new u({name:"Red",type:"integer"}),new u({name:"Green",type:"integer"}),new u({name:"Blue",type:"integer"})));const g=l.features[0].clone();g.geometry=null;const h=[],[y,C]=r.map(e=>e.length);let b=1;for(let u=0;u<y;u++){const e=a[0][u];for(let t=0;t<C;t++){const s=a[1][t];if("changed"===i&&e===s||"unchanged"===i&&e!==s)continue;const n=g.clone();n.attributes={OID:b++,Value:u*C+t,ClassName:e===s?e:`${e} -> ${s}`,Class_From:e,Class_To:s},d&&(n.attributes.Red=f[0][u][0]+f[1][t][0]>>1,n.attributes.Green=f[0][u][1]+f[1][t][1]>>1,n.attributes.Blue=f[0][u][2]+f[1][t][2]>>1),h.push(n)}}if("changed"===i){const e=g.clone();e.attributes={OID:b++,Value:y*C+1,ClassName:"No Change",Class_From:"Same",Class_To:"Same"},h.push(e)}else if("unchanged"===i){const e=g.clone();e.attributes={OID:b++,Value:y*C+2,ClassName:"Changed",Class_From:"Any",Class_To:"Any"},h.push(e)}l.features=h,e.attributeTable=l}_getFieldNames(e,t){return e.map(({fields:e})=>e.find(e=>e.name.toLowerCase()===t)?.name).filter(e=>e)}_getClassFieldName(e){const t=e.fields.find(e=>"string"===e.type&&e.name.toLowerCase().startsWith("class"))??e.fields.find(e=>"string"===e.type&&e.name.toLowerCase().includes("class")||e.name.toLowerCase().includes("type")||e.name.toLowerCase().includes("name"))??e.fields.find(e=>"string"===e.type);return t?.name}};e([t({json:{write:!0,name:"rasterFunction"}})],l.prototype,"functionName",void 0),e([t({type:i,json:{write:!0,name:"rasterFunctionArguments"}})],l.prototype,"functionArguments",void 0),e([t()],l.prototype,"rasterArgumentNames",void 0),e([t({json:{write:!0}})],l.prototype,"_categoryConfig",void 0),l=e([s("esri.layers.raster.functions.ComputeChangeFunction")],l);const m=l;export{m as default};