Skip to content

Commit

Permalink
Add WGS84 to @turf/helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Sep 27, 2017
1 parent 1395703 commit acefd9c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/turf-helpers/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,13 @@ export function isNumber(num: any): boolean
* http://turfjs.org/docs/#isobject
*/
export function isObject(input: any): boolean

/**
* http://turfjs.org/docs/#wgs84
*/
export const wgs84: {
RADIUS: number
FLATTENING_DENOM: number
FLATTENING: number
POLAR_RADIUS: number
}
18 changes: 18 additions & 0 deletions packages/turf-helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ const areaFactors = {
feet: 10.763910417,
inches: 1550.003100006
};

/**
* Round number to precision
*
Expand Down Expand Up @@ -533,3 +534,20 @@ export function isNumber(num) {
export function isObject(input) {
return (!!input) && (input.constructor === Object);
}

const RADIUS = 6378137;
const FLATTENING_DENOM = 298.257223563;
const FLATTENING = 1 / FLATTENING_DENOM;
const POLAR_RADIUS = RADIUS * (1 - FLATTENING);

/**
* WGS84 Provides radius, FLATTENING, and POLAR_RADIUS constants from the reference ellipsoid.
*
* http://earth-info.nga.mil/GandG/wgs84/gravitymod/egm96/egm96.html
*/
export const wgs84 = {
RADIUS,
FLATTENING_DENOM,
FLATTENING,
POLAR_RADIUS,
};
7 changes: 7 additions & 0 deletions packages/turf-helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
convertArea,
isNumber,
isObject,
wgs84,
// Typescript types
Point,
LineString,
Expand Down Expand Up @@ -156,3 +157,9 @@ const polyGeom: Polygon = geometry('Polygon', poly.geometry.coordinates);
const multiPtGeom: MultiPoint = geometry('MultiPoint', multiPt.geometry.coordinates);
const multiLineGeom: MultiLineString = geometry('MultiLineString', multiLine.geometry.coordinates);
const multiPolyGeom: MultiPolygon = geometry('MultiPolygon', multiPoly.geometry.coordinates);

// WGS84
wgs84.FLATTENING
wgs84.FLATTENING_DENOM
wgs84.POLAR_RADIUS
wgs84.RADIUS
3 changes: 2 additions & 1 deletion packages/turf/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ export {
convertDistance,
isNumber,
round,
convertArea
convertArea,
wgs84
} from '@turf/helpers';
import * as helpers from '@turf/helpers';
export { helpers };
Expand Down
3 changes: 2 additions & 1 deletion packages/turf/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ export {
isNumber,
isObject,
round,
convertArea
convertArea,
wgs84
} from '@turf/helpers';
import * as helpers from '@turf/helpers';
export { helpers };
Expand Down

0 comments on commit acefd9c

Please sign in to comment.