Socket
Socket
Sign inDemoInstall

turf-jenks

Package Overview
Dependencies
Maintainers
8
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

turf-jenks - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

69

index.js
var ss = require('simple-statistics');
/**
* Takes a {@FeatureCollection} of any type and returns an array of the [Jenks Natural breaks](http://en.wikipedia.org/wiki/Jenks_natural_breaks_optimization)
* for a given property
* @module turf/jenks
* @param {FeatureCollection} input a FeatureCollection of any type
* @param {string} field the property in `input` on which to calculate Jenks natural breaks
* @param {number} numberOfBreaks number of classes in which to group the data
* @return {Array<number>} the break number for each class plus the minimum and maximum values
* @example
* var points = {
* "type": "FeatureCollection",
* "features": [
* {
* "type": "Feature",
* "properties": {
* "population": 200
* },
* "geometry": {
* "type": "Point",
* "coordinates": [49.859733, 40.400424]
* }
* }, {
* "type": "Feature",
* "properties": {
* "population": 600
* },
* "geometry": {
* "type": "Point",
* "coordinates": [49.83879, 40.401209]
* }
* }, {
* "type": "Feature",
* "properties": {
* "population": 100
* },
* "geometry": {
* "type": "Point",
* "coordinates": [49.817848, 40.376889]
* }
* }, {
* "type": "Feature",
* "properties": {
* "population": 200
* },
* "geometry": {
* "type": "Point",
* "coordinates": [49.840507, 40.386043]
* }
* }, {
* "type": "Feature",
* "properties": {
* "population": 300
* },
* "geometry": {
* "type": "Point",
* "coordinates": [49.854583, 40.37532]
* }
* }
* ]
* };
*
* var breaks = turf.jenks(points, 'population', 3);
*
* //=breaks
*/
module.exports = function(fc, field, num){

@@ -8,3 +73,3 @@ var vals = [];

fc.features.forEach(function(feature){
if(!(feature.properties[field]===undefined)){
if(feature.properties[field]!==undefined){
vals.push(feature.properties[field]);

@@ -16,2 +81,2 @@ }

return breaks;
}
};

17

package.json
{
"name": "turf-jenks",
"version": "1.0.0",
"version": "1.0.1",
"description": "turf jenks module",
"main": "index.js",
"scripts": {
"test": "tape test.js"
"test": "tape test.js",
"doc": "dox -r < index.js | doxme --readme > README.md"
},
"repository": {
"type": "git",
"url": "https://github.com/morganherlocker/turf-jenks.git"
"url": "https://github.com/Turfjs/turf-jenks.git"
},

@@ -23,12 +24,14 @@ "keywords": [

"bugs": {
"url": "https://github.com/morganherlocker/turf-jenks/issues"
"url": "https://github.com/Turfjs/turf-jenks/issues"
},
"homepage": "https://github.com/morganherlocker/turf-jenks",
"homepage": "https://github.com/Turfjs/turf-jenks",
"devDependencies": {
"benchmark": "^1.0.0",
"tape": "^2.13.4"
"tape": "^3.5.0",
"dox": "^0.6.1",
"doxme": "^1.4.3"
},
"dependencies": {
"simple-statistics": "^0.8.1"
"simple-statistics": "^0.9.0"
}
}

@@ -1,41 +0,48 @@

turf-jenks
==========
[![Build Status](https://travis-ci.org/Turfjs/turf-jenks.svg?branch=master)](https://travis-ci.org/Turfjs/turf-jenks)
# turf-jenks
Takes a set of features, a property name, and the desired number of breaks and outputs an array of natural breaks. This classification can be used in the isolines function or the isobands function, or for theming.
[![build status](https://secure.travis-ci.org/Turfjs/turf-jenks.png)](http://travis-ci.org/Turfjs/turf-jenks)
###Install
turf jenks module
```sh
npm install turf-jenks
```
###Parameters
### `turf.jenks(input, field, numberOfBreaks)`
|name|description|
|---|---|
|fc|points to classify|
|z|z field|
|num|number of breaks|
Given a FeatureCollection, return the [Jenks Natural breaks](http://en.wikipedia.org/wiki/Jenks_natural_breaks_optimization)
of a given property
###Usage
### Parameters
| parameter | type | description |
| ---------------- | ----------------- | ------------------------------------------------------------------ |
| `input` | FeatureCollection | a FeatureCollection of any type |
| `field` | string | the property in `input` on which to calculate Jenks natural breaks |
| `numberOfBreaks` | number | number of classes in which to group the data |
### Example
```js
jenks(fc, z, num)
var points = turf.featurecollection([
turf.point([49.859733, 40.400424], {population: 200}),
turf.point([49.83879, 40.401209], {population: 600}),
turf.point([49.817848, 40.376889], {population: 100}),
turf.point([49.840507, 40.386043], {population: 200}),
turf.point([49.854583, 40.37532], {population: 300})]);
var breaks = turf.jenks(points, 'population', 3);
//=breaks
```
###Example
## Installation
```js
var jenks = require('turf-jenks')
var fs = require('fs')
Requires [nodejs](http://nodejs.org/).
var z = 'elevation'
var num = 10
```sh
$ npm install turf-jenks
```
var pts = JSON.parse(js.readFileSync('/path/to/points.geojson'))
## Tests
var jenked = jenks(pts, z, num)
```sh
$ npm test
```
console.log(jenked) // [ 11, 12, 18, 25, 29, 41, 50, 55, 76, 90, 143 ]
```
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