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 e,convertSquareUnitsToCode as t,convertLinearUnitsToCode as r}from"../kernel.js";import{G as i,y as a,k as l,j as o,m as f,x as s,q as u,J as c,A as m,H as h,K as w,g as p,h as d}from"../../chunks/languageUtils.js";import{centroidPolyline as g,centroidMultiPoint as P,getMetersPerVerticalUnitForSR as v,segmentLength3d as I}from"./centroid.js";import y from"../../geometry/Extent.js";import R from"../../geometry/Geometry.js";import x from"../../geometry/Multipoint.js";import N from"../../geometry/Point.js";import j from"../../geometry/Polygon.js";import L from"../../geometry/Polyline.js";import{fromJSON as k}from"../../geometry/support/jsonUtils.js";import{ArcadeExecutionError as M,ExecutionErrorCodes as Z}from"../executionError.js";import{getMetersPerUnitForSR as b}from"../../core/unitUtils.js";let A=null;function z(e){return 0===n.indexOf("4.")?j.fromExtent(e):new j({spatialReference:e.spatialReference,rings:[[[e.xmin,e.ymin],[e.xmin,e.ymax],[e.xmax,e.ymax],[e.xmax,e.ymin],[e.xmin,e.ymin]]]})}function E(n){A=n}function O(n,e){if("polygon"!==n.type&&"polyline"!==n.type&&"extent"!==n.type)return 0;let t=1;if(n.spatialReference.vcsWkid||n.spatialReference.latestVcsWkid){t=v(n.spatialReference)/b(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],t);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],t);(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],t))}else"extent"===n.type&&(r+=2*I([n.xmin,n.ymin,0],[n.xmax,n.ymin,0],t),r+=2*I([n.xmin,n.ymin,0],[n.xmin,n.ymax,0],t),r*=2,r+=4*Math.abs(m(n.zmax,0)*t-m(n.zmin,0)*t));const i=new L({hasZ:!1,hasM:!1,spatialReference:n.spatialReference,paths:[[0,0],[0,r]]});return A.planarLength(i,e)}function q(n,v){function I(n,e,t){if(a(t,2,2,n,e),t[0]instanceof R&&t[1]instanceof R);else if(t[0]instanceof R&&null===t[1]);else if(t[1]instanceof R&&null===t[0]);else if(null!==t[0]||null!==t[1])throw new M(n,Z.InvalidParameter,e)}n.disjoint=function(n,e){return v(n,e,((t,r,a)=>(a=i(a),I(n,e,a),null===a[0]||null===a[1]||A.disjoint(a[0],a[1]))))},n.intersects=function(n,e){return v(n,e,((t,r,a)=>(a=i(a),I(n,e,a),null!==a[0]&&null!==a[1]&&A.intersects(a[0],a[1]))))},n.touches=function(n,e){return v(n,e,((t,r,a)=>(a=i(a),I(n,e,a),null!==a[0]&&null!==a[1]&&A.touches(a[0],a[1]))))},n.crosses=function(n,e){return v(n,e,((t,r,a)=>(a=i(a),I(n,e,a),null!==a[0]&&null!==a[1]&&A.crosses(a[0],a[1]))))},n.within=function(n,e){return v(n,e,((t,r,a)=>(a=i(a),I(n,e,a),null!==a[0]&&null!==a[1]&&A.within(a[0],a[1]))))},n.contains=function(n,e){return v(n,e,((t,r,a)=>(a=i(a),I(n,e,a),null!==a[0]&&null!==a[1]&&A.contains(a[0],a[1]))))},n.overlaps=function(n,e){return v(n,e,((t,r,a)=>(a=i(a),I(n,e,a),null!==a[0]&&null!==a[1]&&A.overlaps(a[0],a[1]))))},n.equals=function(n,e){return v(n,e,((t,r,i)=>(a(i,2,2,n,e),i[0]===i[1]||(i[0]instanceof R&&i[1]instanceof R?A.equals(i[0],i[1]):!(!l(i[0])||!l(i[1]))&&i[0].getTime()===i[1].getTime()))))},n.relate=function(n,e){return v(n,e,((t,r,l)=>{if(l=i(l),a(l,3,3,n,e),l[0]instanceof R&&l[1]instanceof R)return A.relate(l[0],l[1],o(l[2]));if(l[0]instanceof R&&null===l[1])return!1;if(l[1]instanceof R&&null===l[0])return!1;if(null===l[0]&&null===l[1])return!1;throw new M(n,Z.InvalidParameter,e)}))},n.intersection=function(n,e){return v(n,e,((t,r,a)=>(a=i(a),I(n,e,a),null===a[0]||null===a[1]?null:A.intersect(a[0],a[1]))))},n.union=function(n,t){return v(n,t,((r,a,l)=>{const o=[];if(0===(l=i(l)).length)throw new M(n,Z.WrongNumberOfParameters,t);if(1===l.length)if(f(l[0])){const e=i(l[0]);for(let r=0;r<e.length;r++)if(null!==e[r]){if(!(e[r]instanceof R))throw new M(n,Z.InvalidParameter,t);o.push(e[r])}}else{if(!s(l[0])){if(l[0]instanceof R)return u(e(l[0]),n.spatialReference);if(null===l[0])return null;throw new M(n,Z.InvalidParameter,t)}{const e=i(l[0].toArray());for(let r=0;r<e.length;r++)if(null!==e[r]){if(!(e[r]instanceof R))throw new M(n,Z.InvalidParameter,t);o.push(e[r])}}}else for(let e=0;e<l.length;e++)if(null!==l[e]){if(!(l[e]instanceof R))throw new M(n,Z.InvalidParameter,t);o.push(l[e])}return 0===o.length?null:A.union(o)}))},n.difference=function(n,t){return v(n,t,((r,a,l)=>(l=i(l),I(n,t,l),null!==l[0]&&null===l[1]?e(l[0]):null===l[0]?null:A.difference(l[0],l[1]))))},n.symmetricdifference=function(n,t){return v(n,t,((r,a,l)=>(l=i(l),I(n,t,l),null===l[0]&&null===l[1]?null:null===l[0]?e(l[1]):null===l[1]?e(l[0]):A.symmetricDifference(l[0],l[1]))))},n.clip=function(n,e){return v(n,e,((t,r,l)=>{if(l=i(l),a(l,2,2,n,e),!(l[1]instanceof y)&&null!==l[1])throw new M(n,Z.InvalidParameter,e);if(null===l[0])return null;if(!(l[0]instanceof R))throw new M(n,Z.InvalidParameter,e);return null===l[1]?null:A.clip(l[0],l[1])}))},n.cut=function(n,t){return v(n,t,((r,l,o)=>{if(o=i(o),a(o,2,2,n,t),!(o[1]instanceof L)&&null!==o[1])throw new M(n,Z.InvalidParameter,t);if(null===o[0])return[];if(!(o[0]instanceof R))throw new M(n,Z.InvalidParameter,t);return null===o[1]?[e(o[0])]:A.cut(o[0],o[1])}))},n.area=function(n,e){return v(n,e,((r,l,o)=>{if(a(o,1,2,n,e),null===(o=i(o))[0])return 0;if(f(o[0])||s(o[0])){const e=c(o[0],n.spatialReference);return null===e?0:A.planarArea(e,t(m(o[1],-1)))}if(!(o[0]instanceof R))throw new M(n,Z.InvalidParameter,e);return A.planarArea(o[0],t(m(o[1],-1)))}))},n.areageodetic=function(n,e){return v(n,e,((r,l,o)=>{if(a(o,1,2,n,e),null===(o=i(o))[0])return 0;if(f(o[0])||s(o[0])){const e=c(o[0],n.spatialReference);return null===e?0:A.geodesicArea(e,t(m(o[1],-1)))}if(!(o[0]instanceof R))throw new M(n,Z.InvalidParameter,e);return A.geodesicArea(o[0],t(m(o[1],-1)))}))},n.length=function(n,e){return v(n,e,((t,l,o)=>{if(a(o,1,2,n,e),null===(o=i(o))[0])return 0;if(f(o[0])||s(o[0])){const e=h(o[0],n.spatialReference);return null===e?0:A.planarLength(e,r(m(o[1],-1)))}if(!(o[0]instanceof R))throw new M(n,Z.InvalidParameter,e);return A.planarLength(o[0],r(m(o[1],-1)))}))},n.length3d=function(n,e){return v(n,e,((t,l,o)=>{if(a(o,1,2,n,e),null===(o=i(o))[0])return 0;if(f(o[0])||s(o[0])){const e=h(o[0],n.spatialReference);return null===e?0:!0===e.hasZ?O(e,r(m(o[1],-1))):A.planarLength(e,r(m(o[1],-1)))}if(!(o[0]instanceof R))throw new M(n,Z.InvalidParameter,e);return!0===o[0].hasZ?O(o[0],r(m(o[1],-1))):A.planarLength(o[0],r(m(o[1],-1)))}))},n.lengthgeodetic=function(n,e){return v(n,e,((t,l,o)=>{if(a(o,1,2,n,e),null===(o=i(o))[0])return 0;if(f(o[0])||s(o[0])){const e=h(o[0],n.spatialReference);return null===e?0:A.geodesicLength(e,r(m(o[1],-1)))}if(!(o[0]instanceof R))throw new M(n,Z.InvalidParameter,e);return A.geodesicLength(o[0],r(m(o[1],-1)))}))},n.distance=function(n,e){return v(n,e,((t,l,o)=>{o=i(o),a(o,2,3,n,e);let u=o[0];(f(o[0])||s(o[0]))&&(u=w(o[0],n.spatialReference));let c=o[1];if((f(o[1])||s(o[1]))&&(c=w(o[1],n.spatialReference)),!(u instanceof R))throw new M(n,Z.InvalidParameter,e);if(!(c instanceof R))throw new M(n,Z.InvalidParameter,e);return A.distance(u,c,r(m(o[2],-1)))}))},n.distancegeodetic=function(n,e){return v(n,e,((t,l,o)=>{o=i(o),a(o,2,3,n,e);const f=o[0],s=o[1];if(!(f instanceof N))throw new M(n,Z.InvalidParameter,e);if(!(s instanceof N))throw new M(n,Z.InvalidParameter,e);const u=new L({paths:[],spatialReference:f.spatialReference});return u.addPath([f,s]),A.geodesicLength(u,r(m(o[2],-1)))}))},n.densify=function(n,e){return v(n,e,((t,l,o)=>{if(o=i(o),a(o,2,3,n,e),null===o[0])return null;if(!(o[0]instanceof R))throw new M(n,Z.InvalidParameter,e);const f=p(o[1]);if(isNaN(f))throw new M(n,Z.InvalidParameter,e);if(f<=0)throw new M(n,Z.InvalidParameter,e);return o[0]instanceof j||o[0]instanceof L?A.densify(o[0],f,r(m(o[2],-1))):o[0]instanceof y?A.densify(z(o[0]),f,r(m(o[2],-1))):o[0]}))},n.densifygeodetic=function(n,e){return v(n,e,((t,l,o)=>{if(o=i(o),a(o,2,3,n,e),null===o[0])return null;if(!(o[0]instanceof R))throw new M(n,Z.InvalidParameter,e);const f=p(o[1]);if(isNaN(f))throw new M(n,Z.InvalidParameter,e);if(f<=0)throw new M(n,Z.InvalidParameter,e);return o[0]instanceof j||o[0]instanceof L?A.geodesicDensify(o[0],f,r(m(o[2],-1))):o[0]instanceof y?A.geodesicDensify(z(o[0]),f,r(m(o[2],-1))):o[0]}))},n.generalize=function(n,e){return v(n,e,((t,l,o)=>{if(o=i(o),a(o,2,4,n,e),null===o[0])return null;if(!(o[0]instanceof R))throw new M(n,Z.InvalidParameter,e);const f=p(o[1]);if(isNaN(f))throw new M(n,Z.InvalidParameter,e);return A.generalize(o[0],f,d(m(o[2],!0)),r(m(o[3],-1)))}))},n.buffer=function(n,t){return v(n,t,((l,o,f)=>{if(f=i(f),a(f,2,3,n,t),null===f[0])return null;if(!(f[0]instanceof R))throw new M(n,Z.InvalidParameter,t);const s=p(f[1]);if(isNaN(s))throw new M(n,Z.InvalidParameter,t);return 0===s?e(f[0]):A.buffer(f[0],s,r(m(f[2],-1)))}))},n.buffergeodetic=function(n,t){return v(n,t,((l,o,f)=>{if(f=i(f),a(f,2,3,n,t),null===f[0])return null;if(!(f[0]instanceof R))throw new M(n,Z.InvalidParameter,t);const s=p(f[1]);if(isNaN(s))throw new M(n,Z.InvalidParameter,t);return 0===s?e(f[0]):A.geodesicBuffer(f[0],s,r(m(f[2],-1)))}))},n.offset=function(n,e){return v(n,e,((t,l,f)=>{if(f=i(f),a(f,2,6,n,e),null===f[0])return null;if(!(f[0]instanceof j||f[0]instanceof L))throw new M(n,Z.InvalidParameter,e);const s=p(f[1]);if(isNaN(s))throw new M(n,Z.InvalidParameter,e);const u=p(m(f[4],10));if(isNaN(u))throw new M(n,Z.InvalidParameter,e);const c=p(m(f[5],0));if(isNaN(c))throw new M(n,Z.InvalidParameter,e);return A.offset(f[0],s,r(m(f[2],-1)),o(m(f[3],"round")).toLowerCase(),u,c)}))},n.rotate=function(n,e){return v(n,e,((t,r,l)=>{l=i(l),a(l,2,3,n,e);let o=l[0];if(null===o)return null;if(!(o instanceof R))throw new M(n,Z.InvalidParameter,e);o instanceof y&&(o=j.fromExtent(o));const f=p(l[1]);if(isNaN(f))throw new M(n,Z.InvalidParameter,e);const s=m(l[2],null);if(null===s)return A.rotate(o,f);if(s instanceof N)return A.rotate(o,f,s);throw new M(n,Z.InvalidParameter,e)}))},n.centroid=function(n,t){return v(n,t,((r,l,o)=>{if(o=i(o),a(o,1,1,n,t),null===o[0])return null;let c=o[0];if((f(o[0])||s(o[0]))&&(c=w(o[0],n.spatialReference)),null===c)return null;if(!(c instanceof R))throw new M(n,Z.InvalidParameter,t);return c instanceof N?u(e(o[0]),n.spatialReference):c instanceof j?c.centroid:c instanceof L?g(c):c instanceof x?P(c):c instanceof y?c.center:null}))},n.multiparttosinglepart=function(n,t){return v(n,t,((r,l,o)=>{o=i(o),a(o,1,1,n,t);const f=[];if(null===o[0])return null;if(!(o[0]instanceof R))throw new M(n,Z.InvalidParameter,t);if(o[0]instanceof N)return[u(e(o[0]),n.spatialReference)];if(o[0]instanceof y)return[u(e(o[0]),n.spatialReference)];const s=A.simplify(o[0]);if(s instanceof j){const n=[],e=[];for(let t=0;t<s.rings.length;t++)if(s.isClockwise(s.rings[t])){const e=k({rings:[s.rings[t]],hasZ:!0===s.hasZ,hasM:!0===s.hasM,spatialReference:s.spatialReference.toJSON()});n.push(e)}else e.push({ring:s.rings[t],pt:s.getPoint(t,0)});for(let t=0;t<e.length;t++)for(let r=0;r<n.length;r++)if(n[r].contains(e[t].pt)){n[r].addRing(e[t].ring);break}return n}if(s instanceof L){const n=[];for(let e=0;e<s.paths.length;e++){const t=k({paths:[s.paths[e]],hasZ:!0===s.hasZ,hasM:!0===s.hasM,spatialReference:s.spatialReference.toJSON()});n.push(t)}return n}if(o[0]instanceof x){const t=u(e(o[0]),n.spatialReference);for(let n=0;n<t.points.length;n++)f.push(t.getPoint(n));return f}return null}))},n.issimple=function(n,e){return v(n,e,((t,r,l)=>{if(l=i(l),a(l,1,1,n,e),null===l[0])return!0;if(!(l[0]instanceof R))throw new M(n,Z.InvalidParameter,e);return A.isSimple(l[0])}))},n.simplify=function(n,e){return v(n,e,((t,r,l)=>{if(l=i(l),a(l,1,1,n,e),null===l[0])return null;if(!(l[0]instanceof R))throw new M(n,Z.InvalidParameter,e);return A.simplify(l[0])}))},n.convexhull=function(n,e){return v(n,e,((t,r,l)=>{if(l=i(l),a(l,1,1,n,e),null===l[0])return null;if(!(l[0]instanceof R))throw new M(n,Z.InvalidParameter,e);return A.convexHull(l[0])}))}}export{q as registerFunctions,E as setGeometryEngine};
|