geojson-polygon-aggregate
Aggregate properties of GeoJSON polygons, grouped by another set of polygons.
Last updated 4 years ago by drewbo .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install geojson-polygon-aggregate 
SYNC missed versions from official npm registry.

geojson-polygon-aggregate

Aggregate properties of GeoJSON polygons, grouped by another set of polygons

Install

npm install geojson-polygon-aggregate

Usage

var aggregate = require('geojson-polygon-aggregate')
var groups = { /* geojson FeatureCollection of polygons */ }
var data = { /* geojson FeatureCollection of polygons with some data */ } 

// assumes that the features in data have a numeric property called 'something'
var result = aggregate.groups(groups, data, {
  'something': aggregate.reducers.sum('something'),
  'something-area-weighted': aggregate.reducers.areaWeightedSum('something'),
  'area': aggregate.reducers.totalArea(),
  'count': aggregate.reducers.count(),
  'arbitraryProperty': function (memo, feature) {
    // the aggregations above are provided for convenience, but you can
    // do whatever you want here. `memo` is the previous return value
    // of this function, or groups.properties['arbitraryProperty'] on the
    // first iteration.
    if (memo) {
      return memo + ', ' + feature.properties['something']
    } else {
      return 'Values: ' + feature.properties['something']
    }
  }
})

API

all

index.js:21-38

Aggregate properties of GeoJSON polygon features.

Parameters

  • data (FeatureCollection.<Polygon>|Array) The polygons to aggregate.
  • features
  • aggregations Object The aggregations as key-value pairs, where the key is the name of the resulting property, and the value is the reducer function with signature (accumulator, clippedFeature, groupingFeature, additionalArgs[0], additionalArgs[1], ...) => accumulator
  • thisArg Object= Optional 'this' context with which to call reducer functions
  • additionalArgs Array= Optional array of additional args with which to call reducer functions

Returns Object A properties object with the aggregated property values

groups

index.js:54-90

Aggregate properties of GeoJSON polygon features, grouped by another set of polygons.

Parameters

  • groups (FeatureCollection.<Polygon>|Array) The polygons by which to group the aggregations.
  • data (FeatureCollection.<Polygon>|Array) The polygons to aggregate.
  • aggregations Object The aggregations as key-value pairs, where the key is the name of the resulting property, and the value is the reducer function with signature (accumulator, clippedFeature, groupingFeature, additionalArgs[0], additionalArgs[1], ...) => accumulator
  • thisArg Object= Optional 'this' context with which to call reducer functions
  • additionalArgs Array= Optional array of additional args with which to call reducer functions

Returns FeatureCollection.<Polygon> A set of polygons whose geometries are identical to groups, but with properties resulting from the aggregations. Existing properties on features in groups are copied (shallowly), but aggregation results will override if they have the same name.

stream

index.js:101-122

Aggregate properties of streaming GeoJSON polygon features.

Parameters

  • aggregations Object The aggregations as key-value pairs, where the key is the name of the resulting property, and the value is the reducer function with signature (accumulator, clippedFeature, groupingFeature, additionalArgs[0], additionalArgs[1], ...) => accumulator
  • thisArg Object= Optional 'this' context with which to call reducer functions
  • additionalArgs Array= Optional array of additional args with which to call reducer functions

Returns Object A transform stream reading GeoJSON feature objects and, writing, at the end, a properties object with the aggregated property values

Thanks

This module relies heavily on the fantastic Turf.js project. If it doesn't do what you need, something over there very likely does!

Current Tags

  • 2.1.0                                ...           latest (4 years ago)

12 Versions

  • 2.1.0                                ...           4 years ago
  • 2.0.0                                ...           5 years ago
  • 1.4.1                                ...           5 years ago
  • 1.4.0                                ...           5 years ago
  • 1.3.1                                ...           5 years ago
  • 1.3.0                                ...           5 years ago
  • 1.2.0                                ...           5 years ago
  • 1.1.1                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (7)
Dev Dependencies (10)

Copyright 2014 - 2016 © taobao.org |