UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 4.26 kB
import{lerp as e}from"../../../core/mathUtils.js";import{isNone as t,unwrapOr as n,isSome as r}from"../../../core/maybe.js";import{throwIfAborted as s}from"../../../core/promiseUtils.js";import{getMetersPerUnitForSR as o}from"../../../core/unitUtils.js";import{d as a,l as i}from"../../../chunks/vec2.js";import{h as c}from"../../../chunks/vec3.js";import u from"../../../geometry/Polyline.js";import{initializeProjection as f,project as l}from"../../../geometry/projection.js";import h from"../../../geometry/SpatialReference.js";import{geodesicLengths as p,isSupported as m,inverseGeodeticSolver as d,directGeodeticSolver as g}from"../../../geometry/support/geodesicUtils.js";import{ProfileGenerationError as y,ProfileGenerationErrorCause as w}from"./ProfileGenerationError.js";async function R(e,t,n,r,a,i,c){let u,m,d;const g=e.spatialReference,R=g.isGeographic||g.isWebMercator,P=await import("../../../geometry/geometryEngineAsync.js");s(c);let Z=0;R||(Z=await P.planarLength(e,"meters"),s(c));const M=1/o(r);if(R||Z>=a.geodesicDistanceThreshold){await f([{source:g,dest:r},{source:g,dest:h.WGS84}],c);const s=D(e);u=p([s],"meters")[0];const o=j(u,a);if(q(e,u,o)>i)throw new y(w.TooComplex);const R=v(s,t,n);({densifiedPath:m,distances:d}=G(R,o,M)),m=l(m,r)}else{await f([{source:g,dest:r}],c),u=Z;const o=j(u,a);if(q(e,u,o)>i)throw new y(w.TooComplex);const h=v(e,t,n);({densifiedPath:m,distances:d}=z(h,o,M)),s(c),m=l(m,r)}return{densifiedPath:m,pathLength:u*M,distances:d}}function j(e,t){const n=e/t.densificationMaxSamples;return Math.max(t.samplingDistance,n)}function v(e,r,s){if(t(r))return M(e);const o=e.spatialReference,a=r.mode,i=n(r.offset,0);let c=null;switch(s.type){case"2d":c=P(e,a,i);break;case"3d":c=Z(e,a,i,s)}return t(c)?M(e):new u({hasZ:!0,hasM:!1,spatialReference:o,paths:x(e.paths,c)})}function P({hasZ:e},t,n){return"absolute-height"===t?e?([e,t,r])=>[e,t,r+n]:([e,t])=>[e,t,n]:null}function Z({spatialReference:e,hasZ:t},r,s,{elevationProvider:o}){const a=(t,r,s,a)=>n(o?.getElevation(t,r,s,e,a),0);switch(r){case"on-the-ground":return([e,t])=>[e,t,a(e,t,0,"ground")];case"absolute-height":return t?([e,t,n])=>[e,t,n+s]:([e,t])=>[e,t,s];case"relative-to-ground":return t?([e,t,n])=>[e,t,n+a(e,t,n,"ground")+s]:([e,t])=>[e,t,a(e,t,0,"ground")+s];case"relative-to-scene":return t?([e,t,n])=>[e,t,n+a(e,t,n,"scene")+s]:([e,t])=>[e,t,a(e,t,0,"scene")+s];default:return null}}function M(e){return e.hasZ?new u({hasZ:!1,hasM:!1,spatialReference:e.spatialReference,paths:x(e.paths,(([e,t])=>[e,t]))}):e}function x(e,t){const n=e.length,r=new Array(n);for(let s=0;s<n;++s){const n=e[s],o=n.length,a=new Array(n.length);r[s]=a;for(let e=0;e<o;++e)a[e]=t(n[e])}return r}function A(e){return S(e)&&e.paths.length>0&&e.paths.every((e=>e.length>=2))}function S(e){return r(e)&&"polyline"===e.type}function b(e,t,n,r,s){const{spatialReference:a,hasZ:i}=e,c={from:null,to:null,distance:0,azimuth:0,reverseAzimuth:0,spatialReference:a,metersPerSR:o(a)},f=[],l=[];let h=0;for(let o=0;o<e.paths.length;++o){const a=e.paths[o],i=new Array,u=new Array;let p=0;for(let e=1;e<a.length;++e){const o=a[e-1],f=a[e],l=r(c,o,f);let m;for(m=p;m<l.distance;m+=t)i.push(s(l,m)),u.push((h+m)*n);p=m-l.distance,h+=l.distance,i.push(f),u.push(h*n)}f[o]=i,l[o]=u}return{densifiedPath:new u({spatialReference:a,hasZ:i,paths:f}),distances:l}}function z(e,t,n){const{hasZ:r}=e;return b(e,t,n,k,r?C:W)}function G(e,t,n){const{hasZ:r}=e;return b(e,t,n,U,r?T:E)}function U(e,t,n){return e.distance=0,d(e,t,n,e.spatialReference),e.from=t,e.to=n,e}function k(e,t,n){return e.from=t,e.to=n,e.distance=a(n,t)*e.metersPerSR,e}function E({from:e,azimuth:t,spatialReference:n},r){return g([0,0],e,t,r,n)}function T({from:t,to:n,azimuth:r,distance:s,spatialReference:o},a){const i=a/s,c=[0,0,e(t[2],n[2],i)];return g(c,t,r,a,o),c}function W({from:e,to:t,distance:n},r){return i([0,0],e,t,r/n)}function C({from:e,to:t,distance:n},r){return c([0,0,0],e,t,r/n)}function D(e){return m(e.spatialReference)?e:l(e,h.WGS84)}function L(e){return e.paths.reduce(((e,t)=>e+t.length),0)}function q(e,t,n){return L(e)+Math.floor(t/n)+Math.max(0,e.paths.reduce((e=>1+e),0)-1)}export{L as countPoints,R as densifyPath,S as isPolyline,A as isValidInputPath,v as toAbsoluteHeightElevation};