geomasync.js 13 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.24/esri/copyright.txt for details.
  4. */
  5. import{version as n}from"../../kernel.js";import{cloneGeometry as t,convertSquareUnitsToCode as r,convertLinearUnitsToCode as e}from"../kernel.js";import{H as i,p as o,j as l,h as u,l as a,n as s,A as c,y as f,C as g,K as m,J as w,L as h,f as d,g as p}from"../../chunks/languageUtils.js";import{centroidPolyline as A,centroidMultiPoint as y,getMetersPerVerticalUnitForSR as E,segmentLength3d as I}from"./centroid.js";import F from"../../geometry/Extent.js";import R from"../../geometry/Geometry.js";import{disjoint as x,intersects as b,touches as N,crosses as j,within as S,contains as k,overlaps as M,equals as O,relate as P,intersect as Z,union as z,difference as L,symmetricDifference as v,clip as C,cut as J,planarArea as U,geodesicArea as T,planarLength as W,geodesicLength as q,distance as G,densify as H,geodesicDensify as K,generalize as V,buffer as B,geodesicBuffer as D,offset as Q,rotate as X,simplify as Y,isSimple as $}from"../../geometry/geometryEngineAsync.js";import _ from"../../geometry/Multipoint.js";import nn from"../../geometry/Point.js";import tn from"../../geometry/Polygon.js";import rn from"../../geometry/Polyline.js";import{fromJSON as en}from"../../geometry/support/jsonUtils.js";import{getMetersPerUnitForSR as on}from"../../core/unitUtils.js";function ln(t){return 0===n.indexOf("4.")?tn.fromExtent(t):new tn({spatialReference:t.spatialReference,rings:[[[t.xmin,t.ymin],[t.xmin,t.ymax],[t.xmax,t.ymax],[t.xmax,t.ymin],[t.xmin,t.ymin]]]})}function un(n){if(o(n,2,2),n[0]instanceof R&&n[1]instanceof R);else if(n[0]instanceof R&&null===n[1]);else if(n[1]instanceof R&&null===n[0]);else if(null!==n[0]||null!==n[1])throw new Error("Illegal Argument")}async function an(n,t){if("polygon"!==n.type&&"polyline"!==n.type&&"extent"!==n.type)return 0;let r=1;if(n.spatialReference.vcsWkid||n.spatialReference.latestVcsWkid){r=E(n.spatialReference)/on(n.spatialReference)}let e=0;if("polyline"===n.type)for(const o of n.paths)for(let n=1;n<o.length;n++)e+=I(o[n],o[n-1],r);else if("polygon"===n.type)for(const o of n.rings){for(let n=1;n<o.length;n++)e+=I(o[n],o[n-1],r);(o[0][0]!==o[o.length-1][0]||o[0][1]!==o[o.length-1][1]||void 0!==o[0][2]&&o[0][2]!==o[o.length-1][2])&&(e+=I(o[0],o[o.length-1],r))}else"extent"===n.type&&(e+=2*I([n.xmin,n.ymin,0],[n.xmax,n.ymin,0],r),e+=2*I([n.xmin,n.ymin,0],[n.xmin,n.ymax,0],r),e*=2,e+=4*Math.abs(g(n.zmax,0)*r-g(n.zmin,0)*r));const i=new rn({hasZ:!1,hasM:!1,spatialReference:n.spatialReference,paths:[[0,0],[0,e]]});return W(i,t)}function sn(n){"async"===n.mode&&(n.functions.disjoint=function(t,r){return n.standardFunctionAsync(t,r,(function(n,t,r){return un(r=i(r)),null===r[0]||null===r[1]||x(r[0],r[1])}))},n.functions.intersects=function(t,r){return n.standardFunctionAsync(t,r,(function(n,t,r){return un(r=i(r)),null!==r[0]&&null!==r[1]&&b(r[0],r[1])}))},n.functions.touches=function(t,r){return n.standardFunctionAsync(t,r,(function(n,t,r){return un(r=i(r)),null!==r[0]&&null!==r[1]&&N(r[0],r[1])}))},n.functions.crosses=function(t,r){return n.standardFunctionAsync(t,r,(function(n,t,r){return un(r=i(r)),null!==r[0]&&null!==r[1]&&j(r[0],r[1])}))},n.functions.within=function(t,r){return n.standardFunctionAsync(t,r,(function(n,t,r){return un(r=i(r)),null!==r[0]&&null!==r[1]&&S(r[0],r[1])}))},n.functions.contains=function(t,r){return n.standardFunctionAsync(t,r,(function(n,t,r){return un(r=i(r)),null!==r[0]&&null!==r[1]&&k(r[0],r[1])}))},n.functions.overlaps=function(t,r){return n.standardFunctionAsync(t,r,(function(n,t,r){return un(r=i(r)),null!==r[0]&&null!==r[1]&&M(r[0],r[1])}))},n.functions.equals=function(t,r){return n.standardFunctionAsync(t,r,(function(n,t,r){return o(r,2,2),r[0]===r[1]||(r[0]instanceof R&&r[1]instanceof R?O(r[0],r[1]):!(!l(r[0])||!l(r[1]))&&r[0].getTime()===r[1].getTime())}))},n.functions.relate=function(t,r){return n.standardFunctionAsync(t,r,(function(n,t,r){if(r=i(r),o(r,3,3),r[0]instanceof R&&r[1]instanceof R)return P(r[0],r[1],u(r[2]));if(r[0]instanceof R&&null===r[1])return!1;if(r[1]instanceof R&&null===r[0])return!1;if(null===r[0]&&null===r[1])return!1;throw new Error("Illegal Argument")}))},n.functions.intersection=function(t,r){return n.standardFunctionAsync(t,r,(function(n,t,r){return un(r=i(r)),null===r[0]||null===r[1]?null:Z(r[0],r[1])}))},n.functions.union=function(r,e){return n.standardFunctionAsync(r,e,(function(n,e,o){const l=[];if(0===(o=i(o)).length)throw new Error("Function called with wrong number of Parameters");if(1===o.length)if(a(o[0])){const n=i(o[0]);for(let t=0;t<n.length;t++)if(null!==n[t]){if(!(n[t]instanceof R))throw new Error("Illegal Argument");l.push(n[t])}}else{if(!s(o[0])){if(o[0]instanceof R)return c(t(o[0]),r.spatialReference);if(null===o[0])return null;throw new Error("Illegal Argument")}{const n=i(o[0].toArray());for(let t=0;t<n.length;t++)if(null!==n[t]){if(!(n[t]instanceof R))throw new Error("Illegal Argument");l.push(n[t])}}}else for(let t=0;t<o.length;t++)if(null!==o[t]){if(!(o[t]instanceof R))throw new Error("Illegal Argument");l.push(o[t])}return 0===l.length?null:z(l)}))},n.functions.difference=function(r,e){return n.standardFunctionAsync(r,e,(function(n,r,e){return un(e=i(e)),null!==e[0]&&null===e[1]?t(e[0]):null===e[0]?null:L(e[0],e[1])}))},n.functions.symmetricdifference=function(r,e){return n.standardFunctionAsync(r,e,(function(n,r,e){return un(e=i(e)),null===e[0]&&null===e[1]?null:null===e[0]?t(e[1]):null===e[1]?t(e[0]):v(e[0],e[1])}))},n.functions.clip=function(t,r){return n.standardFunctionAsync(t,r,(function(n,t,r){if(r=i(r),o(r,2,2),!(r[1]instanceof F)&&null!==r[1])throw new Error("Illegal Argument");if(null===r[0])return null;if(!(r[0]instanceof R))throw new Error("Illegal Argument");return null===r[1]?null:C(r[0],r[1])}))},n.functions.cut=function(r,e){return n.standardFunctionAsync(r,e,(function(n,r,e){if(e=i(e),o(e,2,2),!(e[1]instanceof rn)&&null!==e[1])throw new Error("Illegal Argument");if(null===e[0])return[];if(!(e[0]instanceof R))throw new Error("Illegal Argument");return null===e[1]?[t(e[0])]:J(e[0],e[1])}))},n.functions.area=function(t,e){return n.standardFunctionAsync(t,e,(async function(n,e,l){if(o(l,1,2),null===(l=i(l))[0])return 0;if(f(l[0])){const n=await l[0].sumArea(r(g(l[1],-1)),!1,t.abortSignal);if(t.abortSignal.aborted)throw new Error("Operation has been cancelled.");return n}if(a(l[0])||s(l[0])){const n=m(l[0],t.spatialReference);return null===n?0:U(n,r(g(l[1],-1)))}if(!(l[0]instanceof R))throw new Error("Illegal Argument");return U(l[0],r(g(l[1],-1)))}))},n.functions.areageodetic=function(t,e){return n.standardFunctionAsync(t,e,(async function(n,e,l){if(o(l,1,2),null===(l=i(l))[0])return 0;if(f(l[0])){const n=await l[0].sumArea(r(g(l[1],-1)),!0,t.abortSignal);if(t.abortSignal.aborted)throw new Error("Operation has been cancelled.");return n}if(a(l[0])||s(l[0])){const n=m(l[0],t.spatialReference);return null===n?0:T(n,r(g(l[1],-1)))}if(!(l[0]instanceof R))throw new Error("Illegal Argument");return T(l[0],r(g(l[1],-1)))}))},n.functions.length=function(t,r){return n.standardFunctionAsync(t,r,(async function(n,r,l){if(o(l,1,2),null===(l=i(l))[0])return 0;if(f(l[0])){const n=await l[0].sumLength(e(g(l[1],-1)),!1,t.abortSignal);if(t.abortSignal.aborted)throw new Error("Operation has been cancelled.");return n}if(a(l[0])||s(l[0])){const n=w(l[0],t.spatialReference);return null===n?0:W(n,e(g(l[1],-1)))}if(!(l[0]instanceof R))throw new Error("Illegal Argument");return W(l[0],e(g(l[1],-1)))}))},n.functions.length3d=function(t,r){return n.standardFunctionAsync(t,r,(function(n,r,l){if(o(l,1,2),null===(l=i(l))[0])return 0;if(a(l[0])||s(l[0])){const n=w(l[0],t.spatialReference);return null===n?0:!0===n.hasZ?an(n,e(g(l[1],-1))):W(n,e(g(l[1],-1)))}if(!(l[0]instanceof R))throw new Error("Illegal Argument");return!0===l[0].hasZ?an(l[0],e(g(l[1],-1))):W(l[0],e(g(l[1],-1)))}))},n.functions.lengthgeodetic=function(t,r){return n.standardFunctionAsync(t,r,(async function(n,r,l){if(o(l,1,2),null===(l=i(l))[0])return 0;if(f(l[0])){const n=await l[0].sumLength(e(g(l[1],-1)),!0,t.abortSignal);if(t.abortSignal.aborted)throw new Error("Operation has been cancelled.");return n}if(a(l[0])||s(l[0])){const n=w(l[0],t.spatialReference);return null===n?0:q(n,e(g(l[1],-1)))}if(!(l[0]instanceof R))throw new Error("Illegal Argument");return q(l[0],e(g(l[1],-1)))}))},n.functions.distance=function(t,r){return n.standardFunctionAsync(t,r,(function(n,r,l){l=i(l),o(l,2,3);let u=l[0];(a(l[0])||s(l[0]))&&(u=h(l[0],t.spatialReference));let c=l[1];if((a(l[1])||s(l[1]))&&(c=h(l[1],t.spatialReference)),!(u instanceof R))throw new Error("Illegal Argument");if(!(c instanceof R))throw new Error("Illegal Argument");return G(u,c,e(g(l[2],-1)))}))},n.functions.distancegeodetic=function(t,r){return n.standardFunctionAsync(t,r,(function(n,t,r){r=i(r),o(r,2,3);const l=r[0],u=r[1];if(!(l instanceof nn))throw new Error("Illegal Argument");if(!(u instanceof nn))throw new Error("Illegal Argument");const a=new rn({paths:[],spatialReference:l.spatialReference});return a.addPath([l,u]),q(a,e(g(r[2],-1)))}))},n.functions.densify=function(t,r){return n.standardFunctionAsync(t,r,(function(n,t,r){if(r=i(r),o(r,2,3),null===r[0])return null;if(!(r[0]instanceof R))throw new Error("Illegal Argument");const l=d(r[1]);if(isNaN(l))throw new Error("Illegal Argument");if(l<=0)throw new Error("Illegal Argument");return r[0]instanceof tn||r[0]instanceof rn?H(r[0],l,e(g(r[2],-1))):r[0]instanceof F?H(ln(r[0]),l,e(g(r[2],-1))):r[0]}))},n.functions.densifygeodetic=function(t,r){return n.standardFunctionAsync(t,r,(function(n,t,r){if(r=i(r),o(r,2,3),null===r[0])return null;if(!(r[0]instanceof R))throw new Error("Illegal Argument");const l=d(r[1]);if(isNaN(l))throw new Error("Illegal Argument");if(l<=0)throw new Error("Illegal Argument");return r[0]instanceof tn||r[0]instanceof rn?K(r[0],l,e(g(r[2],-1))):r[0]instanceof F?K(ln(r[0]),l,e(g(r[2],-1))):r[0]}))},n.functions.generalize=function(t,r){return n.standardFunctionAsync(t,r,(function(n,t,r){if(r=i(r),o(r,2,4),null===r[0])return null;if(!(r[0]instanceof R))throw new Error("Illegal Argument");const l=d(r[1]);if(isNaN(l))throw new Error("Illegal Argument");return V(r[0],l,p(g(r[2],!0)),e(g(r[3],-1)))}))},n.functions.buffer=function(r,l){return n.standardFunctionAsync(r,l,(function(n,r,l){if(l=i(l),o(l,2,3),null===l[0])return null;if(!(l[0]instanceof R))throw new Error("Illegal Argument");const u=d(l[1]);if(isNaN(u))throw new Error("Illegal Argument");return 0===u?t(l[0]):B(l[0],u,e(g(l[2],-1)))}))},n.functions.buffergeodetic=function(r,l){return n.standardFunctionAsync(r,l,(function(n,r,l){if(l=i(l),o(l,2,3),null===l[0])return null;if(!(l[0]instanceof R))throw new Error("Illegal Argument");const u=d(l[1]);if(isNaN(u))throw new Error("Illegal Argument");return 0===u?t(l[0]):D(l[0],u,e(g(l[2],-1)))}))},n.functions.offset=function(t,r){return n.standardFunctionAsync(t,r,(function(n,t,r){if(r=i(r),o(r,2,6),null===r[0])return null;if(!(r[0]instanceof tn||r[0]instanceof rn))throw new Error("Illegal Argument");const l=d(r[1]);if(isNaN(l))throw new Error("Illegal Argument");const a=d(g(r[4],10));if(isNaN(a))throw new Error("Illegal Argument");const s=d(g(r[5],0));if(isNaN(s))throw new Error("Illegal Argument");return Q(r[0],l,e(g(r[2],-1)),u(g(r[3],"round")).toLowerCase(),a,s)}))},n.functions.rotate=function(t,r){return n.standardFunctionAsync(t,r,(function(n,t,r){r=i(r),o(r,2,3);let e=r[0];if(null===e)return null;if(!(e instanceof R))throw new Error("Illegal Argument");e instanceof F&&(e=tn.fromExtent(e));const l=d(r[1]);if(isNaN(l))throw new Error("Illegal Argument");const u=g(r[2],null);if(null===u)return X(e,l);if(u instanceof nn)return X(e,l,u);throw new Error("Illegal Argument")}))},n.functions.centroid=function(r,e){return n.standardFunctionAsync(r,e,(function(n,e,l){if(l=i(l),o(l,1,1),null===l[0])return null;let u=l[0];if((a(l[0])||s(l[0]))&&(u=h(l[0],r.spatialReference)),null===u)return null;if(!(u instanceof R))throw new Error("Illegal Argument");return u instanceof nn?c(t(l[0]),r.spatialReference):u instanceof tn?u.centroid:u instanceof rn?A(u):u instanceof _?y(u):u instanceof F?u.center:null}))},n.functions.multiparttosinglepart=function(r,e){return n.standardFunctionAsync(r,e,(async function(n,e,l){l=i(l),o(l,1,1);const u=[];if(null===l[0])return null;if(!(l[0]instanceof R))throw new Error("Illegal Argument");if(l[0]instanceof nn)return[c(t(l[0]),r.spatialReference)];if(l[0]instanceof F)return[c(t(l[0]),r.spatialReference)];const a=await Y(l[0]);if(a instanceof tn){const n=[],t=[];for(let r=0;r<a.rings.length;r++)if(a.isClockwise(a.rings[r])){const t=en({rings:[a.rings[r]],hasZ:!0===a.hasZ,hazM:!0===a.hasM,spatialReference:a.spatialReference.toJSON()});n.push(t)}else t.push({ring:a.rings[r],pt:a.getPoint(r,0)});for(let r=0;r<t.length;r++)for(let e=0;e<n.length;e++)if(n[e].contains(t[r].pt)){n[e].addRing(t[r].ring);break}return n}if(a instanceof rn){const n=[];for(let t=0;t<a.paths.length;t++){const r=en({paths:[a.paths[t]],hasZ:!0===a.hasZ,hazM:!0===a.hasM,spatialReference:a.spatialReference.toJSON()});n.push(r)}return n}if(l[0]instanceof _){const n=c(t(l[0]),r.spatialReference);for(let t=0;t<n.points.length;t++)u.push(n.getPoint(t));return u}return null}))},n.functions.issimple=function(t,r){return n.standardFunctionAsync(t,r,(function(n,t,r){if(r=i(r),o(r,1,1),null===r[0])return!0;if(!(r[0]instanceof R))throw new Error("Illegal Argument");return $(r[0])}))},n.functions.simplify=function(t,r){return n.standardFunctionAsync(t,r,(function(n,t,r){if(r=i(r),o(r,1,1),null===r[0])return null;if(!(r[0]instanceof R))throw new Error("Illegal Argument");return Y(r[0])}))})}export{sn as registerFunctions};