Comparing version 1.1.1 to 3.0.0-canary.2f5f7167
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 @@ | ||
124
test.js
@@ -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(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
2
0
80
3901
66
2
Updatedgeojson-area@^0.2.1