@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 20.2 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{isSome as e}from"../../../core/arrayUtils.js";import t from"../../../core/Error.js";import{createResolver as n}from"../../../core/promiseUtils.js";import{getMetersPerUnitForSR as o}from"../../../core/unitUtils.js";import i from"../../../geometry/Extent.js";import{P as r,a as s,g as a,h as l,j as c}from"../../../chunks/pe.js";import f from"../../../geometry/Point.js";import u from"../../../geometry/Polygon.js";import{projectWithoutEngine as m}from"../../../geometry/projectionUtils.js";import x from"../../../geometry/SpatialReference.js";import{getInfo as h}from"../../../geometry/support/spatialReferenceUtils.js";var p;function g(){if(!j)throw new t("rasterprojectionhelper-project","projection operator is not loaded")}!function(e){e[e.None=0]="None",e[e.North=1]="North",e[e.South=2]="South",e[e.Both=3]="Both"}(p||(p={}));const y=(e,t,n,o=0)=>{if(1===n[0])return[0,0];let i=1,r=-1,s=1,a=-1;for(let g=0;g<e.length;g+=2)isNaN(e[g])||(i=i>e[g]?e[g]:i,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-i)/l/n[0],u=(a-s)/c/n[1],m=2*o;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,o=(e[n]+e[n+4]+e[n+4*c]+e[n+4*c+4])/4,i=(e[n+1]+e[n+5]+e[n+4*c+1]+e[n+4*c+5])/4,r=Math.abs((o-e[n+2*c+2])/f),s=Math.abs((i-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},d={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},w=32,M=4,R=M,S=new Map,P=new Map,b=500,G=39.37,k=96;let N,E,T,j=!1;async function v(){return N||(N=n(),E=await import("../../../geometry/operators/projectOperator.js"),T=await import("../../../geometry/operators/support/geographicTransformationUtils.js"),E.isLoaded()||await E.load(),T.isLoaded()||await T.load(),j=!0,N.resolve()),N.promise}function C(e,t,n){if(g(),n){const n=E.execute(e,t);return T.getTransformation(t,e.spatialReference,n)}return T.getTransformation(e.spatialReference,t,e)}function _(e,t,n,o){const r=e.spatialReference;if(!r||!t||r.equals(t))return e;g();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=E.execute(a,t,{geographicTransformation:o}),c=ee(t);return null==l||null!=c&&l.width>=c?z(e,r,t):{x:l.width,y:l.height}}function z(e,t,n){const i=o(t)/o(n);return{x:e.x*i,y:e.y*i}}function L(e,n,i){const{spatialReference:r}=i;if(!r||!n||r.equals(n))return e;if(r.isGeographic&&n.isGeographic)return z(e,r,n);if(g(),!j)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*o(r);let c=1;l>30&&(c=30/l,s*=c,a*=c);const f=256,m=s*f/2,x=a*f/2,{x:h,y:p}=i.center,y=[];for(let t=0;t<=f;t++)y.push([h-m,p-x+t*a]);for(let t=1;t<=f;t++)y.push([h-m+t*s,p+x]);for(let t=1;t<=f;t++)y.push([h+m,p+x-t*a]);for(let t=1;t<f;t++)y.push([h+m-t*s,p-x]);y.push(y[0]);const d=new u({rings:[y],spatialReference:r}),w=E.execute(d,n);if(!w)return z(e,r,n);const M=w.extent,R=ee(n);if(null==M||null!=R&&M.width>=R)return z(e,r,n);const S=he(w.rings),P=s*a*f*f,b=Math.sqrt(S/P)/c,G={x:M.width/c/f,y:M.height/c/f},k={x:s*b,y:a*b},N=G.x*G.y;return Math.abs(N-k.x*k.y)/N<.1?G:k}function I(e,t){return("number"==typeof e?e:(e.x+e.y)/2)*o(t)*k*G}function O(e,t){const{pixelSize:n,extent:o}=e;return I(L(n,t,o),t)}function W(e,t=.01){return o(e)?t/o(e):0}function A(e,t,n,o=!0){const i=e.spatialReference;if(i.equals(t))return e;g();const r=E.execute(e,t,{geographicTransformation:n});return o&&r?(B([e],[r],i,t),r):r}function B(e,t,n,o){const i=te(n,!0),r=te(o,!0),s=W(n,b),a=W(o,b);if(s&&null!=i&&null!=r)for(let l=0;l<e.length;l++){const n=t[l];if(!n)continue;const{x:o}=e[l],{x:c}=n;c>=r[1]-a&&Math.abs(o-i[0])<s?n.x-=r[1]-r[0]:c<=r[0]+a&&Math.abs(o-i[1])<s&&(n.x+=r[1]-r[0])}}function F(e){const{inSR:t,outSR:n,preferPE:o}=e;if(t.equals(n)){const{points:t}=K(e,null);return t}if(t.isWebMercator&&n.isWGS84||t.isWGS84&&n.isWebMercator)return U(e);if(o){if(t.isGeographic)return Y(e);if(null!=J(t))return Y(e)}return q(e)}function q(e){const{points:t}=K(e,null),{inSR:n,outSR:o,datumTransformation:i}=e,r=t.map((e=>new f(e[0],e[1],n))),s=E.executeMany(r,o,{geographicTransformation:i});return i&&B(r,s,n,o),s.map((e=>e?[e.x,e.y]:[NaN,NaN]))}function Y(e){const{inSR:t,outSR:n,datumTransformation:o}=e,i=J(t),{points:a,mask:f}=K(e,i);if(!t.isGeographic){const e=t.wkid?r.coordsys(t.wkid):r.fromString(t.isGeographic?s.PE_TYPE_GEOGCS:s.PE_TYPE_PROJCS,t.wkt2||t.wkt);l.projToGeog(e,a.length,a)}if(null!=o&&o.steps.length){let e;const t=179.9955;if(n.isGeographic&&(e=a.map((([e])=>e>t?1:e<-179.9955?-1:0))),o.steps.forEach((e=>{const t=e.wkid?r.geogtran(e.wkid):r.fromString(s.PE_TYPE_GEOGTRAN,e.wkt);c.geogToGeog(t,a.length,a,null,e.isInverse?s.PE_TRANSFORM_2_TO_1:s.PE_TRANSFORM_1_TO_2)})),e)for(let n=0;n<a.length;n++){const o=e[n],i=a[n][0],r=i>t?1:i<-179.9955?-1:0;o&&r&&o!==r&&(a[n][0]=o>0?i+360:i-360)}}if(!n.isGeographic){const e=J(n,!0),t=null!=e&&e.isEnvelope?[e.bbox[1],e.bbox[3]]:[-90,90];D(a,t);const o=n.wkid?r.coordsys(n.wkid):r.fromString(n.isGeographic?s.PE_TYPE_GEOGCS:s.PE_TYPE_PROJCS,n.wkt2||n.wkt);l.geogToProj(o,a.length,a)}let u=a;if(f&&a.length!==f.length){u=[];for(let e=0,t=0;e<f.length;e++)f[e]?u.push(a[t++]):u.push([NaN,NaN])}return u}function U(e){const{cols:t,rows:n,xres:o,yres:i,usePixelCenter:r,inSR:s,outSR:a}=e;let{xmin:l,ymax:c}=e;r&&(l+=o/2,c-=i/2);const u=[],x=[],h=Math.max(t,n);for(let g=0;g<h;g++){const e=l+o*Math.min(t,g),r=c-i*Math.min(n,g),h=m(new f({x:e,y:r,spatialReference:s}),s,a);g<=t&&u.push(h.x),g<=n&&x.push(h.y)}const p=[];for(let f=0;f<t;f++)for(let e=0;e<n;e++)p.push([u[f],x[e]]);return p}function J(e,t=!1){let n=e.wkid||e.wkt2||e.wkt;if(!n||e.isGeographic)return null;if(n=String(n),S.has(n)){const e=S.get(n);return t?e?.gcs:e?.pcs}const o=e.wkid?r.coordsys(e.wkid):r.fromString(e.isGeographic?s.PE_TYPE_GEOGCS:s.PE_TYPE_PROJCS,e.wkt2||e.wkt),i=X(o,W(e,1e-4)),a=X(o,0,!0);return S.set(n,{pcs:i,gcs:a}),t?a:i}function X(e,t=0,n=!1){const o=a.generate(e),i=n?e.horizonGcsGenerate():e.horizonPcsGenerate();if(!o||!i?.length)return null;let r=!1,s=i.find((e=>1===e.getInclusive()&&1===e.getKind()));if(!s){if(s=i.find((e=>1===e.getInclusive()&&0===e.getKind())),!s)return null;r=!0}const l=n?0:(2===o.getNorthPoleLocation()?1:0)|(2===o.getSouthPoleLocation()?2:0),c=o.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:l};let u=0;const m=[];let[x,h]=f[0],[p,g]=f[0];for(let a=0,y=f.length;a<y;a++){u++,u===y&&(u=0);const[e,t]=f[a],[n,o]=f[u];if(o===t)m.push([e,n,t,o,2]);else{const i=(n-e)/(o-t||1e-4),r=e-i*t;t<o?m.push([i,r,t,o,0]):m.push([i,r,o,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:l}}function K(e,t){const n=[],{cols:o,rows:i,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<o;e++)for(let t=0;t<i;t++)n.push([l+r*e,c-s*t]);return{points:n}}const f=new Uint8Array(o*i);if(t.isEnvelope){const{bbox:[e,a,u,m]}=t;for(let x=0,h=0;x<o;x++){const o=l+r*x,p=t.isPannable||o>=e&&o<=u;for(let e=0;e<i;e++,h++){const t=c-s*e;p&&t>=a&&t<=m&&(n.push([o,t]),f[h]=1)}}return{points:n,mask:f}}const u=t.coef,m=[];for(let x=0;x<i;x++){const e=c-s*x,t=[],n=[];for(let i=0;i<u.length;i++){const[o,r,s,a,l]=u[i];if(e===s&&s===a)t.push(o),t.push(r),n.push(2),n.push(2);else if(e>=s&&e<=a){const i=o*e+r;t.push(i),n.push(l)}}let o=t;if(t.length>2){let e=2===n[0]?0:n[0],i=t[0];o=[];for(let r=1;r<n.length;r++)2===n[r]&&r!==n.length-1||(n[r]!==e&&(o.push(0===e?Math.min(i,t[r-1]):Math.max(i,t[r-1])),e=n[r],i=t[r]),r===n.length-1&&o.push(0===n[r]?Math.min(i,t[r]):Math.max(i,t[r])));o.sort(((e,t)=>e-t))}else t[0]>t[1]&&(o=[t[1],t[0]]);m.push(o)}for(let x=0,h=0;x<o;x++){const e=l+r*x;for(let t=0;t<i;t++,h++){const o=c-s*t,i=m[t];if(2===i.length)e>=i[0]&&e<=i[1]&&(n.push([e,o]),f[h]=1);else if(i.length>2){let t=!1;for(let n=0;n<i.length;n+=2)if(e>=i[n]&&e<=i[n+1]){t=!0;break}t&&(n.push([e,o]),f[h]=1)}}}return{points:n,mask:f}}function D(e,t){const[n,o]=t;for(let i=0;i<e.length;i++){const t=e[i][1];(t<n||t>o)&&(e[i]=[NaN,NaN])}}function H(e,t){const n=ee(e[0].spatialReference);if(e.length<2||null==n)return e[0];if(t=t??W(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 Q(t,n,o=null,r=!0){const s=t.spatialReference;if(s.equals(n)||!n)return t;const a=oe(t),l=ee(s,!0),c=ee(n);if(0===a||null==l||null==c){const e=$(t,n,o,r);if(e&&null==l&&null!=c&&Math.abs(e.width-c)<W(n)&&E.isLoaded()){const o=J(s);if(null!=o&&o.poleLocation===p.None&&t.width<(o.bbox[2]-o.bbox[0])/2)return Z(t,n)||e}return e}const f=t.clone().normalize();if(1===f.length&&t.xmax<l&&t.xmax-l/2>W(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})}}const u=f.map((e=>$(e,n,o,r))).filter(e);return 0===u.length?null:H(u)}function V(e,t,n){if("extent"===e.type){const{xmin:t,ymin:n,xmax:o,ymax:i,spatialReference:r}=e;e=new u({rings:[[[t,i],[o,i],[o,n],[t,n],[t,i]]],spatialReference:r})}return e.spatialReference.equals(t)?e:(g(),E.execute(e,t,{geographicTransformation:n}))}function Z(e,t){const n=ee(t);if(null==n)return null;let{xmin:o,ymin:r,xmax:s,ymax:a}=e;const l=e.spatialReference,c=new u({spatialReference:l,rings:[[[o,r],[s,r],[s,a],[o,a],[o,r]]]}),f=E.execute(c,t);if(2!==f.rings.length||!f.rings[0].length||!f.rings[1].length)return null;const{rings:m}=f,x=W(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 $(e,t,n,o=!0,i=!0){const r=e.spatialReference;if(r.equals(t)||!t)return e;g();const s=E.execute(e,t,{geographicTransformation:n});if(i&&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(!o||!s)return s;const a=te(r,!0),l=te(t,!0);if(null==a||null==l)return s;const c=W(r,.001),u=W(r,b),m=W(t,.001);if(Math.abs(s.xmin-l[0])<m&&Math.abs(s.xmax-l[1])<m){const o=Math.abs(e.xmin-a[0]),i=Math.abs(a[1]-e.xmax);if(o<c&&i>u){s.xmin=l[0];const o=[];o.push(new f(e.xmax,e.ymin,r)),o.push(new f(e.xmax,(e.ymin+e.ymax)/2,r)),o.push(new f(e.xmax,e.ymax,r));const i=o.map((e=>A(e,t,n))).filter((e=>!isNaN(e?.x))).map((e=>e.x));s.xmax=Math.max.apply(null,i)}if(i<c&&o>u){s.xmax=l[1];const o=[];o.push(new f(e.xmin,e.ymin,r)),o.push(new f(e.xmin,(e.ymin+e.ymax)/2,r)),o.push(new f(e.xmin,e.ymax,r));const i=o.map((e=>A(e,t,n))).filter((e=>!isNaN(e?.x))).map((e=>e.x));s.xmin=Math.min.apply(null,i)}}else{const e=W(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 ee(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*d[e.wkid]||null}function te(e,t=!1){if(e.isGeographic)return[-180,180];const n=ee(e,t);return null!=n?[-n/2,n/2]:null}function ne(e,t,n,o){let i=(e-t)/n;return i-Math.floor(i)!==0?i=Math.floor(i):o&&(i-=1),i}function oe(e,t=!1){const n=ee(e.spatialReference);if(null==n)return 0;const o=t?0:-(n/2),i=W(e.spatialReference),r=!t&&Math.abs(e.xmax-n/2)<i?n/2:e.xmax,s=!t&&Math.abs(e.xmin+n/2)<i?-n/2:e.xmin;return ne(r,o,n,!0)-ne(s,o,n,!1)}function ie(e){const t=e.storageInfo.origin.x,n=ee(e.spatialReference,!0);if(null==n)return{originX:t,halfWorldWidth:null,pyramidsInfo:null};const o=n/2,{nativePixelSize:i,storageInfo:r,extent:s}=e,{maximumPyramidLevel:a,blockWidth:l,pyramidScalingFactor:c}=r;let f=i.x;const u=[],m=null!=e.transform&&"gcs-shift"===e.transform.type,x=t+(m?0:o),h=m?n-t:o-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),o=h/f/l,i=o-Math.floor(o)===0?o:Math.ceil(o),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:i,leftMargin:a,rightPadding:m,originColumnOffset:r}),f*=c}return{originX:t,halfWorldWidth:o,pyramidsInfo:u,hasGCSSShiftTransform:m}}function re(e){if(!e||e.isGeographic)return e;const t=String(e.wkid||e.wkt2||e.wkt);let n;if(P.has(t))n=P.get(t);else{n=(e.wkid?r.coordsys(e.wkid):r.fromString(s.PE_TYPE_PROJCS,e.wkt2||e.wkt)).getGeogcs().getCode(),P.set(t,n)}return new x({wkid:n})}function se(e){const t=e.isAdaptive&&null==e.spacing;let n=e.spacing||[w,w],o=ae(e),i={cols:o.size[0]+1,rows:o.size[1]+1};const r=o.outofBoundPointCount>0&&o.outofBoundPointCount<o.offsets.length/2;let s=o.outofBoundPointCount===o.offsets.length/2||t&&r?[0,0]:y(o.offsets,i,n,R);const a=(s[0]+s[1])/2,l=e.projectedExtent.spatialReference,c=e.srcBufferExtent.spatialReference;if(t&&(r||a>R)&&(l.isGeographic||J(l),n=[M,M],o=ae({...e,spacing:n}),i={cols:o.size[0]+1,rows:o.size[1]+1},s=y(o.offsets,i,n,R)),o.error=s,n[0]>1&&(o.coefficients=le(o.offsets,i,r)),e.includeGCSGrid&&!l.isGeographic&&!l.isWebMercator)if(c.isGeographic)o.gcsGrid={offsets:o.offsets,coefficients:o.coefficients,spacing:n};else{const t=J(l);if(null!=t&&!t.isEnvelope){const t=re(l),s=Q(e.projectedExtent,t),{offsets:a}=ae({...e,srcBufferExtent:s,spacing:n}),c=le(a,i,r);o.gcsGrid={offsets:a,coefficients:c,spacing:n}}}return o}function ae(e){const{projectedExtent:t,srcBufferExtent:n,pixelSize:o,datumTransformation:i,rasterTransform:r}=e,s=t.spatialReference,a=n.spatialReference;g();const{xmin:l,ymin:c,xmax:u,ymax:m}=t,x=ee(a),h=null!=x&&(e.hasWrapAround||"gcs-shift"===r?.type),p=e.spacing||[w,w],y=p[0]*o.x,d=p[1]*o.y,R=1===p[0],S=Math.ceil((u-l)/y-.1/p[0])+(R?0:1),P=Math.ceil((m-c)/d-.1/p[1])+(R?0:1),G=F({cols:S,rows:P,xmin:l,ymax:m,xres:y,yres:d,inSR:s,outSR:a,datumTransformation:i,preferPE:p[0]<=M,usePixelCenter:R}),k=[];let N,E=0;const T=R?-1:NaN,{xmin:j,xmax:v,ymax:C,width:_,height:z}=n,L=W(a,b),I=null!=x&&j>0&&v>x/2,O=J(s),A=null!=O&&O.poleLocation>0;for(let g=0;g<S;g++){const e=[];for(let t=0;t<P;t++){let n=G[g*P+t];if(h&&n[0]>v&&n[0]>x/2-L?n[0]-=x:h&&0===g&&n[0]<0&&I&&!r&&(n[0]+=x),!n||isNaN(n[0])||isNaN(n[1]))k.push(T),k.push(T),e.push(null),E++;else{if(r){const e=r.inverseTransform(new f({x:n[0],y:n[1],spatialReference:a}));n=[e.x,e.y]}e.push(n),g>0&&h&&N[t]&&n[0]<N[t][0]&&(n[0]+=x,A&&n[0]>v&&n[0]>x&&(n[0]-=x)),k.push((n[0]-j)/_),k.push((C-n[1])/z)}}N=e}return{offsets:k,error:null,coefficients:null,outofBoundPointCount:E,spacing:p,size:R?[S,P]:[S-1,P-1]}}function le(e,t,n){const{cols:o,rows:i}=t,r=new Float32Array((o-1)*(i-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<o-1;l++){for(let t=0;t<i-1;t++){let n=l*i*2+2*t;const c=e[n],f=e[n+1],u=e[n+2],m=e[n+3];n+=2*i;const x=e[n],h=e[n+1],p=e[n+2],g=e[n+3];let y=0,d=12*(t*(o-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 ce(e,t){const n=e.clone().normalize();return 1===n.length?n[0]:H(n,t)}function fe(e){const{spatialReference:t}=e,n=h(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 ue(e,t,n){const{storageInfo:i,pixelSize:r}=t;let s=0,a=!1;const{pyramidResolutions:l}=i,c="mixed"===i.tileInfo.format?.toLowerCase()?Math.max(1,Math.min(3,i.tileInfo.dpi/96)):1,u=(e.x+e.y)/2/c;if(null!=l&&l.length){const e=l[l.length-1],i=(e.x+e.y)/2,c=(r.x+r.y)/2;if(u<=c)s=0;else if(u>=i)s=l.length,a=u/i>8;else{let e,t=c;for(let o=1;o<=l.length;o++){if(e=(l[o-1].x+l[o-1].y)/2,u<=e){u===e?s=o:"down"===n?(s=o-1,a=u/t>8):s="up"===n||u-t>e-u||u/t>2?o:o-1;break}t=e}}const m=0===s?r:l[s-1];if(a){Math.min(m.x,m.y)*o(t.spatialReference)>19567&&(a=!1)}return{pyramidLevel:s,pyramidResolution:new f({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"===n?Math.floor(Math.min(m,x)):"up"===n?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 f({x:p*t.nativePixelSize.x,y:p*t.nativePixelSize.y,spatialReference:t.spatialReference}),excessiveReading:a}}function me(e,t,n=!1){const{pixelSize:o,extent:i}=e,r=C(i,t,!1),s=Q(ce(i,(o.x+o.y)/16),t,r);return!s||n||0===oe(s)?s:$(i,t,r)}function xe(e,t,n){const o=n?.tileSize??512,i=n?.alignGlobalDatasetWithAGOL??!0,r=!!n?.limitToSrcResolution,{extent:s,spatialReference:a,pixelSize:l}=e,c=L(l,t,s);if(null==c)return{projectedPixelSize:null,scales:null,srcResolutions:null,isCustomTilingScheme:!1};const f=(c.x+c.y)/2,u=I(f,t),m=t.isGeographic?256/o*295828763.7958547:256/o*591657527.591555;let h="vector-magdir"===e.dataType||"vector-uv"===e.dataType;const p=me(e,t,!0),g=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(!h&&p&&i&&(t.isGeographic||t.isWebMercator)){const n=ee(t);if(h=oe(p)>0||null!=n&&p.width>n/4,!h&&null!=n){let t=-1;if(g<3)t=2**g*f*o;else if(e.storageInfo){const{maximumPyramidLevel:n=0,pyramidScalingFactor:i=2}=e.storageInfo;t=i**n*f*o}const i=Math.ceil(n/t);h=1===i||2===i&&n/2-p.xmax<t}}let y,d=u;const w=1.001,M=Math.min(2,Math.max(1.414,e.storageInfo?.pyramidScalingFactor||2));if(h){d=m;const n=t.isGeographic?1341104507446289e-21:.29858214164761665,o=I(n,t),i=t.isGeographic?4326:3857;y=L({x:n,y:n},a,me(e,new x({wkid:i}),!0)),y.x*=d/o,y.y*=d/o}else{y={x:l.x,y:l.y};let e=0;for(;d<m*(w/2)&&e<g;)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:!h}}function he(e){let t=0;for(const n of e){const e=n.length;let o=n[0][0]*(n[1][1]-n[e-2][1]);for(let t=1;t<e-1;t++)o+=n[t][0]*(n[t+1][1]-n[t-1][1]);t+=o/2}return Math.abs(t)}export{xe as computeProjectedScales,w as defaultGridSpacing,R as defaultProjectionToleranceInPixels,C as getDefaultDatumTransformationForDataset,F as getProjectedGridPoints,se as getProjectionOffsetGrid,ie as getRasterDatasetAlignmentInfo,O as getSourceScale,ee as getWorldWidth,oe as getWorldWrapCount,v as load,M as minimumGridSpacing,me as projectDatasetExtent,L as projectDatasetResolution,Q as projectExtent,A as projectPoint,V as projectPolygon,_ as projectResolution,fe as shiftExtent,ce as snapExtent,ue as snapPyramid};