Comparing version 1.0.1 to 1.0.2
30
bench.js
@@ -1,17 +0,17 @@ | ||
var count = require('./'); | ||
global.count = require('./'); | ||
var Benchmark = require('benchmark'); | ||
var fs = require('fs'); | ||
var polygon = require('turf-polygon'); | ||
var point = require('turf-point'); | ||
var featurecollection = require('turf-featurecollection'); | ||
global.polygon = require('turf-polygon'); | ||
global.point = require('turf-point'); | ||
global.featurecollection = require('turf-featurecollection'); | ||
var poly1 = polygon([[[0,0],[10,0],[10,10], [0,10]]]); | ||
var poly2 = polygon([[[10,0],[20,10],[20,20], [20,0]]]); | ||
var polyFC = featurecollection([poly1, poly2]); | ||
var pt1 = point(5,5, {population: 200}); | ||
var pt2 = point(1,3, {population: 600}); | ||
var pt3 = point(14,2, {population: 100}); | ||
var pt4 = point(13,1, {population: 200}); | ||
var pt5 = point(19,7, {population: 300}); | ||
var ptFC = featurecollection([pt1, pt2, pt3, pt4, pt5]); | ||
global.poly1 = polygon([[[0,0],[10,0],[10,10], [0,10]]]); | ||
global.poly2 = polygon([[[10,0],[20,10],[20,20], [20,0]]]); | ||
global.polyFC = featurecollection([poly1, poly2]); | ||
global.pt1 = point(5,5, {population: 200}); | ||
global.pt2 = point(1,3, {population: 600}); | ||
global.pt3 = point(14,2, {population: 100}); | ||
global.pt4 = point(13,1, {population: 200}); | ||
global.pt5 = point(19,7, {population: 300}); | ||
global.ptFC = featurecollection([pt1, pt2, pt3, pt4, pt5]); | ||
@@ -21,3 +21,3 @@ var suite = new Benchmark.Suite('turf-count'); | ||
.add('turf-count',function () { | ||
count(polyFC, ptFC, 'pt_count'); | ||
global.count(global.polyFC, global.ptFC, 'pt_count'); | ||
}) | ||
@@ -30,2 +30,2 @@ .on('cycle', function (event) { | ||
}) | ||
.run(); | ||
.run(); |
96
index.js
var inside = require('turf-inside'); | ||
/** | ||
* Takes a {@link FeatureCollection} of {@link Point} features and a {@link FeatureCollection} of {@link Polygon} features and calculates the number of points that fall within the set of polygons. | ||
* | ||
* @module turf/count | ||
* @category aggregation | ||
* @param {FeatureCollection} polygons a FeatureCollection of {@link Polygon} features | ||
* @param {FeatureCollection} points a FeatureCollection of {@link Point} features | ||
* @param {String} countField a field to append to the attributes of the Polygon features representing Point counts | ||
* @return {FeatureCollection} a FeatureCollection of Polygon features with `countField` appended | ||
* @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 | ||
*/ | ||
module.exports = function(polyFC, ptFC, outField, done){ | ||
polyFC.features.forEach(function(poly){ | ||
for (var i = 0; i < polyFC.features.length; i++) { | ||
var poly = polyFC.features[i]; | ||
if(!poly.properties) poly.properties = {}; | ||
var values = []; | ||
ptFC.features.forEach(function(pt){ | ||
var values = 0; | ||
for (var j = 0; j < ptFC.features.length; j++) { | ||
var pt = ptFC.features[j]; | ||
if (inside(pt, poly)) { | ||
values.push(1); | ||
values++; | ||
} | ||
}) | ||
poly.properties[outField] = values.length; | ||
}) | ||
} | ||
poly.properties[outField] = values; | ||
} | ||
return polyFC; | ||
} | ||
}; |
{ | ||
"name": "turf-count", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "turf count module", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "tape test.js" | ||
"test": "tape test.js", | ||
"doc": "dox -r < index.js | doxme --readme > README.md" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/morganherlocker/turf-count.git" | ||
"url": "https://github.com/Turfjs/turf-count.git" | ||
}, | ||
@@ -23,16 +24,18 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/morganherlocker/turf-count/issues" | ||
"url": "https://github.com/Turfjs/turf-count/issues" | ||
}, | ||
"homepage": "https://github.com/morganherlocker/turf-count", | ||
"homepage": "https://github.com/Turfjs/turf-count", | ||
"devDependencies": { | ||
"benchmark": "^1.0.0", | ||
"deep-freeze": "0.0.1", | ||
"tape": "^3.0.3", | ||
"tape": "^3.5.0", | ||
"turf-featurecollection": "^1.0.0", | ||
"turf-point": "^1.2.0", | ||
"turf-polygon": "^1.0.0" | ||
"turf-point": "^2.0.0", | ||
"turf-polygon": "^1.0.2", | ||
"dox": "^0.6.1", | ||
"doxme": "^1.4.3" | ||
}, | ||
"dependencies": { | ||
"turf-inside": "^1.1.2" | ||
"turf-inside": "^1.1.3" | ||
} | ||
} |
@@ -1,44 +0,68 @@ | ||
turf-count | ||
========== | ||
[![Build Status](https://travis-ci.org/Turfjs/turf-count.svg)](https://travis-ci.org/Turfjs/turf-count) | ||
# turf-count | ||
Calculates the number of points that fall within a set of polygons. | ||
[![build status](https://secure.travis-ci.org/Turfjs/turf-count.png)](http://travis-ci.org/Turfjs/turf-count) | ||
###Install | ||
turf count module | ||
```sh | ||
npm install turf-count | ||
``` | ||
###Parameters | ||
### `turf.count(polygons, points, countField)` | ||
|name|description| | ||
|---|---| | ||
|polyFC|a FeatureCollection of polygons| | ||
|pointFC|a FeatureCollection of points| | ||
|countField|field to append to the polygon features representing point counts| | ||
Takes a FeatureCollection of Point features and a FeatureCollection of Polygon features and calculates the number of points that fall within the set of polygons. | ||
###Usage | ||
### Parameters | ||
| parameter | type | description | | ||
| ------------ | ----------------- | ------------------------------------------------------------------------------------- | | ||
| `polygons` | FeatureCollection | a FeatureCollection of Polygon features | | ||
| `points` | FeatureCollection | a FeatureCollection of Point features | | ||
| `countField` | String | a field to append to the attributes of the Polygon features representing Point counts | | ||
### Example | ||
```js | ||
count(polyFC, pointFC, countField) | ||
var polygons = turf.featurecollection([ | ||
turf.polygon([[ | ||
[-112.072391,46.586591], | ||
[-112.072391,46.61761], | ||
[-112.028102,46.61761], | ||
[-112.028102,46.586591], | ||
[-112.072391,46.586591] | ||
]]), | ||
turf.polygon([[ | ||
[-112.023983,46.570426], | ||
[-112.023983,46.615016], | ||
[-111.966133,46.615016], | ||
[-111.966133,46.570426], | ||
[-112.023983,46.570426] | ||
]]) | ||
]); | ||
var points = turf.featurecollection([ | ||
turf.point([-112.0372, 46.608058], {population: 200}), | ||
turf.point([-112.045955, 46.596264], | ||
{population: 600}) | ||
]); | ||
var counted = turf.count(polygons, points, 'pt_count'); | ||
var result = turf.featurecollection( | ||
points.features.concat(counted.features)); | ||
//=result | ||
``` | ||
###Example | ||
## Installation | ||
```js | ||
var point = require('turf-point') | ||
var polygon = require('turf-polygon') | ||
var featurecollection = require('turf-featurecollection') | ||
Requires [nodejs](http://nodejs.org/). | ||
var poly1 = polygon([[[0,0],[10,0],[10,10], [0,10]]]) | ||
var poly2 = polygon([[[10,0],[20,10],[20,20], [20,0]]]) | ||
var polyFC = featurecollection([poly1, poly2]) | ||
var pt1 = point(5,5, {population: 200}) | ||
var pt2 = point(1,3, {population: 600}) | ||
var ptFC = featurecollection([pt1, pt2]) | ||
```sh | ||
$ npm install turf-count | ||
``` | ||
var counted = count(polyFC, ptFC, 'pt_count') | ||
## Tests | ||
console.log(counted) | ||
```sh | ||
$ npm test | ||
``` | ||
14
test.js
@@ -10,10 +10,10 @@ var count = require('./'); | ||
'use strict'; | ||
var poly1 = polygon([[[0,0],[10,0],[10,10], [0,10]]]); | ||
var poly2 = polygon([[[10,0],[20,10],[20,20], [20,0]]]); | ||
var poly1 = polygon([[[0,0],[10,0],[10,10], [0,10], [0, 0]]]); | ||
var poly2 = polygon([[[10,0],[20,10],[20,20], [20,0], [10,0]]]); | ||
var polyFC = featurecollection([poly1, poly2]); | ||
var pt1 = point(5,5, {population: 200}); | ||
var pt2 = point(1,3, {population: 600}); | ||
var pt3 = point(14,2, {population: 100}); | ||
var pt4 = point(13,1, {population: 200}); | ||
var pt5 = point(19,7, {population: 300}); | ||
var pt1 = point([5,5], {population: 200}); | ||
var pt2 = point([1,3], {population: 600}); | ||
var pt3 = point([14,2], {population: 100}); | ||
var pt4 = point([13,1], {population: 200}); | ||
var pt5 = point([19,7], {population: 300}); | ||
var ptFC = featurecollection([pt1, pt2, pt3, pt4, pt5]); | ||
@@ -20,0 +20,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
9050
142
69
0
8
Updatedturf-inside@^1.1.3