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

turf-centroid

Package Overview
Dependencies
Maintainers
9
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

turf-centroid - npm Package Compare versions

Comparing version 1.1.2 to 1.1.3

8

index.js

@@ -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 @@

@@ -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

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