turf-centroid
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -5,3 +5,3 @@ var each = require('turf-meta').coordEach; | ||
/** | ||
* Takes a {@link Feature} or {@link FeatureCollection} of any type and calculates the centroid using the arithmetic mean of all vertices. | ||
* Takes one or more features and calculates the centroid using the arithmetic mean of all vertices. | ||
* This lessens the effect of small islands and artifacts when calculating | ||
@@ -12,4 +12,4 @@ * the centroid of a set of polygons. | ||
* @category measurement | ||
* @param {GeoJSON} features a {@link Feature} or FeatureCollection of any type | ||
* @return {Point} a Point feature at the centroid of the input feature(s) | ||
* @param {(Feature|FeatureCollection)} features input features | ||
* @return {Feature<Point>} the centroid of the input features | ||
* @example | ||
@@ -40,3 +40,3 @@ * var poly = { | ||
*/ | ||
module.exports = function(features){ | ||
module.exports = function(features) { | ||
var xSum = 0, ySum = 0, len = 0; | ||
@@ -43,0 +43,0 @@ each(features, function(coord) { |
{ | ||
"name": "turf-centroid", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "turf centroid module", | ||
@@ -33,2 +33,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"geojson-fixtures": "^0.5.0", | ||
"turf-meta": "^1.0.2", | ||
@@ -35,0 +36,0 @@ "turf-point": "^2.0.0" |
@@ -10,3 +10,3 @@ # turf-centroid | ||
Takes a Feature or FeatureCollection of any type and calculates the centroid using the arithmetic mean of all vertices. | ||
Takes one or more features and calculates the centroid using the arithmetic mean of all vertices. | ||
This lessens the effect of small islands and artifacts when calculating | ||
@@ -18,5 +18,5 @@ the centroid of a set of polygons. | ||
| parameter | type | description | | ||
| ---------- | ------- | ------------------------------------------ | | ||
| `features` | GeoJSON | a Feature or FeatureCollection of any type | | ||
| parameter | type | description | | ||
| ---------- | -------------------------- | -------------- | | ||
| `features` | Feature\,FeatureCollection | input features | | ||
@@ -52,2 +52,5 @@ | ||
**Returns** `Feature.<Point>`, the centroid of the input features | ||
## Installation | ||
@@ -67,1 +70,2 @@ | ||
27
test.js
@@ -1,25 +0,2 @@ | ||
var test = require('tape'); | ||
var centroid = require('./'); | ||
var fs = require('fs'); | ||
var boxFC = JSON.parse(fs.readFileSync(__dirname+'/fixtures/in/box.geojson')); | ||
var blockFC = JSON.parse(fs.readFileSync(__dirname+'/fixtures/in/block.geojson')); | ||
test('centroid', function(t){ | ||
var boxFcCentroid = centroid(boxFC.features[0]); | ||
boxFcCentroid.properties['marker-color'] = '#f0f'; | ||
t.ok(boxFcCentroid, 'should return the proper centroid for a FeatureCollection'); | ||
t.deepEqual(boxFcCentroid.geometry.coordinates, [65.56640625, 43.59448261855401]); | ||
var blockFcCentroid = centroid(blockFC.features[0]); | ||
blockFcCentroid.properties['marker-color'] = '#f0f'; | ||
t.ok(blockFcCentroid, 'should return the proper centroid for a FeatureCollection'); | ||
t.deepEqual(blockFcCentroid.geometry.coordinates, [-114.02900261988646,51.05007001220118]); | ||
boxFC.features.push(boxFcCentroid); | ||
blockFC.features.push(blockFcCentroid); | ||
fs.writeFileSync(__dirname+'/fixtures/out/box_out.geojson', JSON.stringify(boxFC,null,2)); | ||
fs.writeFileSync(__dirname+'/fixtures/out/block_out.geojson', JSON.stringify(blockFC,null,2)); | ||
t.end(); | ||
}); | ||
var geojsonFixtures = require('geojson-fixtures/helper'); | ||
geojsonFixtures(require('tape'), 'all', require('./'), __dirname + '/test'); |
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
68
1
5069
3
8
65
1
+ Addedgeojson-fixtures@^0.5.0
+ AddedJSV@4.0.2(transitive)
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@1.0.02.2.1(transitive)
+ Addedchalk@0.4.01.1.3(transitive)
+ Addedconcat-stream@1.4.11(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedgeojson-fixtures@0.5.0(transitive)
+ Addedgeojsonhint@1.2.1(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhas-color@0.1.7(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedjsonlint-lines@1.7.1(transitive)
+ Addedminimist@1.1.1(transitive)
+ Addednomnom@1.8.1(transitive)
+ Addedreadable-stream@1.1.14(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedstrip-ansi@0.1.13.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedtext-table@0.2.0(transitive)
+ Addedtypedarray@0.0.7(transitive)
+ Addedunderscore@1.6.0(transitive)
- Removedminimist@1.2.8(transitive)