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