UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 4.54 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{_ as e}from"../../../chunks/tslib.es6.js";import{property as t}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as s}from"../../../core/accessorSupport/decorators/subclass.js";import r from"../Field.js";import{getPixelValueRange as n,isIntegerPixelType as o}from"../rasterFormats/pixelRangeUtils.js";import a from"./BaseRasterFunction.js";import{computeChange as i}from"./changeDetectionUtils.js";import u from"./ComputeChangeFunctionArguments.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"),r=e.map((e=>this._getClassFieldName(e)));if(null==s[0]||null==s[1]||null==r[0]||null==r[1])return{success:!1,supportsGPU:!1,error:"both inputs must have proper attribute table with value and class fields"};this._updateAttributeTable(t,s,r)}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 i(t,s,this.outputPixelType,this._categoryConfig)}_getWebGLParameters(){const e=this.outputPixelType??"f32";let[t,s]=n(e);const r=o(e);return r&&(t-=1e-4,s+=1e-4),{method:this.functionArguments.method,domainRange:[t,s],isOutputRounded:r}}_updateAttributeTable(e,t,s){const n=this.sourceRasterInfos.map((e=>e.attributeTable)),o=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]])))),i=o.map((e=>{const t=[];return e.forEach(((e,s)=>t[e]=s)),t})),{keepMethod:u}=this.functionArguments;this._categoryConfig={categoryIndexLookups:i,classNames:a,keepMethod:u};const l=n[0].clone();l.fields=[new r({name:"OID",type:"oid"}),new r({name:"Value",type:"integer"}),new r({name:"ClassName",type:"string"}),new r({name:"Class_From",type:"string"}),new r({name:"Class_To",type:"string"})];const m=this._getFieldNames(n,"red"),p=this._getFieldNames(n,"green"),c=this._getFieldNames(n,"blue"),d=[],g=2===m.length&&2===p.length&&2===c.length;g&&(d.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 r({name:"Red",type:"integer"}),new r({name:"Green",type:"integer"}),new r({name:"Blue",type:"integer"})));const h=l.features[0].clone();h.geometry=null;const f=[],[y,C]=o.map((e=>e.length));let b=1;for(let r=0;r<y;r++){const e=a[0][r];for(let t=0;t<C;t++){const s=a[1][t];if("changed"===u&&e===s||"unchanged"===u&&e!==s)continue;const n=h.clone();n.attributes={OID:b++,Value:r*C+t,ClassName:e===s?e:`${e} -> ${s}`,Class_From:e,Class_To:s},g&&(n.attributes.Red=d[0][r][0]+d[1][t][0]>>1,n.attributes.Green=d[0][r][1]+d[1][t][1]>>1,n.attributes.Blue=d[0][r][2]+d[1][t][2]>>1),f.push(n)}}if("changed"===u){const e=h.clone();e.attributes={OID:b++,Value:y*C+1,ClassName:"No Change",Class_From:"Same",Class_To:"Same"},f.push(e)}else if("unchanged"===u){const e=h.clone();e.attributes={OID:b++,Value:y*C+2,ClassName:"Changed",Class_From:"Any",Class_To:"Any"},f.push(e)}l.features=f,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:u,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.support.rasterFunctions.ComputeChangeFunction")],l);const m=l;export{m as default};