Skip to content

Calculates the number of points that fall within a set of polygons.

License

Notifications You must be signed in to change notification settings

turf-junkyard/turf-count

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

turf-count

build status

turf count module

turf.count(polygons, points, countField)

Takes a set of Point|points and a set of Polygon|polygons and calculates the number of points that fall within the set of polygons.

Parameters

parameter type description
polygons FeatureCollection.<Polygon> input polygons
points FeatureCollection.<Point> input points
countField String a field to append to the attributes of the Polygon features representing Point counts

Example

var polygons = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [[
          [-112.072391,46.586591],
          [-112.072391,46.61761],
          [-112.028102,46.61761],
          [-112.028102,46.586591],
          [-112.072391,46.586591]
        ]]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [[
          [-112.023983,46.570426],
          [-112.023983,46.615016],
          [-111.966133,46.615016],
          [-111.966133,46.570426],
          [-112.023983,46.570426]
        ]]
      }
    }
  ]
};
var points = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "population": 200
      },
      "geometry": {
        "type": "Point",
        "coordinates": [-112.0372, 46.608058]
      }
    }, {
      "type": "Feature",
      "properties": {
        "population": 600
      },
      "geometry": {
        "type": "Point",
        "coordinates": [-112.045955, 46.596264]
      }
    }
  ]
};

var counted = turf.count(polygons, points, 'pt_count');

var resultFeatures = points.features.concat(counted.features);
var result = {
  "type": "FeatureCollection",
  "features": resultFeatures
};

//=result

Returns FeatureCollection.<Polygon>, polygons with countField appended

Installation

Requires nodejs.

$ npm install turf-count

Tests

$ npm test

About

Calculates the number of points that fall within a set of polygons.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •