UNPKG

s2-tools

Version:

A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.

63 lines 1.8 kB
import { ellipsoids } from './ellipsoid'; import { EPSLN, RA4, RA6, SIXTH } from './values'; /** * Derives an ellipsoid's eccentricity for an object * @param el - ellipsoid object to modify */ export function deriveEccentricity(el) { let a = el.a ?? 0; const b = el.b ?? 0; let a2 = a * a; // used in geocentric const b2 = b * b; // used in geocentric let es = (a2 - b2) / a2; // e ^ 2 let e = 0; if (el.rA === true) { a *= 1 - es * (SIXTH + es * (RA4 + es * RA6)); a2 = a * a; es = 0; } else { e = Math.sqrt(es); // eccentricity } const ep2 = (a2 - b2) / b2; // used in geocentric el.es = es; el.e = e; el.ep2 = ep2; } /** * Builds a sphere with ellipsoid parameters * @param obj - an object with/wihtout sphere properties and builds the sphere */ export function deriveSphere(obj) { if (obj.a === undefined) { // do we have an ellipsoid? let ellipse = match(ellipsoids, obj.ellps); if (ellipse === undefined) ellipse = ellipsoids.WGS84; obj.a = ellipse.a; obj.b = ellipse.b; obj.rf = ellipse.rf; } if (obj.rf !== undefined && obj.b === undefined) { obj.b = (1.0 - 1.0 / obj.rf) * obj.a; } if (obj.rf === undefined && obj.b !== undefined) { obj.rf = (obj.a - obj.b) / obj.a; } if (obj.rf === 0 || (obj.b !== undefined && Math.abs(obj.a - obj.b) < EPSLN)) { obj.sphere = true; obj.b = obj.a; } } /** * @param obj - the object to search * @param key - the key to search with * @returns - the value of the key */ function match(obj, key) { if (key === undefined) return; if (obj[key] !== undefined) return obj[key]; } //# sourceMappingURL=derives.js.map