1 | # geojson-polygon-aggregate
|
2 |
|
3 | Aggregate properties of GeoJSON polygons, grouped by another set of polygons
|
4 |
|
5 | ## Install
|
6 |
|
7 | ```
|
8 | npm install geojson-polygon-aggregate
|
9 | ```
|
10 |
|
11 |
|
12 | ## Usage
|
13 |
|
14 | ```javascript
|
15 | var aggregate = require('geojson-polygon-aggregate')
|
16 | var groups = { /* geojson FeatureCollection of polygons */ }
|
17 | var data = { /* geojson FeatureCollection of polygons with some data */ }
|
18 |
|
19 | // assumes that the features in data have a numeric property called 'something'
|
20 | var result = aggregate(groups, data, {
|
21 | 'something': aggregate.sum('something'),
|
22 | 'something-area-weighted': aggregate.areaWeightedSum('something'),
|
23 | 'area': aggregate.totalArea(),
|
24 | 'count': aggregate.count(),
|
25 | 'arbitraryProperty': function (memo, feature) {
|
26 | // the aggregations above are provided for convenience, but you can
|
27 | // do whatever you want here. `memo` is the previous return value
|
28 | // of this function, or groups.properties['arbitraryProperty'] on the
|
29 | // first iteration.
|
30 | if (memo) {
|
31 | return memo + ', ' + feature.properties['something']
|
32 | } else {
|
33 | return 'Values: ' + feature.properties['something']
|
34 | }
|
35 | }
|
36 | })
|
37 | ```
|
38 |
|
39 |
|
40 | ## Thanks
|
41 |
|
42 | This module relies *heavily* on the fantastic [Turf.js](https://github.com/turfjs/turf/) project. If it doesn't do what you need, something over there very likely does!
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|