@turf/area
Advanced tools
Comparing version 3.13.0 to 3.14.0
90
index.js
@@ -1,61 +0,39 @@ | ||
var geometryArea = require('@mapbox/geojson-area').geometry; | ||
var area = require('@mapbox/geojson-area').geometry; | ||
var geomReduce = require('@turf/meta').geomReduce; | ||
/** | ||
* Takes one or more features and returns their area | ||
* in square meters. | ||
* Takes one or more features and returns their area in square meters. | ||
* | ||
* @param {(Feature|FeatureCollection)} input input features | ||
* @return {number} area in square meters | ||
* @name area | ||
* @param {FeatureCollection|Feature<any>} geojson input GeoJSON feature(s) | ||
* @returns {number} area in square meters | ||
* @addToMap polygon | ||
* @example | ||
* 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 | ||
* var polygon = { | ||
* "type": "Feature", | ||
* "properties": {}, | ||
* "geometry": { | ||
* "type": "Polygon", | ||
* "coordinates": [ | ||
* [ | ||
* [125, -15], | ||
* [113, -22], | ||
* [117, -37], | ||
* [130, -33], | ||
* [148, -39], | ||
* [154, -27], | ||
* [144, -15], | ||
* [125, -15] | ||
* ] | ||
* ] | ||
* } | ||
* } | ||
* var area = turf.area(polygon); | ||
* //=area => square meters | ||
* //=polygon | ||
*/ | ||
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 (input.type === 'Feature') { | ||
return geometryArea(input.geometry); | ||
} else { | ||
return geometryArea(input); | ||
} | ||
} | ||
module.exports = area; | ||
module.exports = function (geojson) { | ||
return geomReduce(geojson, function (value, geometry) { | ||
return value + area(geometry); | ||
}, 0); | ||
}; |
{ | ||
"name": "@turf/area", | ||
"version": "3.13.0", | ||
"version": "3.14.0", | ||
"description": "turf area module", | ||
@@ -32,8 +32,11 @@ "main": "index.js", | ||
"devDependencies": { | ||
"geojson-fixtures": "^0.6.0", | ||
"tape": "^3.5.0" | ||
"benchmark": "^2.1.3", | ||
"load-json-file": "^2.0.0", | ||
"tape": "^4.6.3", | ||
"write-json-file": "^2.0.0" | ||
}, | ||
"dependencies": { | ||
"@mapbox/geojson-area": "^0.2.2" | ||
"@mapbox/geojson-area": "^0.2.2", | ||
"@turf/meta": "^3.14.0" | ||
} | ||
} |
@@ -5,8 +5,7 @@ # @turf/area | ||
Takes one or more features and returns their area | ||
in square meters. | ||
Takes one or more features and returns their area in square meters. | ||
**Parameters** | ||
- `input` **([Feature](http://geojson.org/geojson-spec.html#feature-objects) \| [FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects))** input features | ||
- `geojson` **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects)<any>)** input GeoJSON feature(s) | ||
@@ -16,38 +15,24 @@ **Examples** | ||
```javascript | ||
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 | ||
var polygon = { | ||
"type": "Feature", | ||
"properties": {}, | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[125, -15], | ||
[113, -22], | ||
[117, -37], | ||
[130, -33], | ||
[148, -39], | ||
[154, -27], | ||
[144, -15], | ||
[125, -15] | ||
] | ||
] | ||
} | ||
} | ||
var area = turf.area(polygon); | ||
//=area => square meters | ||
//=polygon | ||
``` | ||
@@ -54,0 +39,0 @@ |
4596
2
4
47
64
+ Added@turf/meta@^3.14.0
+ Added@turf/meta@3.14.0(transitive)