UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 2.46 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{JSONMap as e}from"../../../core/jsonMap.js";import{isIntegerPixelType as t}from"../formats/pixelRangeUtils.js";import a from"../../support/PixelBlock.js";const n=new e({0:"difference",1:"relative-difference",2:"categorical",3:"euclidean-distance",4:"angle-difference",5:"band-with-most-change"},{useNumericKeys:!0}),s=new e({0:"all",1:"changed",2:"unchanged"},{useNumericKeys:!0});function i(e,n,s,i){const[f,h]=e,p=t(s)&&!t(f.pixelType)&&!t(h.pixelType),u=[f.mask,h.mask].filter(e=>e),m=a.combineBandMasks(u),g=e.map(e=>e.pixels[0]),{width:k,height:x}=f,b=a.createEmptyBand(s,k*x);switch(n){case"difference":case"relative-difference":o({bands:g,mask:m,outBand:b,isRoundingNeeded:p,isRelative:"relative-difference"===n});break;case"categorical":l({bands:g,mask:m,outBand:b,...i});break;case"euclidean-distance":c({pixels:e.map(e=>e.pixels),mask:m,outBand:b});break;case"angle-difference":d({pixels:e.map(e=>e.pixels),mask:m,outBand:b});break;case"band-with-most-change":r({pixels:e.map(e=>e.pixels),mask:m,outBand:b})}const B=new a({width:k,height:x,pixels:[b],pixelType:s,mask:m});return B.updateStatistics(),B}function o(e){const{bands:[t,a],mask:n,isRelative:s,isRoundingNeeded:i,outBand:o}=e,l=t.length;for(let c=0;c<l;c++)if(!n||n[c]){let e=t[c]-a[c];if(s){const n=Math.max(Math.abs(t[c])-Math.abs(a[c]));e=n>0?e/n:0}o[c]=i?Math.round(e):e}}function l(e){const{bands:[t,a],categoryIndexLookups:[n,s],classNames:[i,o],mask:l,keepMethod:c,outBand:d}=e,r=t.length,f=i.length,h=o.length,p=f*h,u=p+1,m=p+2;for(let g=0;g<r;g++)if(!l||l[g]){const e=t[g],l=a[g],r=n[e],f=s[l],k=i[r],x=o[f];d[g]=null==r||null==f?p:"changed"===c&&k===x?u:"unchanged"===c&&k!==x?m:r*h+f}}function c(e){const{pixels:[t,a],mask:n,outBand:s}=e,i=t[0].length,o=t.length;for(let l=0;l<i;l++)if(!n||n[l]){let e=0;for(let n=0;n<o;n++){const s=t[n][l]-a[n][l];e+=s*s}s[l]=Math.sqrt(e)}}function d(e){const{pixels:[t,a],mask:n,outBand:s}=e,i=t[0].length,o=t.length;for(let l=0;l<i;l++)if(!n||n[l]){let e=0,n=0,i=0;for(let s=0;s<o;s++){const o=t[s][l],c=a[s][l];e+=o*c,n+=o*o,i+=c*c}const c=Math.sqrt(n*i);s[l]=c?Math.acos(e/c):1.5707963267948966}}function r(e){const{pixels:[t,a],mask:n,outBand:s}=e,i=t[0].length,o=t.length;for(let l=0;l<i;l++)if(!n||n[l]){let e=0,n=0;for(let s=0;s<o;s++){const i=Math.abs(t[s][l]-a[s][l]);i>e&&(e=i,n=s)}s[l]=n}}export{n as changeMethodMap,i as computeChange,s as keepMethodMap};