Socket
Socket
Sign inDemoInstall

turf-aggregate

Package Overview
Dependencies
Maintainers
8
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

turf-aggregate - npm Package Compare versions

Comparing version 1.0.0 to 1.0.2

2

bench.js
var aggregate = require('./');
var Benchmark = require('Benchmark');
var Benchmark = require('benchmark');
var fs = require('fs');

@@ -4,0 +4,0 @@ var polygon = require('turf-polygon');

@@ -19,2 +19,151 @@ var average = require('turf-average');

/**
* Calculates a series of aggregations for a set of {@link Point} features within a set of {@link Polygon} features. Sum, average, count, min, max, and deviation are supported.
*
* @module turf/aggregate
* @category aggregation
* @param {FeatureCollection} polygons a FeatureCollection of {@link Polygon} features
* @param {FeatureCollection} points a FeatureCollection of {@link Point} features
* @param {Array} aggregations an array of aggregation objects
* @return {FeatureCollection} a FeatureCollection of {@link Polygon} features with properties listed as `outField` values in `aggregations`
* @example
* var polygons = {
* "type": "FeatureCollection",
* "features": [
* {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Polygon",
* "coordinates": [[
* [1.669921, 48.632908],
* [1.669921, 49.382372],
* [3.636474, 49.382372],
* [3.636474, 48.632908],
* [1.669921, 48.632908]
* ]]
* }
* }, {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Polygon",
* "coordinates": [[
* [2.230224, 47.85003],
* [2.230224, 48.611121],
* [4.361572, 48.611121],
* [4.361572, 47.85003],
* [2.230224, 47.85003]
* ]]
* }
* }
* ]
* };
* var points = {
* "type": "FeatureCollection",
* "features": [
* {
* "type": "Feature",
* "properties": {
* "population": 200
* },
* "geometry": {
* "type": "Point",
* "coordinates": [2.054443,49.138596]
* }
* },
* {
* "type": "Feature",
* "properties": {
* "population": 600
* },
* "geometry": {
* "type": "Point",
* "coordinates": [3.065185,48.850258]
* }
* },
* {
* "type": "Feature",
* "properties": {
* "population": 100
* },
* "geometry": {
* "type": "Point",
* "coordinates": [2.329101,48.79239]
* }
* },
* {
* "type": "Feature",
* "properties": {
* "population": 200
* },
* "geometry": {
* "type": "Point",
* "coordinates": [2.614746,48.334343]
* }
* },
* {
* "type": "Feature",
* "properties": {
* "population": 300
* },
* "geometry": {
* "type": "Point",
* "coordinates": [3.416748,48.056053]
* }
* }
* ]
* };
* var aggregations = [
* {
* aggregation: 'sum',
* inField: 'population',
* outField: 'pop_sum'
* },
* {
* aggregation: 'average',
* inField: 'population',
* outField: 'pop_avg'
* },
* {
* aggregation: 'median',
* inField: 'population',
* outField: 'pop_median'
* },
* {
* aggregation: 'min',
* inField: 'population',
* outField: 'pop_min'
* },
* {
* aggregation: 'max',
* inField: 'population',
* outField: 'pop_max'
* },
* {
* aggregation: 'deviation',
* inField: 'population',
* outField: 'pop_deviation'
* },
* {
* aggregation: 'variance',
* inField: 'population',
* outField: 'pop_variance'
* },
* {
* aggregation: 'count',
* inField: '',
* outField: 'point_count'
* }
* ];
*
* var aggregated = turf.aggregate(
* polygons, points, aggregations);
*
* var result = turf.featurecollection(
* points.features.concat(aggregated.features));
*
* //=result
*/
module.exports = function(polygons, points, aggregations){

@@ -33,3 +182,3 @@ for (var i = 0, len = aggregations.length; i < len; i++) {

} else {
return new Error('"'+ operation +'" is not a recognized aggregation operation.');
throw new Error('"'+ operation +'" is not a recognized aggregation operation.');
}

@@ -39,3 +188,3 @@ }

return polygons;
}
};

@@ -51,2 +200,2 @@ function isAggregationOperation(operation) {

operation === 'count';
}
}
{
"name": "turf-aggregate",
"version": "1.0.0",
"version": "1.0.2",
"description": "turf aggregate 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-aggregate.git"
"url": "https://github.com/Turfjs/turf-aggregate.git"
},

@@ -24,22 +25,24 @@ "keywords": [

"bugs": {
"url": "https://github.com/morganherlocker/turf-aggregate/issues"
"url": "https://github.com/Turfjs/turf-aggregate/issues"
},
"homepage": "https://github.com/morganherlocker/turf-aggregate",
"homepage": "https://github.com/Turfjs/turf-aggregate",
"devDependencies": {
"benchmark": "^1.0.0",
"tape": "^2.13.3",
"turf-featurecollection": "^0.1.0",
"turf-point": "^0.1.1",
"turf-polygon": "^0.1.1"
"tape": "^3.5.0",
"turf-featurecollection": "^1.0.0",
"turf-point": "^2.0.0",
"turf-polygon": "^1.0.2",
"dox": "^0.6.1",
"doxme": "^1.4.3"
},
"dependencies": {
"turf-average": "0.1.1",
"turf-count": "0.0.4",
"turf-deviation": "0.0.2",
"turf-max": "0.0.3",
"turf-median": "0.0.2",
"turf-min": "0.0.2",
"turf-sum": "0.0.2",
"turf-variance": "0.0.2"
"turf-average": "^1.1.0",
"turf-count": "^1.0.1",
"turf-deviation": "^1.0.0",
"turf-max": "^1.0.0",
"turf-median": "^1.0.1",
"turf-min": "^1.0.0",
"turf-sum": "^1.0.0",
"turf-variance": "^1.0.0"
}
}

@@ -1,44 +0,47 @@

turf-aggregate
==============
# turf-aggregate
[![build status](https://secure.travis-ci.org/Turfjs/turf-aggregate.png)](http://travis-ci.org/Turfjs/turf-aggregate)
Takes a set of polygons, a set of points, and an array of aggregations, then perform them. Sum, average, count, min, max, and deviation are supported.
turf aggregate module
###Install
```sh
npm install turf-aggregate
```
### `turf.aggregate(polygons, points, aggregations)`
###Parameters
Calculates a series of aggregations for a set of Point features within a set of Polygon features. Sum, average, count, min, max, and deviation are supported.
|name|description|
|---|---|
|polygonFC|a FeatureCollection containing Polygons|
|pointFC|a FeatureCollection containing Points|
|aggregations|an array of aggregation objects (options in the example below)|
###Usage
### Parameters
```js
aggregate(polygonFC, pointFC, aggregations)
```
| parameter | type | description |
| -------------- | ----------------- | --------------------------------------- |
| `polygons` | FeatureCollection | a FeatureCollection of Polygon features |
| `points` | FeatureCollection | a FeatureCollection of Point features |
| `aggregations` | Array | an array of aggregation objects |
###Example
```javascript
var aggregate = require('turf-aggregate')
var point = require('turf-point')
var polygon = require('turf-polygon')
var featurecollection = require('turf-featurecollection')
### Example
var poly1 = polygon([[[0,0],[10,0],[10,10],[0,10]]])
var poly2 = polygon([[[10,0],[20,10],[20,20], [20,0]]])
var polyFC = featurecollection([poly1, poly2])
var pt1 = point(5,5, {population: 200})
var pt2 = point(1,3, {population: 600})
var pt3 = point(14,2, {population: 100})
var pt4 = point(13,1, {population: 200})
var pt5 = point(19,7, {population: 300})
var ptFC = featurecollection([pt1, pt2, pt3, pt4, pt5])
```js
var polygons = turf.featurecollection([
turf.polygon([[
[1.669921, 48.632908],
[1.669921, 49.382372],
[3.636474, 49.382372],
[3.636474, 48.632908],
[1.669921, 48.632908]]
]),
turf.polygon([[
[2.230224, 47.85003],
[2.230224, 48.611121],
[4.361572, 48.611121],
[4.361572, 47.85003],
[2.230224, 47.85003]]
])
]);
var points = turf.featurecollection([
turf.point([2.054443,49.138596], {population: 200}),
turf.point([3.065185,48.850258], {population: 600}),
turf.point([2.329101,48.79239], {population: 100}),
turf.point([2.614746,48.334343], {population: 200}),
turf.point([3.416748,48.056053], {population: 300})]);
var aggregations = [

@@ -85,7 +88,26 @@ {

}
]
];
var polys = aggregate(polyFC, ptFC, aggregations)
var aggregated = turf.aggregate(
polygons, points, aggregations);
console.log(polys)
var result = turf.featurecollection(
points.features.concat(aggregated.features));
//=result
```
## Installation
Requires [nodejs](http://nodejs.org/).
```sh
$ npm install turf-aggregate
```
## Tests
```sh
$ npm test
```

@@ -1,17 +0,17 @@

var aggregate = require('./')
var test = require('tape')
var polygon = require('turf-polygon')
var point = require('turf-point')
var featurecollection = require('turf-featurecollection')
var aggregate = require('./');
var test = require('tape');
var polygon = require('turf-polygon');
var point = require('turf-point');
var featurecollection = require('turf-featurecollection');
test('aggregate', function(t){
var poly1 = polygon([[[0,0],[10,0],[10,10],[0,10]]])
var poly2 = polygon([[[10,0],[20,10],[20,20], [20,0]]])
var polyFC = featurecollection([poly1, poly2])
var pt1 = point(5,5, {population: 200})
var pt2 = point(1,3, {population: 600})
var pt3 = point(14,2, {population: 100})
var pt4 = point(13,1, {population: 200})
var pt5 = point(19,7, {population: 300})
var ptFC = featurecollection([pt1, pt2, pt3, pt4, pt5])
var poly1 = polygon([[[0,0],[10,0],[10,10],[0,10],[0,0]]]);
var poly2 = polygon([[[10,0],[20,10],[20,20],[20,0],[10,0]]]);
var polyFC = featurecollection([poly1, poly2]);
var pt1 = point([5,5], {population: 200});
var pt2 = point([1,3], {population: 600});
var pt3 = point([14,2], {population: 100});
var pt4 = point([13,1], {population: 200});
var pt5 = point([19,7], {population: 300});
var ptFC = featurecollection([pt1, pt2, pt3, pt4, pt5]);
var aggregations = [

@@ -58,22 +58,20 @@ {

}
]
];
var aggregated = aggregate(polyFC, ptFC, aggregations)
t.equal(aggregated.features[0].properties.pop_sum, 800)
t.equal(aggregated.features[1].properties.pop_sum, 600)
t.equal(aggregated.features[0].properties.pop_avg, 400)
t.equal(aggregated.features[1].properties.pop_avg, 200)
t.equal(aggregated.features[0].properties.pop_median, 400)
t.equal(aggregated.features[1].properties.pop_median, 200)
t.equal(aggregated.features[0].properties.pop_min, 200)
t.equal(aggregated.features[1].properties.pop_min, 100)
t.equal(aggregated.features[0].properties.pop_max, 600)
t.equal(aggregated.features[1].properties.pop_max, 300)
t.ok(aggregated.features[0].properties.pop_deviation)
t.ok(aggregated.features[1].properties.pop_deviation)
t.ok(aggregated.features[0].properties.pop_variance)
t.ok(aggregated.features[1].properties.pop_variance)
t.end()
})
var aggregated = aggregate(polyFC, ptFC, aggregations);
t.equal(aggregated.features[0].properties.pop_sum, 800);
t.equal(aggregated.features[1].properties.pop_sum, 600);
t.equal(aggregated.features[0].properties.pop_avg, 400);
t.equal(aggregated.features[1].properties.pop_avg, 200);
t.equal(aggregated.features[0].properties.pop_median, 400);
t.equal(aggregated.features[1].properties.pop_median, 200);
t.equal(aggregated.features[0].properties.pop_min, 200);
t.equal(aggregated.features[1].properties.pop_min, 100);
t.equal(aggregated.features[0].properties.pop_max, 600);
t.equal(aggregated.features[1].properties.pop_max, 300);
t.ok(aggregated.features[0].properties.pop_deviation);
t.ok(aggregated.features[1].properties.pop_deviation);
t.ok(aggregated.features[0].properties.pop_variance);
t.ok(aggregated.features[1].properties.pop_variance);
t.end();
});
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