@turf/area
Advanced tools
Comparing version 5.1.5 to 6.0.0
74
index.js
@@ -1,3 +0,6 @@ | ||
import { geomReduce } from '@turf/meta'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var meta_1 = require("@turf/meta"); | ||
// Note: change RADIUS => earthRadius | ||
var RADIUS = 6378137; | ||
/** | ||
@@ -19,12 +22,6 @@ * Takes one or more features and returns their area in square meters. | ||
function area(geojson) { | ||
return geomReduce(geojson, function (value, geom) { | ||
return meta_1.geomReduce(geojson, function (value, geom) { | ||
return value + calculateArea(geom); | ||
}, 0); | ||
} | ||
var RADIUS = 6378137; | ||
// var FLATTENING_DENOM = 298.257223563; | ||
// var FLATTENING = 1 / FLATTENING_DENOM; | ||
// var POLAR_RADIUS = RADIUS * (1 - FLATTENING); | ||
/** | ||
@@ -34,28 +31,23 @@ * Calculate Area | ||
* @private | ||
* @param {GeoJSON} geojson GeoJSON | ||
* @param {Geometry} geom GeoJSON Geometries | ||
* @returns {number} area | ||
*/ | ||
function calculateArea(geojson) { | ||
var area = 0, i; | ||
switch (geojson.type) { | ||
case 'Polygon': | ||
return polygonArea(geojson.coordinates); | ||
case 'MultiPolygon': | ||
for (i = 0; i < geojson.coordinates.length; i++) { | ||
area += polygonArea(geojson.coordinates[i]); | ||
} | ||
return area; | ||
case 'Point': | ||
case 'MultiPoint': | ||
case 'LineString': | ||
case 'MultiLineString': | ||
return 0; | ||
case 'GeometryCollection': | ||
for (i = 0; i < geojson.geometries.length; i++) { | ||
area += calculateArea(geojson.geometries[i]); | ||
} | ||
return area; | ||
function calculateArea(geom) { | ||
var area = 0; | ||
var i; | ||
switch (geom.type) { | ||
case 'Polygon': | ||
return polygonArea(geom.coordinates); | ||
case 'MultiPolygon': | ||
for (i = 0; i < geom.coordinates.length; i++) { | ||
area += polygonArea(geom.coordinates[i]); | ||
} | ||
return area; | ||
case 'Point': | ||
case 'MultiPoint': | ||
case 'LineString': | ||
case 'MultiLineString': | ||
return 0; | ||
} | ||
} | ||
function polygonArea(coords) { | ||
@@ -71,3 +63,2 @@ var area = 0; | ||
} | ||
/** | ||
@@ -95,14 +86,15 @@ * @private | ||
var coordsLength = coords.length; | ||
if (coordsLength > 2) { | ||
for (i = 0; i < coordsLength; i++) { | ||
if (i === coordsLength - 2) { // i = N-2 | ||
if (i === coordsLength - 2) { | ||
lowerIndex = coordsLength - 2; | ||
middleIndex = coordsLength - 1; | ||
upperIndex = 0; | ||
} else if (i === coordsLength - 1) { // i = N-1 | ||
} | ||
else if (i === coordsLength - 1) { | ||
lowerIndex = coordsLength - 1; | ||
middleIndex = 0; | ||
upperIndex = 1; | ||
} else { // i = 0 to N-3 | ||
} | ||
else { | ||
lowerIndex = i; | ||
@@ -117,13 +109,9 @@ middleIndex = i + 1; | ||
} | ||
area = area * RADIUS * RADIUS / 2; | ||
} | ||
return area; | ||
} | ||
function rad(_) { | ||
return _ * Math.PI / 180; | ||
function rad(num) { | ||
return num * Math.PI / 180; | ||
} | ||
export default area; | ||
exports.default = area; |
{ | ||
"name": "@turf/area", | ||
"version": "5.1.5", | ||
"version": "6.0.0", | ||
"description": "turf area module", | ||
"main": "main.js", | ||
"module": "main.es.js", | ||
"types": "index.d.ts", | ||
"main": "index", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"main.js", | ||
"main.es.js" | ||
"index.ts" | ||
], | ||
"scripts": { | ||
"pretest": "rollup -c ../../rollup.config.js", | ||
"test": "node -r @std/esm test.js", | ||
"posttest": "node -r @std/esm ../../scripts/validate-es5-dependencies.js", | ||
"bench": "node -r @std/esm bench.js", | ||
"prepare": "tsc", | ||
"pretest": "tsc", | ||
"test": "node test.js", | ||
"bench": "node bench.js", | ||
"docs": "node ../../scripts/generate-readmes" | ||
@@ -38,6 +34,5 @@ }, | ||
"devDependencies": { | ||
"@std/esm": "*", | ||
"benchmark": "*", | ||
"load-json-file": "*", | ||
"rollup": "*", | ||
"typescript": "*", | ||
"tape": "*", | ||
@@ -47,9 +42,5 @@ "write-json-file": "*" | ||
"dependencies": { | ||
"@turf/helpers": "^5.1.5", | ||
"@turf/meta": "^5.1.5" | ||
}, | ||
"@std/esm": { | ||
"esm": "js", | ||
"cjs": true | ||
"@turf/helpers": "6.x", | ||
"@turf/meta": "6.x" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
5
9888
5
221
1
+ Added@turf/helpers@6.5.0(transitive)
+ Added@turf/meta@6.5.0(transitive)
- Removed@turf/helpers@5.1.5(transitive)
- Removed@turf/meta@5.2.0(transitive)
Updated@turf/helpers@6.x
Updated@turf/meta@6.x