Skip to content

Instantly share code, notes, and snippets.

@morganherlocker
Created December 9, 2014 21:32
Show Gist options
  • Select an option

  • Save morganherlocker/6ffc4c450a447d0461e8 to your computer and use it in GitHub Desktop.

Select an option

Save morganherlocker/6ffc4c450a447d0461e8 to your computer and use it in GitHub Desktop.
var average = require('turf-average')
var sum = require('turf-sum')
var median = require('turf-median')
var min = require('turf-min')
var max = require('turf-max')
var deviation = require('turf-deviation')
var variance = require('turf-variance')
var count = require('turf-count')
var turf = {}
turf.average = average
turf.sum = sum
turf.median = median
turf.min = min
turf.max = max
turf.deviation = deviation
turf.variance = variance
turf.count = count
module.exports = function(polygons, points, aggregations) {
for (var i = 0, len = aggregations.length; i < len; i++) {
var agg = aggregations[i],
operation = agg.aggregation,
unrecognizedError;
if (isAggregationOperation(operation)) {
if (operation === 'count') {
polygons = turf[operation](polygons, points, agg.outField);
} else {
polygons = turf[operation](polygons, points, agg.inField, agg.outField);
}
} else {
unrecognizedError = new Error('"' + operation + '" is not a recognized aggregation operation.');
return err;
}
}
return polygons;
}
function isAggregationOperation(operation) {
return operation === 'average' ||
operation === 'sum' ||
operation === 'median' ||
operation === 'min' ||
operation === 'max' ||
operation === 'deviation' ||
operation === 'variance' ||
operation === 'count';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment