New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@turf/area

Package Overview
Dependencies
Maintainers
4
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/area - npm Package Compare versions

Comparing version 4.7.3 to 5.0.4

main.js

11

index.d.ts

@@ -1,11 +0,8 @@

/// <reference types="geojson" />
import { AllGeoJSON } from '@turf/helpers'
type Feature = GeoJSON.Feature<any>;
type Features = GeoJSON.FeatureCollection<any>;
/**
* http://turfjs.org/docs/#area
*/
declare function area(features: Feature | Features): number;
declare namespace area { }
export = area;
export default function area(
geojson: AllGeoJSON
): number;

@@ -1,3 +0,2 @@

var area = require('@mapbox/geojson-area').geometry;
var geomReduce = require('@turf/meta').geomReduce;
import { geomReduce } from '@turf/meta';

@@ -8,3 +7,3 @@ /**

* @name area
* @param {FeatureCollection|Feature<any>} geojson input GeoJSON feature(s)
* @param {GeoJSON} geojson input GeoJSON feature(s)
* @returns {number} area in square meters

@@ -20,6 +19,108 @@ * @example

*/
module.exports = function (geojson) {
return geomReduce(geojson, function (value, geometry) {
return value + area(geometry);
function area(geojson) {
return 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);
/**
* Calculate Area
*
* @private
* @param {GeoJSON} geojson GeoJSON
* @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 polygonArea(coords) {
var area = 0;
if (coords && coords.length > 0) {
area += Math.abs(ringArea(coords[0]));
for (var i = 1; i < coords.length; i++) {
area -= Math.abs(ringArea(coords[i]));
}
}
return area;
}
/**
* @private
* Calculate the approximate area of the polygon were it projected onto the earth.
* Note that this area will be positive if ring is oriented clockwise, otherwise it will be negative.
*
* Reference:
* Robert. G. Chamberlain and William H. Duquette, "Some Algorithms for Polygons on a Sphere", JPL Publication 07-03, Jet Propulsion
* Laboratory, Pasadena, CA, June 2007 http://trs-new.jpl.nasa.gov/dspace/handle/2014/40409
*
* @param {Array<Array<number>>} coords Ring Coordinates
* @returns {number} The approximate signed geodesic area of the polygon in square meters.
*/
function ringArea(coords) {
var p1;
var p2;
var p3;
var lowerIndex;
var middleIndex;
var upperIndex;
var i;
var area = 0;
var coordsLength = coords.length;
if (coordsLength > 2) {
for (i = 0; i < coordsLength; i++) {
if (i === coordsLength - 2) { // i = N-2
lowerIndex = coordsLength - 2;
middleIndex = coordsLength - 1;
upperIndex = 0;
} else if (i === coordsLength - 1) { // i = N-1
lowerIndex = coordsLength - 1;
middleIndex = 0;
upperIndex = 1;
} else { // i = 0 to N-3
lowerIndex = i;
middleIndex = i + 1;
upperIndex = i + 2;
}
p1 = coords[lowerIndex];
p2 = coords[middleIndex];
p3 = coords[upperIndex];
area += (rad(p3[0]) - rad(p1[0])) * Math.sin(rad(p2[1]));
}
area = area * RADIUS * RADIUS / 2;
}
return area;
}
function rad(_) {
return _ * Math.PI / 180;
}
export default area;
{
"name": "@turf/area",
"version": "4.7.3",
"version": "5.0.4",
"description": "turf area module",
"main": "index.js",
"main": "main",
"module": "index",
"jsnext:main": "index",
"types": "index.d.ts",
"files": [
"index.js",
"index.d.ts"
"index.d.ts",
"main.js"
],
"scripts": {
"test": "node test.js",
"bench": "node bench.js"
"pretest": "rollup -c ../../rollup.config.js",
"test": "node -r @std/esm test.js",
"bench": "node -r @std/esm bench.js"
},
"repository": {
"type": "git",
"url": "git://github.com/Turfjs/turf.git"
},
"keywords": [

@@ -23,20 +31,22 @@ "turf",

"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/Turfjs/turf.git"
},
"homepage": "https://github.com/Turfjs/turf",
"bugs": {
"url": "https://github.com/Turfjs/turf/issues"
},
"homepage": "https://github.com/Turfjs/turf",
"devDependencies": {
"benchmark": "^2.1.4",
"load-json-file": "^2.0.0",
"tape": "^4.6.3",
"write-json-file": "^2.0.0"
"@std/esm": "*",
"benchmark": "*",
"load-json-file": "*",
"rollup": "*",
"tape": "*",
"write-json-file": "*"
},
"dependencies": {
"@mapbox/geojson-area": "^0.2.2",
"@turf/meta": "^4.7.3"
"@turf/helpers": "^5.0.4",
"@turf/meta": "^5.0.4"
},
"@std/esm": {
"esm": "js",
"cjs": true
}
}
# @turf/area
# area
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
## area
Takes one or more features and returns their area in square meters.

@@ -9,3 +11,3 @@

- `geojson` **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects)&lt;any>)** input GeoJSON feature(s)
- `geojson` **[GeoJSON](http://geojson.org/geojson-spec.html#geojson-objects)** input GeoJSON feature(s)

@@ -12,0 +14,0 @@ **Examples**

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc