Git Product home page Git Product logo

geojson-polygon-aggregate's Introduction

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!

geojson-polygon-aggregate's People

Contributors

anandthakker avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.