UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) • 20.8 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{numberMaxFloat32 as t}from"../../../core/mathUtils.js";import{getPixelValueRange as e}from"../formats/pixelRangeUtils.js";import n from"../../support/PixelBlock.js";const l=9,i="PixelID";function o(t){return null!=t&&t.pixels?.length>0}function r(t,e){return e?.length&&o(t)?t.extractBands(e):t}function s(t){if(!t?.length||t.some(t=>!o(t)))return null;if(1===t.length)return t[0]?.clone()??null;const e=t,{width:l,height:i,pixelType:r}=e[0];if(e.some(t=>t.width!==l||t.height!==i))return null;const s=e.map(({mask:t})=>t).filter(t=>null!=t);let a=null;s.length&&(a=new Uint8Array(l*i),a.set(s[0]),s.length>1&&k(s.slice(1),a));const f=[];e.forEach(({pixels:t})=>f.push(...t));const h=null!=a&&f.length===e.length?e.map(({width:t,height:e,mask:n})=>n??new Uint8Array(t*e).fill(255)):null,c=e.map(({statistics:t})=>t).filter(t=>t?.length),u=[];return c.forEach(t=>u.push(...t)),new n({pixelType:r,width:l,height:i,mask:a,bandMasks:h,pixels:f,statistics:u.length?u:null})}function a(t){if(!t)return;const e=t.colormap;if(!e||0===e.length)return;const n=e.sort((t,e)=>t[0]-e[0]),l=n[0][0]<0?n[0][0]:0,i=Math.max(256,n[n.length-1][0]-l+1),o=new Uint8Array(4*i),r=[],s=5===n[0].length;if(i>65536)return n.forEach(t=>{r[t[0]-l]=s?t.slice(1):t.slice(1).concat([255])}),{indexed2DColormap:r,offset:l,alphaSpecified:s};if(t.fillUnspecified){let t=n[0];for(let e=t[0]-l,r=0;e<i;e++)o[4*e]=t[1],o[4*e+1]=t[2],o[4*e+2]=t[3],o[4*e+3]=s?t[4]:255,e===t[0]-l&&(t=r===n.length-1?t:n[++r])}else for(let a=0;a<n.length;a++){const t=n[a],e=4*(t[0]-l);o[e]=t[1],o[e+1]=t[2],o[e+2]=t[3],o[e+3]=s?t[4]:255}return{indexedColormap:o,offset:l,alphaSpecified:s}}function f(t,e){if(!o(t))return t;if(!e||!e.indexedColormap&&!e.indexed2DColormap)return t;const n=t.clone(),l=n.pixels;let i=n.mask;const r=n.width*n.height;if(1!==l.length)return t;const{indexedColormap:s,indexed2DColormap:a,offset:f,alphaSpecified:h}=e,c=l[0],u=new Uint8Array(c.length),p=new Uint8Array(c.length),d=new Uint8Array(c.length);let x,g=0;if(s){const t=s.length-1;if(null!=i)for(let e=0;e<r;e++)i[e]&&(g=4*(c[e]-f),g<f||g>t?i[e]=0:(u[e]=s[g],p[e]=s[g+1],d[e]=s[g+2],i[e]=s[g+3]));else{i=new Uint8Array(r);for(let e=0;e<r;e++)g=4*(c[e]-f),g<f||g>t?i[e]=0:(u[e]=s[g],p[e]=s[g+1],d[e]=s[g+2],i[e]=s[g+3]);n.mask=i}}else if(a)if(null!=i)for(let o=0;o<r;o++)i[o]&&(x=a[c[o]],u[o]=x[0],p[o]=x[1],d[o]=x[2],i[o]=x[3]);else{i=new Uint8Array(r);for(let t=0;t<r;t++)x=a[c[t]],u[t]=x[0],p[t]=x[1],d[t]=x[2],i[t]=x[3];n.mask=i}return n.pixels=[u,p,d],n.statistics=null,n.pixelType="u8",n.maskIsAlpha=h,n}function h(t,e){if(!o(t))return null;const{pixels:l,mask:i}=t,r=l.length;let s=e.lut;const{offset:a}=e;s&&1===s[0].length&&(s=l.map(()=>s));const f=[],h=e.outputPixelType||"u8";for(let n=0;n<r;n++){const t=c(l[n],i,s[n],a||0,h);f.push(t)}const u=new n({width:t.width,height:t.height,pixels:f,mask:i,pixelType:h});return u.updateStatistics(),u}function c(t,e,l,i,o){const r=t.length,s=n.createEmptyBand(o,r);if(e)for(let n=0;n<r;n++)e[n]&&(s[n]=l[t[n]-i]);else for(let n=0;n<r;n++)s[n]=l[t[n]-i];return s}function u(t,e,n,l){const{width:i,height:o,pixels:r,mask:s}=t,a=i*o,{bandId:f,ranges:h}=n,c=r[f];if(!c)return;const u=1===h.length,[p,d]=h[0];for(let x=0;x<a;x++)if(!s||s[x]){const t=c[x];if(u)t>=p&&t<=d&&(e[x]=l);else for(let n=0;n<h.length;n++){const[i,o]=h[n];if(t>=i&&t<=o){e[x]=l;break}}}}function p(t,e,n,l){const{width:i,height:o,xyMask:r,xBandId:s,yBandId:a,xBandRange:f,yBandRange:h}=n,{pixels:c,mask:u}=t,p=c[s],d=c[a],[x,g]=f,[m,y]=h,w=(g-x)/i,k=(y-m)/o;for(let M=0;M<p.length;M++)if(!u||u[M]){let t=p[M],n=d[M];if(t<x||t>g||n<m||n>y)continue;r?(t=(t-x)*w,t=t>i-1?i-1:t<0?0:255&t,n=(y-n)*k,n=n>o-1?o-1:n<0?0:255&n,r[n*i+t]&&(e[M]=l)):e[M]=l}}function d(t){const{pixelBlock:e,renderedPixelBlock:n,highlightOptions:l}=t;if(!o(e))return;const{width:i,height:r}=e,s=i*r,a=new Uint8Array(s);for(let o=1;o<=l.length;o++){const t=l[o-1];"bandId"in t?u(e,a,t,o):p(e,a,t,o)}const{pixels:f}=n;1===f.length&&(f[1]=f[0].slice(),f[2]=f[0].slice());const h=l.map(t=>t.color),[c,d,x]=f;if(n.mask){const t=n.mask;for(let e=0;e<s;e++)if(t[e]){t[e]=255;const n=a[e];if(n){const l=h[n-1];c[e]=l[0],d[e]=l[1],x[e]=l[2],t[e]=l[3]}}}else{const t=new Uint8Array(s).fill(255);for(let e=0;e<s;e++){const n=a[e];if(n){const l=h[n-1];c[e]=l[0],d[e]=l[1],x[e]=l[2],t[e]=l[3]}}n.mask=t}n.maskIsAlpha=!0}function x(t,e){if(!o(t))return null;const n=t.clone(),{pixels:l}=n,i=n.width*n.height,r=e.length,s=Math.floor(r/2),a=e[Math.floor(s)],f=l[0],h=new Uint8Array(i),c=new Uint8Array(i),u=new Uint8Array(i);let p=n.mask;const d=4===e[0].mappedColor.length;p||(p=new Uint8Array(i),p.fill(d?255:1),n.mask=p);for(let o=0;o<i;o++)if(p[o]){const t=f[o];let n=!1,l=s,i=a,d=0,x=r-1;for(;x-d>1;){if(t===i.value){n=!0;break}t>i.value?d=l:x=l,l=Math.floor((d+x)/2),i=e[Math.floor(l)]}n||(t===e[d].value?(i=e[d],n=!0):t===e[x].value?(i=e[x],n=!0):t<e[d].value?n=!1:t>e[d].value&&(t<e[x].value?(i=e[d],n=!0):x===r-1?n=!1:(i=e[x],n=!0))),n?(h[o]=i.mappedColor[0],c[o]=i.mappedColor[1],u[o]=i.mappedColor[2],p[o]=i.mappedColor[3]):h[o]=c[o]=u[o]=p[o]=0}return n.pixels=[h,c,u],n.mask=p,n.pixelType="u8",n.maskIsAlpha=d,n}function g(e,n,i=!1){const o=1e-5,r=new Float32Array(3*l),s=n.length;for(let a=0;a<l;a++)r[3*a]=e[2*a]??t-1,r[3*a+1]=e[2*a+1]??t,r[3*a+2]=n[a]??0,a<s&&(a>0&&(r[3*a]-=o),e[2*a+1]!==e[2*a]&&(a<s-1||!i)&&(r[3*a+1]-=o));return r}function m(t,l){if(!o(t))return null;const{width:i,height:r}=t,{inputRanges:s,outputValues:a,outputPixelType:f,noDataRanges:h,allowUnmatched:c,replacementValue:u,isLastInputRangeInclusive:p}=l,d=t.pixels[0],x=n.createEmptyBand(f,d.length),g=t.mask,m=new Uint8Array(i*r);g?m.set(g):m.fill(255);const y=t.pixelType.startsWith("f")?1e-6:0,w=s.map(t=>t-y);w[0]=s[0],w[w.length-1]=s[s.length-1]+(p?1e-6:0);const k=s.length/2,[M,A]=e(f);for(let e=0;e<r;e++)for(let t=0;t<i;t++){const n=e*i+t;if(m[n]){const t=d[n];let e=!1;for(let l=k-1;l>=0;l--)if(t===s[2*l]||t>w[2*l]&&t<w[2*l+1]){x[n]=a[l],e=!0;break}e||(c?x[n]=t>A?A:t<M?M:u??t:m[n]=0)}}const U=h?.length;if(U)for(let e=0;e<r;e++)for(let t=0;t<i;t++){const n=e*i+t;if(!g||g[n]){const t=d[n];for(let e=0;e<U;e+=2)if(t>=h[e]&&t<=h[e+1]){x[n]=0,m[n]=0;break}}}return new n({width:i,height:r,pixelType:f,pixels:[x],mask:m})}function y(t,e,n,l){const i=null!=n&&n.length>=2?new Set(n):null,o=1===n?.length?n[0]:null,r=!!e?.length;for(let s=0;s<t.length;s++)if(l[s]){const n=t[s];if(r){let t=!1;for(let l=0;l<e.length;l+=2)if(n>=e[l]&&n<=e[l+1]){t=!0;break}t||(l[s]=0)}l[s]&&(n===o||i?.has(n))&&(l[s]=0)}}function w(t,e){const n=t[0].length;e??=new Uint8Array(n).fill(255);for(let l=0;l<n;l++)if(e[l]){let n=!1;for(let e=0;e<t.length;e++)if(t[e][l]){n=!0;break}n||(e[l]=0)}return e}function k(t,e){const n=t[0].length;e??=new Uint8Array(n).fill(255);for(let l=0;l<n;l++)if(e[l]){let n=!1;for(let e=0;e<t.length;e++)if(0===t[e][l]){n=!0;break}n&&(e[l]=0)}return e}function M(t,e){if(!o(t))return null;const{width:l,height:i,pixels:r}=t,s=l*i,a=new Uint8Array(s);t.mask?a.set(t.mask):a.fill(255);const f=r.length,{includedRanges:h,noDataValues:u,outputPixelType:p,matchAll:d,lookups:x}=e;if(x){const t=[];for(let e=0;e<f;e++){const n=x[e],l=c(r[e],a,n.lut,n.offset||0,"u8");t.push(l)}1===t.length?a.set(t[0]):d?w(t,a):k(t,a)}else if(d){const t=[];for(let e=0;e<f;e++){const n=new Uint8Array(s);n.set(a),y(r[e],h?.slice(2*e,2*e+2),u?.[e],n),t.push(n)}1===t.length?a.set(t[0]):w(t,a)}else for(let n=0;n<f;n++)y(r[n],h?.slice(2*n,2*n+2),u?.[n],a);return new n({width:l,height:i,pixelType:p,pixels:r,mask:a})}function A(t){const{srcPixelType:l,inputRanges:i,outputValues:o,allowUnmatched:r,noDataRanges:s,isLastInputRangeInclusive:a,outputPixelType:f}=t;if("u8"!==l&&"s8"!==l&&"u16"!==l&&"s16"!==l)return null;const h=l.includes("16")?65536:256,c=l.includes("s")?-h/2:0,u=n.createEmptyBand(f,h),p=new Uint8Array(h);r&&p.fill(255);const[d,x]=e(f);if(i?.length&&o?.length){const t=1e-6,e=i.map(e=>e-t);e[0]=i[0],a&&(e[e.length-1]=i[i.length-1]);for(let n=0;n<e.length;n++){const t=o[n]>x?x:o[n]<d?d:o[n],l=Math.ceil(e[2*n]-c),r=i[2*n+1]===i[2*n]?l:Math.floor(e[2*n+1]-c);for(let e=l;e<=r;e++)u[e]=t,p[e]=255}}if(s?.length)for(let e=0;e<s.length;e++){const t=Math.ceil(s[2*e]-c),n=Math.floor(s[2*e+1]-c);for(let e=t;e<=n;e++)p[e]=0}return{lut:u,offset:c,mask:p}}function U(t,e,n){if("u8"!==t&&"s8"!==t&&"u16"!==t&&"s16"!==t)return null;const l=t.includes("16")?65536:256,i=t.includes("s")?-l/2:0,o=new Uint8Array(l);if(e)for(let r=0;r<e.length;r++){const t=Math.ceil(e[2*r]-i),n=Math.floor(e[2*r+1]-i);for(let e=t;e<=n;e++)o[e]=255}else o.fill(255);if(n)for(let r=0;r<n.length;r++)o[n[r]-i]=0;return{lut:o,offset:i}}function b(t,e,n,l,i,o,r,s){return{xmin:i<=n*t?0:i<n*t+t?i-n*t:t,ymin:o<=l*e?0:o<l*e+e?o-l*e:e,xmax:i+r<=n*t?0:i+r<n*t+t?i+r-n*t:t,ymax:o+s<=l*e?0:o+s<l*e+e?o+s-l*e:e}}function T(t,e){if(!t||0===t.length)return null;const n=t.find(t=>t.pixelBlock);if(null==n?.pixelBlock)return null;const l=(n.extent.xmax-n.extent.xmin)/n.pixelBlock.width,i=(n.extent.ymax-n.extent.ymin)/n.pixelBlock.height,o=.01*Math.min(l,i),r=t.sort((t,e)=>Math.abs(t.extent.ymax-e.extent.ymax)>o?e.extent.ymax-t.extent.ymax:Math.abs(t.extent.xmin-e.extent.xmin)>o?t.extent.xmin-e.extent.xmin:0),s=Math.min.apply(null,r.map(t=>t.extent.xmin)),a=Math.min.apply(null,r.map(t=>t.extent.ymin)),f=Math.max.apply(null,r.map(t=>t.extent.xmax)),h=Math.max.apply(null,r.map(t=>t.extent.ymax)),c={x:Math.round((e.xmin-s)/l),y:Math.round((h-e.ymax)/i)},u={width:Math.round((f-s)/l),height:Math.round((h-a)/i)},p={width:Math.round((e.xmax-e.xmin)/l),height:Math.round((e.ymax-e.ymin)/i)};if(Math.round(u.width/n.pixelBlock.width)*Math.round(u.height/n.pixelBlock.height)!==r.length||c.x<0||c.y<0||u.width<p.width||u.height<p.height)return null;return{extent:e,pixelBlock:S(r.map(t=>t.pixelBlock),u,{clipOffset:c,clipSize:p})}}function B(t,e,n,l,i,o){const{width:r,height:s}=n.block,{x:a,y:f}=n.offset,{width:h,height:c}=n.mosaic,u=b(r,s,l,i,a,f,h,c);let p=0,d=0;if(o){const t=o.hasGCSSShiftTransform?360:o.halfWorldWidth??0,e=r*o.resolutionX,n=o.startX+l*e;n<t&&n+e>t?d=o.rightPadding:n>=t&&(p=o.leftMargin-o.rightPadding,d=0)}if(u.xmax-=d,"number"!=typeof e)for(let x=u.ymin;x<u.ymax;x++){const n=(i*s+x-f)*h+(l*r-a)+p,o=x*r;for(let l=u.xmin;l<u.xmax;l++)t[n+l]=e[o+l]}else for(let x=u.ymin;x<u.ymax;x++){const n=(i*s+x-f)*h+(l*r-a)+p;for(let l=u.xmin;l<u.xmax;l++)t[n+l]=e}}function S(t,e,l={}){const{clipOffset:i,clipSize:r,alignmentInfo:s,blockWidths:a}=l;if(a)return v(t,e,{blockWidths:a});const f=t.find(t=>o(t));if(null==f)return null;const h=r?r.width:e.width,c=r?r.height:e.height,u=f.width,p=f.height,d=e.width/u,x=e.height/p,g={offset:i||{x:0,y:0},mosaic:r||e,block:{width:u,height:p}},m=f.pixelType,y=n.getPixelArrayConstructor(m),w=f.pixels.length,k=[];let M,A;for(let n=0;n<w;n++){A=new y(h*c);for(let e=0;e<x;e++)for(let l=0;l<d;l++){const i=t[e*d+l];o(i)&&(M=i.pixels[n],B(A,M,g,l,e,s))}k.push(A)}const U=t.some(t=>null==t||null!=t.mask&&t.mask.length>0),b=t.some(t=>t?.bandMasks&&t.bandMasks.length>1),T=U?new Uint8Array(h*c):void 0,S=b?[]:void 0;if(T){for(let e=0;e<x;e++)for(let n=0;n<d;n++){const l=t[e*d+n],i=null!=l?l.mask:null;B(T,null!=i?i:l?255:0,g,n,e,s)}if(S)for(let e=0;e<w;e++){const n=new Uint8Array(h*c);for(let l=0;l<x;l++)for(let i=0;i<d;i++){const o=t[l*d+i],r=o?.bandMasks?.[e]??o?.mask;B(n,null!=r?r:o?255:0,g,i,l,s)}S.push(n)}}const C=new n({width:h,height:c,pixels:k,pixelType:m,bandMasks:S,mask:T});return C.updateStatistics(),C}function v(t,e,l){const i=t.find(t=>null!=t);if(null==i)return null;const r=t.some(t=>null==t||!!t.mask),{width:s,height:a}=e,f=r?new Uint8Array(s*a):null,{blockWidths:h}=l,c=[],u=i.getPlaneCount(),p=n.getPixelArrayConstructor(i.pixelType);if(r)for(let n=0,y=0;n<t.length;y+=h[n],n++){const e=t[n];if(!o(e))continue;const l=e.mask;for(let t=0;t<a;t++)for(let i=0;i<h[n];i++)f[t*s+i+y]=null==l?255:l[t*e.width+i]}const d=t.some(t=>t?.bandMasks&&t.bandMasks.length>1),x=d?[]:void 0,g=s*a;for(let n=0;n<u;n++){const e=new p(g),l=d?new Uint8Array(g):void 0;for(let i=0,r=0;i<t.length;r+=h[i],i++){const f=t[i];if(!o(f))continue;const c=f.pixels[n];if(null!=c){for(let t=0;t<a;t++)for(let n=0;n<h[i];n++)e[t*s+n+r]=c[t*f.width+n];if(l){const t=f.bandMasks?.[n]??f.mask;for(let e=0;e<a;e++)for(let n=0;n<h[i];n++)l[e*s+n+r]=t?t[e*f.width+n]:255}}}c.push(e),x&&l&&x.push(l)}const m=new n({width:s,height:a,mask:f,bandMasks:x,pixels:c,pixelType:i.pixelType});return m.updateStatistics(),m}function C(t,e,n){if(!o(t))return null;const{width:l,height:i}=t,r=e.x,s=e.y,a=n.width+r,f=n.height+s;if(r<0||s<0||a>l||f>i)return t;if(0===r&&0===s&&a===l&&f===i)return t;t.mask||(t.mask=new Uint8Array(l*i));const h=t.mask;for(let o=0;o<i;o++){const t=o*l;for(let e=0;e<l;e++)h[t+e]=o<s||o>=f||e<r||e>=a?0:1}return t.updateStatistics(),t}function I(t){if(!o(t))return null;const e=t.clone(),{width:n,height:l,pixels:i}=t,r=i[0],s=e.pixels[0],a=t.mask;for(let o=2;o<l-1;o++){const t=new Map;for(let l=o-2;l<o+2;l++)for(let e=0;e<4;e++){const i=l*n+e;_(t,r[i],a?a[i]:1)}s[o*n]=R(t),s[o*n+1]=s[o*n+2]=s[o*n];let e=3;for(;e<n-1;e++){let l=(o-2)*n+e+1;_(t,r[l],a?a[l]:1),l=(o-1)*n+e+1,_(t,r[l],a?a[l]:1),l=o*n+e+1,_(t,r[l],a?a[l]:1),l=(o+1)*n+e+1,_(t,r[l],a?a[l]:1),l=(o-2)*n+e-3,P(t,r[l],a?a[l]:1),l=(o-1)*n+e-3,P(t,r[l],a?a[l]:1),l=o*n+e-3,P(t,r[l],a?a[l]:1),l=(o+1)*n+e-3,P(t,r[l],a?a[l]:1),s[o*n+e]=R(t)}s[o*n+e+1]=s[o*n+e]}for(let o=0;o<n;o++)s[o]=s[n+o]=s[2*n+o],s[(l-1)*n+o]=s[(l-2)*n+o];return e.updateStatistics(),e}function R(t){if(0===t.size)return 0;let e=0,n=-1,l=0;const i=t.keys();let o=i.next();for(;!o.done;)l=t.get(o.value),l>e&&(n=o.value,e=l),o=i.next();return n}function P(t,e,n){if(0===n)return;const l=t.get(e);1===l?t.delete(e):t.set(e,l-1)}function _(t,e,n){0!==n&&t.set(e,t.has(e)?t.get(e)+1:1)}function F(t,e,l){let{x:i,y:r}=e;const{width:s,height:a}=l;if(0===i&&0===r&&a===t.height&&s===t.width)return t;const{width:f,height:h}=t,c=Math.max(0,r),u=Math.max(0,i),p=Math.min(i+s,f),d=Math.min(r+a,h);if(p<0||d<0||!o(t))return null;i=Math.max(0,-i),r=Math.max(0,-r);const{pixels:x}=t,g=s*a,m=x.length,y=[];for(let o=0;o<m;o++){const e=x[o],l=n.createEmptyBand(t.pixelType,g);for(let t=c;t<d;t++){const n=t*f;let o=(t+r-c)*s+i;for(let t=u;t<p;t++)l[o++]=e[n+t]}y.push(l)}const w=new Uint8Array(g),k=t.mask;for(let n=c;n<d;n++){const t=n*f;let e=(n+r-c)*s+i;for(let n=u;n<p;n++)w[e++]=k?k[t+n]:1}const M=new n({width:l.width,height:l.height,pixelType:t.pixelType,pixels:y,mask:w});return M.updateStatistics(),M}function W(t,e=!0){if(!o(t))return null;const{pixels:l,width:i,height:r,mask:s,pixelType:a}=t,f=[],h=Math.round(i/2),c=Math.round(r/2),u=r-1,p=i-1;for(let o=0;o<l.length;o++){const t=l[o],s=n.createEmptyBand(a,h*c);let d=0;for(let n=0;n<r;n+=2)for(let l=0;l<i;l+=2){const o=t[n*i+l];if(e){const e=l===p?o:t[n*i+l+1],r=n===u?o:t[n*i+l+i],a=l===p?r:n===u?e:t[n*i+l+i+1];s[d++]=(o+e+r+a)/4}else s[d++]=o}f.push(s)}let d=null;if(null!=s){d=new Uint8Array(h*c);let t=0;for(let n=0;n<r;n+=2)for(let l=0;l<i;l+=2){const o=s[n*i+l];if(e){const e=l===p?o:s[n*i+l+1],r=n===u?o:s[n*i+l+i],a=l===p?r:n===u?e:s[n*i+l+i+1];d[t++]=o*e*r*a?1:0}else d[t++]=o}}return new n({width:h,height:c,pixelType:a,pixels:f,mask:d})}function E(t,e,n=0,l=!0){if(!o(t))return null;const{width:i,height:r}=e;let{width:s,height:a}=t;const f=new Map,h={x:0,y:0},c=1+n;let u=t;for(let o=0;o<c;o++){const t=Math.ceil(s/i),n=Math.ceil(a/r);for(let l=0;l<n;l++){h.y=l*r;for(let n=0;n<t;n++){h.x=n*i;const t=F(u,h,e);f.set(`${o}/${l}/${n}`,t)}}o<c-1&&(u=W(u,l)),s=Math.round(s/2),a=Math.round(a/2)}return f}function D(t){const{pixelBlock:e,tileSize:n,level:l,row:i,col:r,useBilinear:s}=t;if(!o(e))return null;const{width:a,height:f}=n,h=2**l,c=h*a,u=h*f;let p=F(e,{y:i*u,x:r*c},{width:c,height:u});if(!p)return null;for(let o=l;o>0;o--)p=W(p,s);return p}function N(t,e,n,l,i=0){const{width:o,height:r}=t,{width:s,height:a}=e,f=l.cols,h=l.rows,c=Math.ceil(s/f-.1/f),u=Math.ceil(a/h-.1/h);let p,d,x,g,m,y,w;const k=c*f,M=k*u*h,A=new Float32Array(M),U=new Float32Array(M),b=new Uint32Array(M),T=new Uint32Array(M);let B,S,v=0;for(let C=0;C<u;C++)for(let t=0;t<c;t++){p=12*(C*c+t),d=n[p],x=n[p+1],g=n[p+2],m=n[p+3],y=n[p+4],w=n[p+5];for(let e=0;e<h;e++){v=(C*h+e)*k+t*f,S=(e+.5)/h;for(let t=0;t<e;t++)B=(t+.5)/f,A[v+t]=(d*B+x*S+g)*o+i,U[v+t]=(m*B+y*S+w)*r+i,b[v+t]=Math.floor(A[v+t]),T[v+t]=Math.floor(U[v+t])}p+=6,d=n[p],x=n[p+1],g=n[p+2],m=n[p+3],y=n[p+4],w=n[p+5];for(let e=0;e<h;e++){v=(C*h+e)*k+t*f,S=(e+.5)/h;for(let t=e;t<f;t++)B=(t+.5)/f,A[v+t]=(d*B+x*S+g)*o+i,U[v+t]=(m*B+y*S+w)*r+i,b[v+t]=Math.floor(A[v+t]),T[v+t]=Math.floor(U[v+t])}}return{offsets_x:A,offsets_y:U,offsets_xi:b,offsets_yi:T,gridWidth:k}}function j(t,e){const{coefficients:n,spacing:l}=e,{offsets_x:i,offsets_y:o,gridWidth:r}=N(t,t,n,{rows:l[0],cols:l[1]}),{width:s,height:a}=t,f=new Float32Array(s*a),h=180/Math.PI;for(let c=0;c<a;c++)for(let t=0;t<s;t++){const e=c*r+t,n=0===c?e:e-r,l=c===a-1?e:e+r,u=i[n]-i[l],p=o[l]-o[n];if(isNaN(u)||isNaN(p))f[c*s+t]=90;else{let e=Math.atan2(p,u)*h;e=(360+e)%360,f[c*s+t]=e}}return f}function O(t,e,l,i,r="nearest"){if(!o(t))return null;"majority"===r&&(t=I(t));const{pixels:s,mask:a,bandMasks:f,pixelType:h}=t,c=t.width,u=t.height,p=n.getPixelArrayConstructor(h),d=s.length,{width:x,height:g}=e;let m=!1;for(let n=0;n<l.length;n+=3)-1===l[n]&&-1===l[n+1]&&-1===l[n+2]&&(m=!0);const{offsets_x:y,offsets_y:w,offsets_xi:k,offsets_yi:M,gridWidth:A}=N({width:c,height:u},e,l,i,"majority"===r?.5:0);let U;const b=(t,e,n,l)=>{const i=t instanceof Float32Array||t instanceof Float64Array?0:.5;for(let o=0;o<g;o++){U=o*A;for(let r=0;r<x;r++){if(y[U]<0||w[U]<0)t[o*x+r]=0;else if(l)t[o*x+r]=e[k[U]+M[U]*c];else{const l=Math.floor(y[U]),s=Math.floor(w[U]),a=Math.ceil(y[U]),f=Math.ceil(w[U]),h=y[U]-l,u=w[U]-s;if(!n||n[l+s*c]&&n[a+s*c]&&n[l+f*c]&&n[a+f*c]){const n=(1-h)*e[l+s*c]+h*e[a+s*c],p=(1-h)*e[l+f*c]+h*e[a+f*c];t[o*x+r]=(1-u)*n+u*p+i}else t[o*x+r]=e[k[U]+M[U]*c]}U++}}},T=[];let B;const S=f?.length===d,v=[];for(let n=0;n<d;n++){if(S){const t=new Uint8Array(x*g);b(t,f[n],f[n],!0),v.push(t)}B=new p(x*g),b(B,s[n],S?f[n]:a,"nearest"===r||"majority"===r),T.push(B)}const C=new n({width:x,height:g,pixelType:h,pixels:T,bandMasks:S?v:void 0});if(null!=a)C.mask=new Uint8Array(x*g),b(C.mask,a,a,!0);else if(m){C.mask=new Uint8Array(x*g);for(let t=0;t<x*g;t++)C.mask[t]=y[t]<0||w[t]<0?0:1}return C.updateStatistics(),C}function z(t){const{pixelBlock:e,extent:n,fieldNames:l,skipFactor:o,skipSpatialReference:r=!1,pixelIdOffset:s=0}=t,a=[],{width:f,height:h,pixels:c,mask:u}=e,p=t.imageRowSize??f,d=n.width/f,x=n.height/h,g=c.length,m=Math.floor(o/2),{xmin:y,ymax:w}=n,k=r?void 0:n.spatialReference.toJSON();for(let M=m;M<h;M+=o)for(let t=m;t<f;t+=o){const e=M*f+t;if(!u||u[e]){const n={x:y+(t+.5)*d,y:w-(M+.5)*x,spatialReference:k},o={[i]:s+M*p+t};for(let t=0;t<g;t++)o[l[t+1]]=c[t][e];a.push({geometry:n,attributes:o})}}return a}function L(t,e){const{width:n,height:l,pixels:i,mask:o}=t,r=i[0];let s=0;for(let a=0;a<l;a++){let t=a*n;for(let l=0;l<n;l++,t++)o&&!o[t]||(e[r[t]]++,s++)}return s}function V(t,e){const{width:n,height:l,pixels:i,mask:o}=t,r=e.width/n,s=e.height/l,{xmin:a,ymax:f}=e,h=e.spatialReference.toJSON(),c=[];for(let u=0;u<l;u++)for(let t=0;t<n;t++){const e=u*n+t;if(!o||o[e]){const n={x:a+(t+.5)*r,y:f-(u+.5)*s,spatialReference:h},l=i.map(t=>t[e]);c.push({location:n,value:l})}}return c}function $(t,e,l){const{attributeTable:i}=e;if(!i)return t;const o=i.fields.find(t=>t.name.toLowerCase()===l.toLowerCase()),r=i.fields.find(t=>"value"===t.name.toLowerCase());if(!o||!r)return t;const[s]=t.pixels,a="single"===o.type?"f32":"double"===o.type||"big-integer"===o.type?"f64":"small-integer"===o.type?"s16":"s32",f=s.length,h=new("f32"===a?Float32Array:"f64"===a?Float64Array:"s16"===a?Int16Array:Int32Array)(f),c=new Map;for(const n of i.features){const t=n.attributes[r.name],e=n.attributes[o.name];c.set(t,e)}const u=t.mask??new Uint8Array(f).fill(255);for(let n=0;n<f;n++)if(u[n]){const t=c.get(s[n]);null==t?u[n]=0:h[n]=t}return new n({width:t.width,height:t.height,pixels:[h],mask:u,pixelType:a})}export{O as approximateTransform,F as clip,D as clipTile,f as colorize,s as compositeBands,z as convertPixelBlockToFeatures,L as countCategoricalPixels,a as createColormapLUT,U as createMaskLUT,g as createRangeMaps,A as createRemapLUT,r as extractBands,b as getClipBounds,j as getLocalArithmeticNorthRotations,V as getValidPixels,d as highlightPixels,N as interpolateOffsets,o as isValidPixelBlock,c as lookupBandValues,h as lookupPixels,$ as mapPixelValueToAttribute,M as mask,k as matchAnyMask,l as maxMapSizeGpu,S as mosaic,T as mosaicPixelData,i as pixelIdFieldName,m as remap,x as remapColor,I as resampleByMajority,u as selectBySingleBandRange,p as selectByXYMask,C as setValidBoundary,E as split};