12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.24/esri/copyright.txt for details.
- */
- import e from"../../core/Error.js";import t from"../../core/Logger.js";import{isNone as n,isSome as o}from"../../core/maybe.js";import{isPoint as r,isPolygon as s,isPolyline as c,isMultipoint as l}from"../../geometry/support/jsonUtils.js";import{OptimizedFeature as u}from"./OptimizedFeature.js";import i from"./OptimizedFeatureSet.js";import f from"./OptimizedGeometry.js";function h(e,t){return e?t?4:3:t?3:2}const a=t.getLogger("esri.layers.graphics.featureConversionUtils"),g={esriGeometryPoint:0,esriGeometryPolyline:2,esriGeometryPolygon:3,esriGeometryMultipoint:0},d=(e,t,n,o,r,s)=>{e[n]=r,e[n+1]=s},m=(e,t,n,o,r,s)=>{e[n]=r,e[n+1]=s,e[n+2]=t[o+2]},y=(e,t,n,o,r,s)=>{e[n]=r,e[n+1]=s,e[n+2]=t[o+3]},p=(e,t,n,o,r,s)=>{e[n]=r,e[n+1]=s,e[n+2]=t[o+2],e[n+3]=t[o+3]};function I(e,t,n,o){if(e){if(n)return t&&o?p:m;if(t&&o)return y}else if(t&&o)return m;return d}function b({scale:e,translate:t},n){return Math.round((n-t[0])/e[0])}function M({scale:e,translate:t},n){return Math.round((t[1]-n)/e[1])}function w({scale:e,translate:t},n){return n*e[0]+t[0]}function N({scale:e,translate:t},n){return t[1]-n*e[1]}function G(e,t,n){return e?t?n?k(e):P(e):n?Z(e):T(e):null}function T(e){const t=e.coords;return{x:t[0],y:t[1]}}function F(e,t){return e.coords[0]=t.x,e.coords[1]=t.y,e}function P(e){const t=e.coords;return{x:t[0],y:t[1],z:t[2]}}function x(e,t){return e.coords[0]=t.x,e.coords[1]=t.y,e.coords[2]=t.z,e}function Z(e){const t=e.coords;return{x:t[0],y:t[1],m:t[2]}}function j(e,t){return e.coords[0]=t.x,e.coords[1]=t.y,e.coords[2]=t.m,e}function k(e){const t=e.coords;return{x:t[0],y:t[1],z:t[2],m:t[3]}}function E(e,t){return e.coords[0]=t.x,e.coords[1]=t.y,e.coords[2]=t.z,e.coords[3]=t.m,e}function z(e,t,n,r){let s=T;n&&r?s=k:n?s=P:r&&(s=Z);for(const c of t){const{geometry:t,attributes:n}=c,r=o(t)?s(t):null;e.push({attributes:n,geometry:r})}return e}function v(e,t){return e&&t?E:e?x:t?j:F}function S(e,t,n,o,r){const s=v(n,o);for(const c of t){const{geometry:t,attributes:n}=c;let o;t&&(o=s(new f,t)),e.push(new u(o,n,null,n[r]))}return e}function V(e,t,n=v(null!=t.z,null!=t.m)){return n(e,t)}function Y(e,t,n,o){for(const r of t){const{geometry:t,attributes:s}=r;let c;t&&(c=_(t,n,o)),e.push({attributes:s,geometry:c})}return e}function _(e,t,o){if(n(e))return null;const r=h(t,o),s=[];for(let n=0;n<e.coords.length;n+=r){const t=[];for(let o=0;o<r;o++)t.push(e.coords[n+o]);s.push(t)}return t?o?{points:s,hasZ:t,hasM:o}:{points:s,hasZ:t}:o?{points:s,hasM:o}:{points:s}}function O(e,t,n,o,r){const s=h(n,o);for(const c of t){const t=c.geometry,n=c.attributes;let o;t&&(o=U(new f,t,s)),e.push(new u(o,n,null,n[r]))}return e}function U(e,t,n=h(t.hasZ,t.hasM)){e.lengths[0]=t.points.length;const o=e.coords;let r=0;for(const s of t.points)for(let e=0;e<n;e++)o[r++]=s[e];return e}function A(e,t,n,r){for(const s of t){const{geometry:t,attributes:c}=s;let l;o(t)&&(l=L(t,n,r)),e.push({attributes:c,geometry:l})}return e}function L(e,t,n){if(!e)return null;const o=h(t,n),{coords:r,lengths:s}=e,c=[];let l=0;for(const u of s){const e=[];for(let t=0;t<u;t++){const t=[];for(let e=0;e<o;e++)t.push(r[l++]);e.push(t)}c.push(e)}return t?n?{paths:c,hasZ:t,hasM:n}:{paths:c,hasZ:t}:n?{paths:c,hasM:n}:{paths:c}}function q(e,t,n,o,r){const s=h(n,o);for(const c of t){const t=c.geometry,n=c.attributes;let o;t&&(o=$(new f,t,s)),e.push(new u(o,n,null,n[r]))}return e}function $(e,t,n=h(t.hasZ,t.hasM)){const{lengths:o,coords:r}=e;let s=0;for(const c of t.paths){for(const e of c)for(let t=0;t<n;t++)r[s++]=e[t];o.push(c.length)}return e}function R(e,t,n,r){for(const s of t){const{geometry:t,attributes:c,centroid:l}=s;let u;if(o(t)&&(u=C(t,n,r)),o(l)){const t=T(l);e.push({attributes:c,centroid:t,geometry:u})}else e.push({attributes:c,geometry:u})}return e}function C(e,t,n){if(!e)return null;const o=h(t,n),{coords:r,lengths:s}=e,c=[];let l=0;for(const u of s){const e=[];for(let t=0;t<u;t++){const t=[];for(let e=0;e<o;e++)t.push(r[l++]);e.push(t)}c.push(e)}return t?n?{rings:c,hasZ:t,hasM:n}:{rings:c,hasZ:t}:n?{rings:c,hasM:n}:{rings:c}}function B(e,t,n,r,s){for(const c of t){const t=c.geometry,l=c.centroid,i=c.attributes;let h;t&&(h=D(new f,t,n,r)),o(l)?e.push(new u(h,i,F(new f,l),i[s])):e.push(new u(h,i,null,i[s]))}return e}function D(e,t,n=t.hasZ,o=t.hasM){return H(e,t.rings,n,o),e}function H(e,t,n,o){const r=h(n,o),{lengths:s,coords:c}=e;let l=0;s.length=c.length=0;for(const u of t){for(const e of u)for(let t=0;t<r;t++)c[l++]=e[t];s.push(u.length)}return e}const J=[],K=[];function Q(e,t,n,o,r){J[0]=e;const[s]=W(K,J,t,n,o,r);return J.length=K.length=0,s}function W(t,n,o,r,s,c){if(t.length=0,!o){for(const e of n){const n=e.attributes[c];t.push(new u(null,e.attributes,null,n))}return t}switch(o){case"esriGeometryPoint":return S(t,n,r,s,c);case"esriGeometryMultipoint":return O(t,n,r,s,c);case"esriGeometryPolyline":return q(t,n,r,s,c);case"esriGeometryPolygon":return B(t,n,r,s,c);default:a.error("convertToFeatureSet:unknown-geometry",new e(`Unable to parse unknown geometry type '${o}'`)),t.length=0}return t}function X(t,n,o,r,s,c){const l=t.length;switch(o){case"esriGeometryPoint":S(t,n,r,s,c);break;case"esriGeometryMultipoint":O(t,n,r,s,c);break;case"esriGeometryPolyline":q(t,n,r,s,c);break;case"esriGeometryPolygon":B(t,n,r,s,c);break;default:a.error("convertToFeatureSet:unknown-geometry",new e(`Unable to parse unknown geometry type '${o}'`))}for(let e=0;e<n.length;e++)t[e+l].geometryType=o,t[e+l].insertAfter=n[e].insertAfter,t[e+l].groupId=n[e].groupId;return t}function ee(e,t,n,o){K[0]=e,re(J,K,t,n,o);const r=J[0];return J.length=K.length=0,r}function te(t,o,u){if(n(t))return null;const i=new f;if("hasZ"in t&&null==o&&(o=t.hasZ),"hasM"in t&&null==u&&(u=t.hasM),r(t)){return v(null!=o?o:null!=t.z,null!=u?u:null!=t.m)(i,t)}return s(t)?D(i,t,o,u):c(t)?$(i,t,h(o,u)):l(t)?U(i,t,h(o,u)):void a.error("convertFromGeometry:unknown-geometry",new e(`Unable to parse unknown geometry type '${t}'`))}function ne(t,o,r,s){const c=t&&("coords"in t?t:t.geometry);if(n(c))return null;switch(o){case"esriGeometryPoint":{let e=T;return r&&s?e=k:r?e=P:s&&(e=Z),e(c)}case"esriGeometryMultipoint":return _(c,r,s);case"esriGeometryPolyline":return L(c,r,s);case"esriGeometryPolygon":return C(c,r,s);default:return void a.error("convertToGeometry:unknown-geometry",new e(`Unable to parse unknown geometry type '${o}'`))}}function oe(e,t){for(const n of t)e.push({attributes:n.attributes});return e}function re(t,o,r,s,c){if(t.length=0,n(r))return oe(t,o);switch(r){case"esriGeometryPoint":return z(t,o,s,c);case"esriGeometryMultipoint":return Y(t,o,s,c);case"esriGeometryPolyline":return A(t,o,s,c);case"esriGeometryPolygon":return R(t,o,s,c);default:a.error("convertToFeatureSet:unknown-geometry",new e(`Unable to parse unknown geometry type '${r}'`))}return t}function se(e){const{objectIdFieldName:t,spatialReference:n,transform:o,fields:r,hasM:s,hasZ:c,features:l,geometryType:u,exceededTransferLimit:i,uniqueIdField:f,queryGeometry:h,queryGeometryType:a}=e,g={features:re([],l,u,c,s),fields:r,geometryType:u,objectIdFieldName:t,spatialReference:n,uniqueIdField:f,queryGeometry:ne(h,a,!1,!1)};return o&&(g.transform=o),i&&(g.exceededTransferLimit=i),s&&(g.hasM=s),c&&(g.hasZ=c),g}function ce(t,n){const o=new i,{hasM:r,hasZ:s,features:c,objectIdFieldName:l,spatialReference:u,geometryType:f,exceededTransferLimit:h,transform:g,fields:d}=t;return d&&(o.fields=d),o.geometryType=f,o.objectIdFieldName=l||n,o.spatialReference=u,o.objectIdFieldName?(c&&W(o.features,c,f,s,r,o.objectIdFieldName),h&&(o.exceededTransferLimit=h),r&&(o.hasM=r),s&&(o.hasZ=s),g&&(o.transform=g),o):(a.error(new e("optimized-features:invalid-objectIdFieldName","objectIdFieldName is missing")),o)}function le(e){const{transform:t,features:n,hasM:r,hasZ:s}=e;if(!t)return e;for(const c of n)o(c.geometry)&&me(c.geometry,c.geometry,r,s,t),o(c.centroid)&&me(c.centroid,c.centroid,r,s,t);return e.transform=null,e}function ue(e,t){const{geometryType:n,features:o,hasM:r,hasZ:s}=t;if(!e)return t;for(let c=0;c<o.length;c++){const t=o[c],l=t.weakClone();l.geometry=new f,ie(l.geometry,t.geometry,r,s,n,e),t.centroid&&(l.centroid=new f,ie(l.centroid,t.centroid,r,s,"esriGeometryPoint",e)),o[c]=l}return t.transform=e,t}function ie(e,t,o,r,s,c,l=o,u=r){if(e.lengths.length&&(e.lengths.length=0),e.coords.length&&(e.coords.length=0),n(t)||!t.coords.length)return null;const i=g[s],{coords:f,lengths:a}=t,d=h(o,r),m=h(o&&l,r&&u),y=I(o,r,l,u);if(!a.length)return y(e.coords,f,0,0,b(c,f[0]),M(c,f[1])),e.lengths.length&&(e.lengths.length=0),e.coords.length=d,e;let p,w,N,G,T=0,F=0,P=F;for(const n of a){if(n<i)continue;let t=0;F=P,N=p=b(c,f[T]),G=w=M(c,f[T+1]),y(e.coords,f,F,T,N,G),t++,T+=d,F+=m;for(let o=1;o<n;o++,T+=d)N=b(c,f[T]),G=M(c,f[T+1]),N===p&&G===w||(y(e.coords,f,F,T,N-p,G-w),F+=m,t++,p=N,w=G);t>=i&&(e.lengths.push(t),P=F)}return e.coords.length=P,e.coords.length?e:null}function fe(e,t,n,o,r,s,c=n,l=o){if(e.lengths.length&&(e.lengths.length=0),e.coords.length&&(e.coords.length=0),!t||!t.coords.length)return null;const u=g[r],{coords:i,lengths:f}=t,a=h(n,o),d=h(n&&c,o&&l),m=I(n,o,c,l);if(!f.length)return m(e.coords,i,0,0,i[0],i[1]),e.lengths.length&&(e.lengths.length=0),e.coords.length=a,e;let y=0;const p=s*s;for(const h of f){if(h<u){y+=h*a;continue}const t=e.coords.length/d,n=y,o=y+(h-1)*a;m(e.coords,i,e.coords.length,n,i[n],i[n+1]),ae(e.coords,i,a,p,m,n,o),m(e.coords,i,e.coords.length,o,i[o],i[o+1]);const r=e.coords.length/d-t;r>=u?e.lengths.push(r):e.coords.length=t*d,y+=h*a}return e.coords.length?e:null}function he(e,t,n,o){const r=e[t],s=e[t+1],c=e[n],l=e[n+1],u=e[o],i=e[o+1];let f=c,h=l,a=u-f,g=i-h;if(0!==a||0!==g){const e=((r-f)*a+(s-h)*g)/(a*a+g*g);e>1?(f=u,h=i):e>0&&(f+=a*e,h+=g*e)}return a=r-f,g=s-h,a*a+g*g}function ae(e,t,n,o,r,s,c){let l,u=o,i=0;for(let f=s+n;f<c;f+=n)l=he(t,f,s,c),l>u&&(i=f,u=l);u>o&&(i-s>n&&ae(e,t,n,o,r,s,i),r(e,t,e.length,i,t[i],t[i+1]),c-i>n&&ae(e,t,n,o,r,i,c))}function ge(e,t,o,r){if(n(t)||!t.coords||!t.coords.length)return null;const s=h(o,r);let c=Number.POSITIVE_INFINITY,l=Number.POSITIVE_INFINITY,u=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;if(t&&t.coords){const e=t.coords;for(let t=0;t<e.length;t+=s){const n=e[t],o=e[t+1];c=Math.min(c,n),u=Math.max(u,n),l=Math.min(l,o),i=Math.max(i,o)}}return e[0]=c,e[1]=l,e[2]=u,e[3]=i,e}function de(e,t,n,o){const r=h(n,o),{lengths:s,coords:c}=t;let l=Number.POSITIVE_INFINITY,u=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,f=Number.NEGATIVE_INFINITY,a=0;for(const h of s){let e=c[a],t=c[a+1];l=Math.min(e,l),u=Math.min(t,u),i=Math.max(e,i),f=Math.max(t,f),a+=r;for(let n=1;n<h;n++,a+=r){const n=c[a],o=c[a+1];e+=n,t+=o,n<0&&(l=Math.min(l,e)),n>0&&(i=Math.max(i,e)),o<0?u=Math.min(u,t):o>0&&(f=Math.max(f,t))}}return e[0]=l,e[1]=u,e[2]=i,e[3]=f,e}function me(e,t,n,o,r){const{coords:s,lengths:c}=t,l=n?o?p:m:o?m:d,u=h(n,o);if(!s.length)return e!==t&&(e.lengths.length=0,e.coords.length=0),e;if(!c.length)return l(e.coords,s,0,0,w(r,s[0]),N(r,s[1])),e!==t&&(e.lengths.length=0,e.coords.length=u),e;const[i,f]=r.scale;let a=0;for(let h=0;h<c.length;h++){const t=c[h];e.lengths[h]=t;let n=w(r,s[a]),o=N(r,s[a+1]);l(e.coords,s,a,a,n,o),a+=u;for(let r=1;r<t;r++,a+=u)n+=s[a]*i,o-=s[a+1]*f,l(e.coords,s,a,a,n,o)}return e!==t&&(e.lengths.length=c.length,e.coords.length=s.length),e}function ye(e,t,n,o,r,s){const c=h(n,o),l=I(n,o,r,s),u=t.coords;e.coords.length=0,e.lengths.length=0,e.lengths.push(...t.lengths);for(let i=0;i<u.length;i+=c)l(e.coords,u,e.coords.length,i,u[i],u[i+1]);return e}function pe(e,t,n,o,r){if(!t||!t.coords||!t.coords.length)return null;const s=g[n],{coords:c,lengths:l}=t,u=I(o,r,o,r),i=h(o,r);let f=0,a=0,d=0,m=0;for(const h of l){a=m,u(e.coords,c,a,f,c[f],c[f+1]),f+=i;let t=c[f],n=c[f+1],o=t,r=n,l=n/t;a+=i,u(e.coords,c,a,f,o,r),f+=i;for(let s=2;s<h;s++){t=c[f],n=c[f+1];const s=n/t,h=l===s||!isFinite(l)&&!isFinite(s),g=h&&isFinite(s)?l>=0&&s>=0||l<=0&&s<=0:r>=0&&n>=0||r<=0&&n<=0;h&&g?(o+=t,r+=n):(o=t,r=n,a+=i),u(e.coords,c,a,f,o,r),f+=i,l=s}a+=i;const g=(a-m)/i;g>=s&&(e.lengths[d]=g,m=a,d++)}return e.coords.length>m&&(e.coords.length=m),e.lengths.length>d&&(e.lengths.length=d),e.coords.length&&e.lengths.length?e:null}function Ie(e,t,n,o){let r=0,s=e[o*t],c=e[o*(t+1)];for(let l=1;l<n;l++){const n=s+e[o*(t+l)],u=c+e[o*(t+l)+1],i=(n-s)*(u+c);s=n,c=u,r+=i}return.5*r}function be(e,t){const{coords:n,lengths:o}=e;let r=0,s=0;for(let c=0;c<o.length;c++){s+=Ie(n,r,o[c],t),r+=c}return Math.abs(s)}function Me(e,t){const n=e.clone(),o=e.coords,r=e.lengths;let s=0;for(let c=0;c<r.length;c++){const e=r[c];let l=o[t*s],u=o[t*s+1];for(let r=1;r<e;r++){const e=o[t*(s+r)],c=o[t*(s+r)+1],i=e-l,f=c-u;n.coords[t*(s+r)]=i,n.coords[t*(s+r)+1]=f,l=e,u=c}s+=e}return n}function we(e,t){if(n(e))return null;const o=e.clone(),r=e.coords,s=e.lengths;let c=0;for(let n=0;n<s.length;n++){const e=s[n];let l=r[t*c],u=r[t*c+1];for(let n=1;n<e;n++){const e=l+r[t*(c+n)],s=u+r[t*(c+n)+1];o.coords[t*(c+n)]=e,o.coords[t*(c+n)+1]=s,l=e,u=s}c+=e}return o}export{Q as convertFromFeature,ce as convertFromFeatureSet,W as convertFromFeatures,te as convertFromGeometry,X as convertFromGraphics,U as convertFromMultipoint,O as convertFromMultipointFeatures,H as convertFromNestedArray,V as convertFromPoint,S as convertFromPointFeatures,D as convertFromPolygon,$ as convertFromPolyline,q as convertFromPolylineFeatures,ee as convertToFeature,se as convertToFeatureSet,re as convertToFeatures,ne as convertToGeometry,_ as convertToMultipoint,Y as convertToMultipointFeatures,G as convertToPoint,C as convertToPolygon,L as convertToPolyline,we as deltaDecodeGeometry,Me as deltaEncodeGeometry,fe as generalizeOptimizedGeometry,ge as getBoundsOptimizedGeometry,be as getQuantizedArea,de as getQuantizedBoundsOptimizedGeometry,Ie as getSignedQuantizedRingArea,ue as quantizeOptimizedFeatureSet,ie as quantizeOptimizedGeometry,b as quantizeX,M as quantizeY,pe as removeCollinearVectices,ye as removeZMValues,le as unquantizeOptimizedFeatureSet,me as unquantizeOptimizedGeometry,w as unquantizeX,N as unquantizeY};
|