UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) • 19.8 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{isSome as e}from"../../../core/arrayUtils.js";import t from"../../../core/Error.js";import{getMetersPerUnitForSR as n}from"../../../core/unitUtils.js";import i from"../../../geometry/Extent.js";import{P as o,a as r,g as s,h as a,j as l}from"../../../chunks/pe.js";import c from"../../../geometry/Point.js";import f from"../../../geometry/Polygon.js";import{canProjectWithoutEngine as u,isLoaded as m,load as x,getTransformation as h,project as p}from"../../../geometry/projection.js";import g from"../../../geometry/SpatialReference.js";import{getInfo as y}from"../../../geometry/support/spatialReferenceUtils.js";var d;function w(e,t,n){return!u(e,t,n)}function M(e,n,i){const o=w(e,n,i);if(o&&!m())throw new t("rasterprojectionhelper-project","projection engine is not loaded");return o}!function(e){e[e.None=0]="None",e[e.North=1]="North",e[e.South=2]="South",e[e.Both=3]="Both"}(d||(d={}));const R=(e,t,n,i=0)=>{if(1===n[0])return[0,0];let o=1,r=-1,s=1,a=-1;for(let g=0;g<e.length;g+=2)isNaN(e[g])||(o=o>e[g]?e[g]:o,r=r>e[g]?r:e[g],s=s>e[g+1]?e[g+1]:s,a=a>e[g+1]?a:e[g+1]);const{cols:l,rows:c}=t,f=(r-o)/l/n[0],u=(a-s)/c/n[1],m=2*i;let x=0,h=!1,p=[0,0];for(let g=0;g<l-3;g++){for(let t=0;t<c-3;t++){const n=g*c*2+2*t,i=(e[n]+e[n+4]+e[n+4*c]+e[n+4*c+4])/4,o=(e[n+1]+e[n+5]+e[n+4*c+1]+e[n+4*c+5])/4,r=Math.abs((i-e[n+2*c+2])/f),s=Math.abs((o-e[n+2*c+3])/u);if(r+s>x&&(x=r+s,p=[r,s]),m&&x>m){h=!0;break}}if(h)break}return p},S={3395:20037508.342789244,3410:17334193.943686873,3857:20037508.342788905,3975:17367530.445161372,4087:20037508.342789244,4088:20015108.787169147,6933:17367530.445161372,32662:20037508.342789244,53001:20015086.79602057,53002:10007543.39801029,53003:20015086.79602057,53004:20015086.79602057,53016:14152803.599503474,53017:17333573.624304302,53034:20015086.79602057,53079:20015114.352186374,53080:20015114.352186374,54001:20037508.342789244,54002:10018754.171394624,54003:20037508.342789244,54004:20037508.342789244,54016:14168658.027268292,54017:17367530.44516137,54034:20037508.342789244,54079:20037508.342789244,54080:20037508.342789244,54100:20037508.342789244,54101:20037508.342789244},P=32,b=4,G=b,k=new Map,E=new Map,N=500,T=39.37,v=96;let C=null;async function j(){C&&m()||(m()||await x(),C=await import("../../../geometry/geometryEngine.js"))}function _(e,t,n){M(e.spatialReference,t);return n?h(t,e.spatialReference,e):h(e.spatialReference,t,e)}function z(e,t,n,o=null){const r=e.spatialReference;if(!r||!t||r.equals(t))return e;M(r,t,o);const s=n.center,a=new i({xmin:s.x-e.x/2,xmax:s.x+e.x/2,ymin:s.y-e.y/2,ymax:s.y+e.y/2,spatialReference:r}),l=p(a,t,o),c=te(t);return null==l||null!=c&&l.width>=c?L(e,r,t):{x:l.width,y:l.height}}function L(e,t,i){const o=n(t)/n(i);return{x:e.x*o,y:e.y*o}}function I(e,i,o){const{spatialReference:r}=o;if(!r||!i||r.equals(i))return e;if(r.isGeographic&&i.isGeographic)return L(e,r,i);if(M(r,i),!C)throw new t("raster-projection-helper:project-dataset-resolution","geometry engine is not loaded");let{x:s,y:a}=e;const l=(s+a)/2*n(r);let c=1;l>30&&(c=30/l,s*=c,a*=c);const u=256,m=s*u/2,x=a*u/2,{x:h,y:g}=o.center,y=[];for(let t=0;t<=u;t++)y.push([h-m,g-x+t*a]);for(let t=1;t<=u;t++)y.push([h-m+t*s,g+x]);for(let t=1;t<=u;t++)y.push([h+m,g+x-t*a]);for(let t=1;t<u;t++)y.push([h+m-t*s,g-x]);y.push(y[0]);const d=new f({rings:[y],spatialReference:r}),w=p(d,i);if(!w)return L(e,r,i);const R=w.extent,S=te(i);if(null==R||null!=S&&R.width>=S)return L(e,r,i);const P=C.planarArea(w),b=s*a*u*u,G=Math.sqrt(P/b)/c,k={x:R.width/c/u,y:R.height/c/u},E={x:s*G,y:a*G},N=k.x*k.y;return Math.abs(N-E.x*E.y)/N<.1?k:E}function W(e,t){return("number"==typeof e?e:(e.x+e.y)/2)*n(t)*v*T}function O(e,t){const{pixelSize:n,extent:i}=e;return W(I(n,t,i),t)}function A(e,t=.01){return n(e)?t/n(e):0}function B(e,t,n=null,i=!0){const o=e.spatialReference;if(o.equals(t))return e;M(o,t,n);const r=p(e,t,n);return i&&r?(F([e],[r],o,t),r):r}function F(e,t,n,i){const o=ne(n,!0),r=ne(i,!0),s=A(n,N),a=A(i,N);if(s&&null!=o&&null!=r)for(let l=0;l<e.length;l++){const n=t[l];if(!n)continue;const{x:i}=e[l],{x:c}=n;c>=r[1]-a&&Math.abs(i-o[0])<s?n.x-=r[1]-r[0]:c<=r[0]+a&&Math.abs(i-o[1])<s&&(n.x+=r[1]-r[0])}}function q(e){const{inSR:t,outSR:n,datumTransformation:i,preferPE:o}=e;if(t.equals(n)){const{points:t}=D(e,null);return t}if(t.isWebMercator&&n.isWGS84||t.isWGS84&&n.isWebMercator)return U(e);if(M(t,n,i)&&o){if(t.isGeographic)return J(e);if(null!=X(t))return J(e)}return Y(e)}function Y(e){const{points:t}=D(e,null),{inSR:n,outSR:i,datumTransformation:o}=e,r=t.map((e=>new c(e[0],e[1],n))),s=p(r,i,o);return o&&F(r,s,n,i),s.map((e=>e?[e.x,e.y]:[NaN,NaN]))}function J(e){const{inSR:t,outSR:n,datumTransformation:i}=e,l=X(t),{points:c,mask:f}=D(e,l);if(!t.isGeographic){const e=t.wkid?o.coordsys(t.wkid):o.fromString(t.isGeographic?r.PE_TYPE_GEOGCS:r.PE_TYPE_PROJCS,t.wkt2||t.wkt);s.projToGeog(e,c.length,c)}if(null!=i&&i.steps.length){let e;const t=179.9955;if(n.isGeographic&&(e=c.map((([e])=>e>t?1:e<-179.9955?-1:0))),i.steps.forEach((e=>{const t=e.wkid?o.geogtran(e.wkid):o.fromString(r.PE_TYPE_GEOGTRAN,e.wkt);a.geogToGeog(t,c.length,c,null,e.isInverse?r.PE_TRANSFORM_2_TO_1:r.PE_TRANSFORM_1_TO_2)})),e)for(let n=0;n<c.length;n++){const i=e[n],o=c[n][0],r=o>t?1:o<-179.9955?-1:0;i&&r&&i!==r&&(c[n][0]=i>0?o+360:o-360)}}if(!n.isGeographic){const e=X(n,!0),t=null!=e&&e.isEnvelope?[e.bbox[1],e.bbox[3]]:[-90,90];H(c,t);const i=n.wkid?o.coordsys(n.wkid):o.fromString(n.isGeographic?r.PE_TYPE_GEOGCS:r.PE_TYPE_PROJCS,n.wkt2||n.wkt);s.geogToProj(i,c.length,c)}let u=c;if(f&&c.length!==f.length){u=[];for(let e=0,t=0;e<f.length;e++)f[e]?u.push(c[t++]):u.push([NaN,NaN])}return u}function U(e){const{cols:t,rows:n,xres:i,yres:o,usePixelCenter:r,inSR:s,outSR:a}=e;let{xmin:l,ymax:f}=e;r&&(l+=i/2,f-=o/2);const u=[],m=[],x=Math.max(t,n);for(let g=0;g<x;g++){const e=l+i*Math.min(t,g),r=f-o*Math.min(n,g),x=p(new c({x:e,y:r,spatialReference:s}),a);g<=t&&u.push(x.x),g<=n&&m.push(x.y)}const h=[];for(let c=0;c<t;c++)for(let e=0;e<n;e++)h.push([u[c],m[e]]);return h}function X(e,t=!1){let n=e.wkid||e.wkt2||e.wkt;if(!n||e.isGeographic)return null;if(n=String(n),k.has(n)){const e=k.get(n);return t?e?.gcs:e?.pcs}const i=e.wkid?o.coordsys(e.wkid):o.fromString(e.isGeographic?r.PE_TYPE_GEOGCS:r.PE_TYPE_PROJCS,e.wkt2||e.wkt),s=K(i,A(e,1e-4)),a=K(i,0,!0);return k.set(n,{pcs:s,gcs:a}),t?a:s}function K(e,t=0,n=!1){const i=l.generate(e),o=n?e.horizonGcsGenerate():e.horizonPcsGenerate();if(!i||!o?.length)return null;let r=!1,s=o.find((e=>1===e.getInclusive()&&1===e.getKind()));if(!s){if(s=o.find((e=>1===e.getInclusive()&&0===e.getKind())),!s)return null;r=!0}const a=n?0:(2===i.getNorthPoleLocation()?1:0)|(2===i.getSouthPoleLocation()?2:0),c=i.isPannableRectangle(),f=s.getCoord();if(r)return{isEnvelope:r,isPannable:c,vertices:f,coef:null,bbox:[f[0][0]-t,f[0][1]-t,f[1][0]+t,f[1][1]+t],poleLocation:a};let u=0;const m=[];let[x,h]=f[0],[p,g]=f[0];for(let l=0,y=f.length;l<y;l++){u++,u===y&&(u=0);const[e,t]=f[l],[n,i]=f[u];if(i===t)m.push([e,n,t,i,2]);else{const o=(n-e)/(i-t||1e-4),r=e-o*t;t<i?m.push([o,r,t,i,0]):m.push([o,r,i,t,1])}x=x<e?x:e,h=h<t?h:t,p=p>e?p:e,g=g>t?g:t}return{isEnvelope:!1,isPannable:c,vertices:f,coef:m,bbox:[x,h,p,g],poleLocation:a}}function D(e,t){const n=[],{cols:i,rows:o,xres:r,yres:s,usePixelCenter:a}=e;let{xmin:l,ymax:c}=e;if(a&&(l+=r/2,c-=s/2),null==t){for(let e=0;e<i;e++)for(let t=0;t<o;t++)n.push([l+r*e,c-s*t]);return{points:n}}const f=new Uint8Array(i*o);if(t.isEnvelope){const{bbox:[e,a,u,m]}=t;for(let x=0,h=0;x<i;x++){const i=l+r*x,p=t.isPannable||i>=e&&i<=u;for(let e=0;e<o;e++,h++){const t=c-s*e;p&&t>=a&&t<=m&&(n.push([i,t]),f[h]=1)}}return{points:n,mask:f}}const u=t.coef,m=[];for(let x=0;x<o;x++){const e=c-s*x,t=[],n=[];for(let o=0;o<u.length;o++){const[i,r,s,a,l]=u[o];if(e===s&&s===a)t.push(i),t.push(r),n.push(2),n.push(2);else if(e>=s&&e<=a){const o=i*e+r;t.push(o),n.push(l)}}let i=t;if(t.length>2){let e=2===n[0]?0:n[0],o=t[0];i=[];for(let r=1;r<n.length;r++)2===n[r]&&r!==n.length-1||(n[r]!==e&&(i.push(0===e?Math.min(o,t[r-1]):Math.max(o,t[r-1])),e=n[r],o=t[r]),r===n.length-1&&i.push(0===n[r]?Math.min(o,t[r]):Math.max(o,t[r])));i.sort(((e,t)=>e-t))}else t[0]>t[1]&&(i=[t[1],t[0]]);m.push(i)}for(let x=0,h=0;x<i;x++){const e=l+r*x;for(let t=0;t<o;t++,h++){const i=c-s*t,o=m[t];if(2===o.length)e>=o[0]&&e<=o[1]&&(n.push([e,i]),f[h]=1);else if(o.length>2){let t=!1;for(let n=0;n<o.length;n+=2)if(e>=o[n]&&e<=o[n+1]){t=!0;break}t&&(n.push([e,i]),f[h]=1)}}}return{points:n,mask:f}}function H(e,t){const[n,i]=t;for(let o=0;o<e.length;o++){const t=e[o][1];(t<n||t>i)&&(e[o]=[NaN,NaN])}}function Q(e,t){const n=te(e[0].spatialReference);if(e.length<2||null==n)return e[0];if(t=t??A(e[0].spatialReference),1===(e=e.filter((e=>e.width>t))).length)return e[0];let{xmin:o,xmax:r,ymin:s,ymax:a}=e[0];for(let i=1;i<e.length;i++){const t=e[i];r=t.xmax+n*i,s=Math.min(s,t.ymin),a=Math.max(a,t.ymax)}return new i({xmin:o,xmax:r,ymin:s,ymax:a,spatialReference:e[0].spatialReference})}function V(t,n,o=null,r=!0){const s=t.spatialReference;if(s.equals(n))return t;const a=oe(t),l=te(s,!0),c=te(n);if(0===a||null==l||null==c){const e=ee(t,n,o,r);if(null==l&&null!=c&&Math.abs(e.width-c)<A(n)&&m()){const i=X(s);if(null!=i&&i.poleLocation===d.None&&t.width<(i.bbox[2]-i.bbox[0])/2)return $(t,n)||e}return e}const f=t.clone().normalize();if(1===f.length&&t.xmax<l&&t.xmax-l/2>A(s)){const{xmin:e,xmax:n}=t;for(let o=0;o<=a;o++){const r=0===o?e:-l/2,c=o===a?n-l*o:l/2;f[o]=new i({xmin:r,xmax:c,ymin:t.ymin,ymax:t.ymax,spatialReference:s})}}return Q(f.map((e=>ee(e,n,o,r))).filter(e))}function Z(e,t,n){if("extent"===e.type){const{xmin:t,ymin:n,xmax:i,ymax:o,spatialReference:r}=e;e=new f({rings:[[[t,o],[i,o],[i,n],[t,n],[t,o]]],spatialReference:r})}return e.spatialReference.equals(t)?e:(M(e.spatialReference,t,n),p(e,t,n))}function $(e,t){const n=te(t);if(null==n)return null;let{xmin:o,ymin:r,xmax:s,ymax:a}=e;const l=e.spatialReference,c=new f({spatialReference:l,rings:[[[o,r],[s,r],[s,a],[o,a],[o,r]]]}),u=p(c,t);if(2!==u.rings.length||!u.rings[0].length||!u.rings[1].length)return null;const{rings:m}=u,x=A(l),h=new i({spatialReference:t});for(let i=0;i<2;i++){o=s=m[i][0][0],r=a=m[i][0][1];for(let e=0;e<m[i].length;e++)o=o>m[i][e][0]?m[i][e][0]:o,s=s<m[i][e][0]?m[i][e][0]:s,r=r>m[i][e][1]?m[i][e][1]:r,a=a<m[i][e][1]?m[i][e][1]:a;if(0===i)h.ymin=r,h.ymax=a,h.xmin=o,h.xmax=s;else if(h.ymin=Math.min(h.ymin,r),h.ymax=Math.max(h.ymax,a),Math.abs(s-n/2)<x)h.xmin=o,h.xmax=h.xmax+n;else{if(!(Math.abs(o+n/2)<x))return null;h.xmax=s+n}}return h}function ee(e,t,n=null,i=!0,o=!0){const r=e.spatialReference;if(r.equals(t)||!t)return e;M(r,t,n);const s=p(e,t,n);if(o&&t.isWebMercator&&s&&(s.ymax=Math.min(20037508.342787,s.ymax),s.ymin=Math.max(-20037508.342787,s.ymin),s.ymin>=s.ymax))return null;if(!i||!s)return s;const a=ne(r,!0),l=ne(t,!0);if(null==a||null==l)return s;const f=A(r,.001),u=A(r,N),m=A(t,.001);if(Math.abs(s.xmin-l[0])<m&&Math.abs(s.xmax-l[1])<m){const i=Math.abs(e.xmin-a[0]),o=Math.abs(a[1]-e.xmax);if(i<f&&o>u){s.xmin=l[0];const i=[];i.push(new c(e.xmax,e.ymin,r)),i.push(new c(e.xmax,(e.ymin+e.ymax)/2,r)),i.push(new c(e.xmax,e.ymax,r));const o=i.map((e=>B(e,t,n))).filter((e=>!isNaN(e?.x))).map((e=>e.x));s.xmax=Math.max.apply(null,o)}if(o<f&&i>u){s.xmax=l[1];const i=[];i.push(new c(e.xmin,e.ymin,r)),i.push(new c(e.xmin,(e.ymin+e.ymax)/2,r)),i.push(new c(e.xmin,e.ymax,r));const o=i.map((e=>B(e,t,n))).filter((e=>!isNaN(e?.x))).map((e=>e.x));s.xmin=Math.min.apply(null,o)}}else{const e=A(t,.001);Math.abs(s.xmin-l[0])<e&&(s.xmin=l[0]),Math.abs(s.xmax-l[1])<e&&(s.xmax=l[1])}return s}function te(e,t=!1){if(!e)return null;const n=t?20037508.342787:20037508.342788905;return e.isWebMercator?2*n:e.wkid&&e.isGeographic?360:2*S[e.wkid]||null}function ne(e,t=!1){if(e.isGeographic)return[-180,180];const n=te(e,t);return null!=n?[-n/2,n/2]:null}function ie(e,t,n,i){let o=(e-t)/n;return o-Math.floor(o)!=0?o=Math.floor(o):i&&(o-=1),o}function oe(e,t=!1){const n=te(e.spatialReference);if(null==n)return 0;const i=t?0:-(n/2),o=A(e.spatialReference),r=!t&&Math.abs(e.xmax-n/2)<o?n/2:e.xmax,s=!t&&Math.abs(e.xmin+n/2)<o?-n/2:e.xmin;return ie(r,i,n,!0)-ie(s,i,n,!1)}function re(e){const t=e.storageInfo.origin.x,n=te(e.spatialReference,!0);if(null==n)return{originX:t,halfWorldWidth:null,pyramidsInfo:null};const i=n/2,{nativePixelSize:o,storageInfo:r,extent:s}=e,{maximumPyramidLevel:a,blockWidth:l,pyramidScalingFactor:c}=r;let f=o.x;const u=[],m=null!=e.transform&&"gcs-shift"===e.transform.type,x=t+(m?0:i),h=m?n-t:i-t;for(let p=0;p<=a;p++){const e=(s.xmax-t)/f/l,n=e-Math.floor(e)==0?e:Math.ceil(e),i=h/f/l,o=i-Math.floor(i)==0?i:Math.ceil(i),r=Math.floor(x/f/l),a=Math.round(x/f)%l,m=(l-Math.round(h/f)%l)%l;u.push({resolutionX:f,blockWidth:l,datasetColumnCount:n,worldColumnCountFromOrigin:o,leftMargin:a,rightPadding:m,originColumnOffset:r}),f*=c}return{originX:t,halfWorldWidth:i,pyramidsInfo:u,hasGCSSShiftTransform:m}}function se(e){if(!e||e.isGeographic)return e;const t=String(e.wkid||e.wkt2||e.wkt);let n;if(E.has(t))n=E.get(t);else{n=(e.wkid?o.coordsys(e.wkid):o.fromString(r.PE_TYPE_PROJCS,e.wkt2||e.wkt)).getGeogcs().getCode(),E.set(t,n)}return new g({wkid:n})}function ae(e){const t=e.isAdaptive&&null==e.spacing;let n=e.spacing||[P,P],i=le(e),o={cols:i.size[0]+1,rows:i.size[1]+1};const r=i.outofBoundPointCount>0&&i.outofBoundPointCount<i.offsets.length/2;let s=i.outofBoundPointCount===i.offsets.length/2||t&&r?[0,0]:R(i.offsets,o,n,G);const a=(s[0]+s[1])/2,l=e.projectedExtent.spatialReference,c=e.srcBufferExtent.spatialReference;if(t&&(r||a>G)){w(l,c,e.datumTransformation)&&(l.isGeographic||X(l)),n=[b,b],i=le({...e,spacing:n}),o={cols:i.size[0]+1,rows:i.size[1]+1},s=R(i.offsets,o,n,G)}if(i.error=s,n[0]>1&&(i.coefficients=ce(i.offsets,o,r)),e.includeGCSGrid&&!l.isGeographic&&!l.isWebMercator)if(c.isGeographic)i.gcsGrid={offsets:i.offsets,coefficients:i.coefficients,spacing:n};else{const t=X(l);if(null!=t&&!t.isEnvelope){const t=se(l),s=V(e.projectedExtent,t),{offsets:a}=le({...e,srcBufferExtent:s,spacing:n}),c=ce(a,o,r);i.gcsGrid={offsets:a,coefficients:c,spacing:n}}}return i}function le(e){const{projectedExtent:t,srcBufferExtent:n,pixelSize:i,datumTransformation:o,rasterTransform:r}=e,s=t.spatialReference,a=n.spatialReference,l=M(s,a),{xmin:f,ymin:u,xmax:m,ymax:x}=t,h=te(a),p=null!=h&&(e.hasWrapAround||"gcs-shift"===r?.type),g=e.spacing||[P,P],y=g[0]*i.x,d=g[1]*i.y,w=1===g[0],R=Math.ceil((m-f)/y-.1/g[0])+(w?0:1),S=Math.ceil((x-u)/d-.1/g[1])+(w?0:1),G=q({cols:R,rows:S,xmin:f,ymax:x,xres:y,yres:d,inSR:s,outSR:a,datumTransformation:o,preferPE:g[0]<=b,usePixelCenter:w}),k=[];let E,T=0;const v=w?-1:NaN,{xmin:C,xmax:j,ymax:_,width:z,height:L}=n,I=A(a,N),W=null!=h&&C>0&&j>h/2;let O=!1;if(l){const e=X(s);O=null!=e&&e.poleLocation>0}for(let M=0;M<R;M++){const e=[];for(let t=0;t<S;t++){let n=G[M*S+t];if(p&&n[0]>j&&n[0]>h/2-I?n[0]-=h:p&&0===M&&n[0]<0&&W&&!r&&(n[0]+=h),!n||isNaN(n[0])||isNaN(n[1]))k.push(v),k.push(v),e.push(null),T++;else{if(r){const e=r.inverseTransform(new c({x:n[0],y:n[1],spatialReference:a}));n=[e.x,e.y]}e.push(n),M>0&&p&&E[t]&&n[0]<E[t][0]&&(n[0]+=h,O&&n[0]>j&&n[0]>h&&(n[0]-=h)),k.push((n[0]-C)/z),k.push((_-n[1])/L)}}E=e}return{offsets:k,error:null,coefficients:null,outofBoundPointCount:T,spacing:g,size:w?[R,S]:[R-1,S-1]}}function ce(e,t,n){const{cols:i,rows:o}=t,r=new Float32Array((i-1)*(o-1)*2*6),s=new Float32Array([-0,-1,1,-1,1,-0,1,-0,-0]),a=new Float32Array([-1,1,0,0,-1,1,1,0,0]);for(let l=0;l<i-1;l++){for(let t=0;t<o-1;t++){let n=l*o*2+2*t;const c=e[n],f=e[n+1],u=e[n+2],m=e[n+3];n+=2*o;const x=e[n],h=e[n+1],p=e[n+2],g=e[n+3];let y=0,d=12*(t*(i-1)+l);for(let e=0;e<3;e++)r[d++]=s[y++]*c+s[y++]*u+s[y++]*p;y=0;for(let e=0;e<3;e++)r[d++]=s[y++]*f+s[y++]*m+s[y++]*g;y=0;for(let e=0;e<3;e++)r[d++]=a[y++]*c+a[y++]*x+a[y++]*p;y=0;for(let e=0;e<3;e++)r[d++]=a[y++]*f+a[y++]*h+a[y++]*g}if(n)for(let e=0;e<r.length;e++)isNaN(r[e])&&(r[e]=-1)}return r}function fe(e,t){const n=e.clone().normalize();return 1===n.length?n[0]:Q(n,t)}function ue(e){const{spatialReference:t}=e,n=y(t);if(!n)return e;const[o,r]=n.valid,s=r-o;let a=0;if(e.xmin<o){const t=o-e.xmin;a=Math.ceil(t/s)}else if(e.xmin>r){const t=e.xmin-r;a=-Math.ceil(t/s)}return new i({spatialReference:e.spatialReference,xmin:e.xmin+a*s,ymin:e.ymin,xmax:e.xmax+a*s,ymax:e.ymax})}function me(e,t,i){const{storageInfo:o,pixelSize:r}=t;let s=0,a=!1;const{pyramidResolutions:l}=o,f="mixed"===o.tileInfo.format?.toLowerCase()?Math.max(1,Math.min(3,o.tileInfo.dpi/96)):1,u=(e.x+e.y)/2/f;if(null!=l&&l.length){const e=l[l.length-1],o=(e.x+e.y)/2,f=(r.x+r.y)/2;if(u<=f)s=0;else if(u>=o)s=l.length,a=u/o>8;else{let e,t=f;for(let n=1;n<=l.length;n++){if(e=(l[n-1].x+l[n-1].y)/2,u<=e){u===e?s=n:"down"===i?(s=n-1,a=u/t>8):s="up"===i||u-t>e-u||u/t>2?n:n-1;break}t=e}}const m=0===s?r:l[s-1];if(a){Math.min(m.x,m.y)*n(t.spatialReference)>19567&&(a=!1)}return{pyramidLevel:s,pyramidResolution:new c({x:m.x,y:m.y,spatialReference:t.spatialReference}),excessiveReading:a}}const m=Math.log(e.x/r.x)/Math.LN2,x=Math.log(e.y/r.y)/Math.LN2,h=t.storageInfo.maximumPyramidLevel||0;s="down"===i?Math.floor(Math.min(m,x)):"up"===i?Math.ceil(Math.max(m,x)):Math.round((m+x)/2),s<0?s=0:s>h&&(a=s>h+3,s=h);const p=2**s;return{pyramidLevel:s,pyramidResolution:new c({x:p*t.nativePixelSize.x,y:p*t.nativePixelSize.y,spatialReference:t.spatialReference}),excessiveReading:a}}function xe(e,t,n=!1){const{pixelSize:i,extent:o}=e,r=_(o,t,!1),s=V(fe(o,(i.x+i.y)/16),t,r);return n||0===oe(s)?s:ee(o,t,r)}function he(e,t,n){const i=n?.tileSize??512,o=n?.alignGlobalDatasetWithAGOL??!0,r=!!n?.limitToSrcResolution,{extent:s,spatialReference:a,pixelSize:l}=e,c=I(l,t,s);if(null==c)return{projectedPixelSize:null,scales:null,srcResolutions:null,isCustomTilingScheme:!1};const f=(c.x+c.y)/2,u=W(f,t),m=t.isGeographic?256/i*295828763.7958547:256/i*591657527.591555;let x="vector-magdir"===e.dataType||"vector-uv"===e.dataType;const h=xe(e,t,!0),p=Math.min(Math.ceil(Math.log(Math.min(e.width,e.height)/32)/Math.LN2),Math.ceil(Math.log(m/2/u)/Math.LN2));if(!x&&o&&(t.isGeographic||t.isWebMercator)){const n=te(t);if(x=oe(h)>0||null!=n&&h.width>n/4,!x&&null!=n){let t=-1;if(p<3)t=2**p*f*i;else if(e.storageInfo){const{maximumPyramidLevel:n=0,pyramidScalingFactor:o=2}=e.storageInfo;t=o**n*f*i}const o=Math.ceil(n/t);x=1===o||2===o&&n/2-h.xmax<t}}let y,d=u;const w=1.001,M=Math.min(2,Math.max(1.414,e.storageInfo?.pyramidScalingFactor||2));if(x){d=m;const n=t.isGeographic?1341104507446289e-21:.29858214164761665,i=W(n,t),o=t.isGeographic?4326:3857;y=I({x:n,y:n},a,xe(e,new g({wkid:o}),!0)),y.x*=d/i,y.y*=d/i}else{y={x:l.x,y:l.y};let e=0;for(;d<m*(w/2)&&e<p;)e++,d*=M,y.x*=M,y.y*=M;Math.max(d,m)/Math.min(d,m)<=w&&(d=m)}const R=[d],S=[{x:y.x,y:y.y}],P=70.5310735,b=Math.min(P,u)/w;for(;d>=b;)d/=M,y.x/=M,y.y/=M,R.push(d),S.push({x:y.x,y:y.y});if(r){const e=.001*l.x;let t=S.findIndex((t=>t.x>=l.x-e&&t.x<=l.x+e));t>-1?(S.length=t+1,R.length=t+1):(t=S.findIndex((t=>t.x<=l.x+e)),t>0&&(S.length=t,R.length=t))}return{projectedPixelSize:c,scales:R,srcResolutions:S,isCustomTilingScheme:!x}}export{he as computeProjectedScales,P as defaultGridSpacing,G as defaultProjectionToleranceInPixels,_ as getDefaultDatumTransformationForDataset,q as getProjectedGridPoints,ae as getProjectionOffsetGrid,re as getRasterDatasetAlignmentInfo,O as getSourceScale,te as getWorldWidth,oe as getWorldWrapCount,j as load,b as minimumGridSpacing,xe as projectDatasetExtent,I as projectDatasetResolution,V as projectExtent,B as projectPoint,Z as projectPolygon,z as projectResolution,w as requirePE,ue as shiftExtent,fe as snapExtent,me as snapPyramid};