Skip to content

Commit

Permalink
added hectares to convertArea (#1943)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour authored Nov 16, 2020
1 parent 23d5cb9 commit 321991c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/turf-helpers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
5 changes: 3 additions & 2 deletions packages/turf-helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type Coord = Feature<Point> | 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";

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/turf-helpers/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit 321991c

Please sign in to comment.