turf-average
turf average module
turf.average(polygons, points, field, outputField)
Calculates the average value of a field for a set of Point|points within a set of Polygon|polygons.
Parameters
parameter | type | description |
---|---|---|
polygons |
FeatureCollection.<Polygon> | polygons with values on which to average |
points |
FeatureCollection.<Point> | points from which to calculate the average |
field |
String | the field in the points features from which to pull values to average |
outputField |
String | the field in polygons to put results of the averages |
Example
var polygons = "type": "FeatureCollection" "features": "type": "Feature" "properties": {} "geometry": "type": "Polygon" "coordinates": 10666351 59890659 10666351 59936784 10762481 59936784 10762481 59890659 10666351 59890659 "type": "Feature" "properties": {} "geometry": "type": "Polygon" "coordinates": 10764541 59889281 10764541 59937128 10866165 59937128 10866165 59889281 10764541 59889281 ;var points = "type": "FeatureCollection" "features": "type": "Feature" "properties": "population": 200 "geometry": "type": "Point" "coordinates": 10724029 59926807 "type": "Feature" "properties": "population": 600 "geometry": "type": "Point" "coordinates": 10715789 59904778 "type": "Feature" "properties": "population": 100 "geometry": "type": "Point" "coordinates": 10746002 59908566 "type": "Feature" "properties": "population": 200 "geometry": "type": "Point" "coordinates": 10806427 59908910 "type": "Feature" "properties": "population": 300 "geometry": "type": "Point" "coordinates": 1079544 59931624 ; var averaged = turf; var resultFeatures = pointsfeatures;var result = "type": "FeatureCollection" "features": resultFeatures; //=result
Returns FeatureCollection.<Polygon>
, polygons with the value of outField
set to the calculated averages
Installation
Requires nodejs.
$ npm install turf-average
Tests
$ npm test