Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

turf-average

Package Overview
Dependencies
Maintainers
9
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

turf-average

turf average module

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
decreased by-78.72%
Maintainers
9
Weekly downloads
 
Created
Source

turf-average

build status

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

parametertypedescription
polygonsFeatureCollection.<Polygon>polygons with values on which to average
pointsFeatureCollection.<Point>points from which to calculate the average
fieldStringthe field in the points features from which to pull values to average
outputFieldStringthe field in polygons to put results of the averages

Example

var polygons = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [[
          [10.666351, 59.890659],
          [10.666351, 59.936784],
          [10.762481, 59.936784],
          [10.762481, 59.890659],
          [10.666351, 59.890659]
        ]]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [[
          [10.764541, 59.889281],
          [10.764541, 59.937128],
          [10.866165, 59.937128],
          [10.866165, 59.889281],
          [10.764541, 59.889281]
        ]]
      }
    }
  ]
};
var points = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "population": 200
      },
      "geometry": {
        "type": "Point",
        "coordinates": [10.724029, 59.926807]
      }
    }, {
      "type": "Feature",
      "properties": {
        "population": 600
      },
      "geometry": {
        "type": "Point",
        "coordinates": [10.715789, 59.904778]
      }
    }, {
      "type": "Feature",
      "properties": {
        "population": 100
      },
      "geometry": {
        "type": "Point",
        "coordinates": [10.746002, 59.908566]
      }
    }, {
      "type": "Feature",
      "properties": {
        "population": 200
      },
      "geometry": {
        "type": "Point",
        "coordinates": [10.806427, 59.908910]
      }
    }, {
      "type": "Feature",
      "properties": {
        "population": 300
      },
      "geometry": {
        "type": "Point",
        "coordinates": [10.79544, 59.931624]
      }
    }
  ]
};

var averaged = turf.average(
 polygons, points, 'population', 'pop_avg');

var resultFeatures = points.features.concat(
  averaged.features);
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

Keywords

FAQs

Package last updated on 18 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc