Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

turf-area

Package Overview
Dependencies
Maintainers
8
Versions
12
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 1.1.1 to 3.0.0-canary.2f5f7167

.npmignore

24

index.js
var geometryArea = require('geojson-area').geometry;
/**
* Takes a {@link GeoJSON} feature or {@link FeatureCollection} of any type and returns the area of that feature
* Takes a one or more features and returns their area
* in square meters.
*
* @module turf/area
* @category measurement
* @param {GeoJSON} input a {@link Feature} or {@link FeatureCollection} of any type
* @param {(Feature|FeatureCollection)} input input features
* @return {Number} area in square meters

@@ -49,15 +48,16 @@ * @example

*/
module.exports = function(_) {
if (_.type === 'FeatureCollection') {
for (var i = 0, sum = 0; i < _.features.length; i++) {
if (_.features[i].geometry) {
sum += geometryArea(_.features[i].geometry);
function area(input) {
if (input.type === 'FeatureCollection') {
for (var i = 0, sum = 0; i < input.features.length; i++) {
if (input.features[i].geometry) {
sum += geometryArea(input.features[i].geometry);
}
}
return sum;
} else if (_.type === 'Feature') {
return geometryArea(_.geometry);
} else if (input.type === 'Feature') {
return geometryArea(input.geometry);
} else {
return geometryArea(_);
return geometryArea(input);
}
};
}
module.exports = area;
{
"name": "turf-area",
"version": "1.1.1",
"version": "3.0.0-canary.2f5f7167",
"description": "calculate the area of a polygon or multipolygon feature",
"main": "index.js",
"scripts": {
"test": "tape test.js",
"doc": "dox -r < index.js | doxme --readme > README.md"
"test": "tape test.js"
},

@@ -19,3 +18,3 @@ "keywords": [

"dependencies": {
"geojson-area": "^0.2.0"
"geojson-area": "^0.2.1"
},

@@ -27,6 +26,5 @@ "repository": {

"devDependencies": {
"tape": "^3.5.0",
"dox": "^0.6.1",
"doxme": "^1.4.3"
"geojson-fixtures": "^0.6.0",
"tape": "^3.5.0"
}
}

@@ -10,10 +10,11 @@ # turf-area

Given any kind of GeoJSON feature, return the area of that feature,
Takes a one or more features and returns their area
in square meters.
### Parameters
| parameter | type | description |
| --------- | ------- | ----------- |
| `input` | GeoJSON | |
| parameter | type | description |
| --------- | -------------------------- | -------------- |
| `input` | Feature\,FeatureCollection | input features |

@@ -24,9 +25,43 @@

```js
var polygons = turf.featurecollection([
turf.polygon([[[0,0],[10,0],[10,10],[0,10],[0,0]]]),
turf.polygon([[[10,0],[20,10],[20,20], [20,0]]])]);
var polygons = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[
[-67.031021, 10.458102],
[-67.031021, 10.53372],
[-66.929397, 10.53372],
[-66.929397, 10.458102],
[-67.031021, 10.458102]
]]
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[
[-66.919784, 10.397325],
[-66.919784, 10.513467],
[-66.805114, 10.513467],
[-66.805114, 10.397325],
[-66.919784, 10.397325]
]]
}
}
]
};
var area = turf.area(polygons);
//=area
```
**Returns** `Number`, area in square meters
## Installation

@@ -46,1 +81,2 @@

@@ -1,121 +0,5 @@

var area = require('./'),
test = require('tape');
test('turf-area - polygon', function(t) {
var poly = {
type: 'Polygon',
coordinates: [
[
[0, 0],
[10, 0],
[10, 10],
[0, 10],
[0, 0],
]
]
};
t.equal(area(poly), 1232921098571.292);
t.end();
var geojsonFixtures = require('geojson-fixtures/helper');
geojsonFixtures(require('tape'), 'all', require('./'), __dirname + '/test', false, function(t, input, output) {
t.ok(typeof output === 'number', 'output is number');
t.ok(output >= 0, 'area is positive or zero');
});
test('turf-area - polygon', function(t) {
var point = {
type: 'Point',
coordinates: [0, 0]
};
t.equal(area(point), 0);
t.end();
});
test('turf-area - linestring', function(t) {
var ls = {
type: 'LineString',
coordinates: [[0, 0], [1, 2]]
};
t.equal(area(ls), 0);
t.end();
});
test('turf-area - featurecollection', function(t) {
var fc = {
type: 'FeatureCollection',
features: [{
type: 'Feature',
geometry: {
type: 'Polygon',
coordinates: [
[
[0, 0],
[10, 0],
[10, 10],
[0, 10],
[0, 0],
]
]
},
properties: {}
}]
};
t.equal(area(fc), 1232921098571.292);
t.end();
});
test('turf-area - featurecollection n > 1', function(t) {
var fc = {
type: 'FeatureCollection',
features: [{
type: 'Feature',
geometry: {
type: 'Polygon',
coordinates: [
[
[0, 0],
[10, 0],
[10, 10],
[0, 10],
[0, 0],
]
]
},
properties: {}
}, {
type: 'Feature',
geometry: {
type: 'Polygon',
coordinates: [
[
[0, 0],
[10, 0],
[10, 10],
[0, 10],
[0, 0],
]
]
},
properties: {}
}]
};
t.equal(area(fc), 1232921098571.292 * 2);
t.end();
});
test('turf-area - feature', function(t) {
var feature = {
type: 'Feature',
geometry: {
type: 'Polygon',
coordinates: [
[
[0, 0],
[10, 0],
[10, 10],
[0, 10],
[0, 0],
]
]
},
properties: {}
};
t.equal(area(feature), 1232921098571.292);
t.end();
});
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