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

turf-quantile

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-quantile - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

75

index.js
var ss = require('simple-statistics');
/**
* Takes a {@link FeatureCollection}, a property name, and a set of percentiles and returns a quantile array.
* @module turf/quantile
* @category classification
* @param {FeatureCollection} input a FeatureCollection of any type
* @param {String} field the property in `input` from which to retrieve quantile values
* @param {Array<number>} percentiles an Array of percentiles on which to calculate quantile values
* @return {Array<number>} an array of the break values
* @example
* var points = {
* "type": "FeatureCollection",
* "features": [
* {
* "type": "Feature",
* "properties": {
* "population": 5
* },
* "geometry": {
* "type": "Point",
* "coordinates": [5, 5]
* }
* }, {
* "type": "Feature",
* "properties": {
* "population": 40
* },
* "geometry": {
* "type": "Point",
* "coordinates": [1, 3]
* }
* }, {
* "type": "Feature",
* "properties": {
* "population": 80
* },
* "geometry": {
* "type": "Point",
* "coordinates": [14, 2]
* }
* }, {
* "type": "Feature",
* "properties": {
* "population": 90
* },
* "geometry": {
* "type": "Point",
* "coordinates": [13, 1]
* }
* }, {
* "type": "Feature",
* "properties": {
* "population": 100
* },
* "geometry": {
* "type": "Point",
* "coordinates": [19, 7]
* }
* }
* ]
* };
*
* var breaks = turf.quantile(
* points, 'population', [25, 50, 75, 99]);
*
* //=breaks
*/
module.exports = function(fc, field, percentiles){

@@ -9,8 +75,7 @@ var vals = [];

vals.push(feature.properties[field]);
})
});
percentiles.forEach(function(percentile){
quantiles.push(ss.quantile(vals, percentile * .01));
})
quantiles.push(ss.quantile(vals, percentile * 0.01));
});
return quantiles;
}
};

17

package.json
{
"name": "turf-quantile",
"version": "1.0.0",
"version": "1.0.1",
"description": "turf quantile 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-quantile.git"
"url": "https://github.com/Turfjs/turf-quantile.git"
},

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

"bugs": {
"url": "https://github.com/morganherlocker/turf-quantile/issues"
"url": "https://github.com/Turfjs/turf-quantile/issues"
},
"homepage": "https://github.com/morganherlocker/turf-quantile",
"homepage": "https://github.com/Turfjs/turf-quantile",
"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,51 @@

turf-quantile
=============
# turf-quantile
[![build status](https://secure.travis-ci.org/Turfjs/turf-quantile.png)](http://travis-ci.org/Turfjs/turf-quantile)
Takes a set of features, a property name, and a set of percentiles and outputs a quantile array. This can be passed as a break array to the isolines function or the isobands function.
turf quantile module
###Install
```sh
npm install turf-quantile
```
### `turf.quantile(input, field, percentiles)`
###Parameters
Takes a FeatureCollection, a property name, and a set of percentiles and returns a quantile array.
|name|description|
|---|---|
|pts|points to classify|
|z|z field|
|percentiles|percentiles to classify|
### Parameters
###Usage
| parameter | type | description |
| ------------- | ----------------- | ------------------------------------------------------------- |
| `input` | FeatureCollection | a FeatureCollection of any type |
| `field` | String | the property on which to retrieve quantile values |
| `percentiles` | Array.<number> | an Array of percentiles on which to calculate quantile values |
### Example
```js
quantile(pts, z, percentiles)
var points = turf.featurecollection([
turf.point([5,5], {population: 5}),
turf.point([1,3], {population: 40}),
turf.point([14,2], {population: 80}),
turf.point([13,1], {population: 90}),
turf.point([19,7], {population: 100})
]);
var breaks = turf.quantile(
points, 'population', [25, 50, 75, 99]);
//=breaks
```
###Example
## Installation
```js
var quantile = require('turf-quantile')
var fs = require('fs')
Requires [nodejs](http://nodejs.org/).
var z = 'elevation'
var percentiles = [10,30,40,60,80,90,99]
```sh
$ npm install turf-quantile
```
var pts = JSON.parse(fs.readFileSync('/path/to/pts.geojson'))
## Tests
var quantiles = quantile(pts, propertyName, percentiles)
console.log(quantiles) // [ 12, 25, 29, 52, 76, 99, 143 ]
```sh
$ npm test
```
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