From 321991ce0ea2130e2701ac7563f97fe19e16bd54 Mon Sep 17 00:00:00 2001 From: "Daniel J. Dufour" Date: Mon, 16 Nov 2020 15:05:01 -0500 Subject: [PATCH] added hectares to convertArea (#1943) --- packages/turf-helpers/README.md | 2 +- packages/turf-helpers/index.ts | 5 +++-- packages/turf-helpers/test.js | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/turf-helpers/README.md b/packages/turf-helpers/README.md index 75ee559dcf..05aeff79f5 100644 --- a/packages/turf-helpers/README.md +++ b/packages/turf-helpers/README.md @@ -453,7 +453,7 @@ Returns **[number][6]** the converted length ## convertArea Converts a area to the requested unit. -Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches +Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches, hectares **Parameters** diff --git a/packages/turf-helpers/index.ts b/packages/turf-helpers/index.ts index f2d370dc80..6d1502af4a 100644 --- a/packages/turf-helpers/index.ts +++ b/packages/turf-helpers/index.ts @@ -19,7 +19,7 @@ export type Coord = Feature | Point | Position; // TurfJS String Types export type Units = "meters" | "millimeters" | "centimeters" | "kilometers" | "acres" | "miles" | "nauticalmiles" | - "inches" | "yards" | "feet" | "radians" | "degrees"; + "inches" | "yards" | "feet" | "radians" | "degrees" | "hectares"; export type Grid = "point" | "square" | "hex" | "triangle"; export type Corners = "sw" | "se" | "nw" | "ne" | "center" | "centroid"; @@ -97,6 +97,7 @@ export let areaFactors: any = { centimeters: 10000, centimetres: 10000, feet: 10.763910417, + hectares: 0.0001, inches: 1550.003100006, kilometers: 0.000001, kilometres: 0.000001, @@ -628,7 +629,7 @@ export function convertLength( /** * Converts a area to the requested unit. - * Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches + * Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches, hectares * @param {number} area to be converted * @param {Units} [originalUnit="meters"] of the distance * @param {Units} [finalUnit="kilometers"] returned unit diff --git a/packages/turf-helpers/test.js b/packages/turf-helpers/test.js index 3d9c7dbfed..87465cf7d6 100644 --- a/packages/turf-helpers/test.js +++ b/packages/turf-helpers/test.js @@ -354,6 +354,7 @@ test('convertArea', t => { t.equal(convertArea(100, undefined, 'yards'), 119.59900459999999); t.equal(convertArea(100, 'metres', 'feet'), 1076.3910417); t.equal(convertArea(100000, 'feet', undefined), 0.009290303999749462); + t.equal(convertArea(1, 'meters', 'hectares'), 0.0001); // t.throws(() => convertLength(1, 'foo'), 'invalid original units'); // t.throws(() => convertLength(1, 'meters', 'foo'), 'invalid final units');