turf-within
Advanced tools
Comparing version 1.0.1 to 3.0.0-canary.2f5f7167
var within = require('./'); | ||
var Benchmark = require('benchmark'); | ||
var fs = require('fs'); | ||
var point = require('turf-point'); | ||
var polygon = require('turf-polygon'); | ||
var featureCollection = require('turf-featurecollection'); | ||
var point = require('turf-helpers').point; | ||
var polygon = require('turf-helpers').polygon; | ||
var featurecollection = require('turf-helpers').featureCollection; | ||
@@ -8,0 +8,0 @@ var poly1 = polygon([[[0,0],[10,0],[10,10],[0,10]]]); |
33
index.js
var inside = require('turf-inside'); | ||
var featureCollection = require('turf-featurecollection'); | ||
var featureCollection = require('turf-helpers').featureCollection; | ||
/** | ||
* Takes a {@link FeatureCollection} of {@link Point} features and a FeatureCollection of {@link Polygon} features and returns a FeatureCollection of Point features representing all points that fall within a collection of polygons. | ||
* Takes a set of {@link Point|points} and a set of {@link Polygon|polygons} and returns the points that fall within the polygons. | ||
* | ||
* @module turf/within | ||
* @name within | ||
* @category joins | ||
* @param {FeatureCollection} points a FeatureCollection of {@link Point} features | ||
* @param {FeatureCollection} polygons a FeatureCollection of {@link Polygon} features | ||
* @return {FeatureCollection} a collection of all points that land | ||
* within at least one polygon | ||
* @param {FeatureCollection<Point>} points input points | ||
* @param {FeatureCollection<Polygon>} polygons input polygons | ||
* @return {FeatureCollection<Point>} points that land within at least one polygon | ||
* @example | ||
@@ -85,13 +84,13 @@ * var searchWithin = { | ||
*/ | ||
module.exports = function(ptFC, polyFC){ | ||
var pointsWithin = featureCollection([]); | ||
for (var i = 0; i < polyFC.features.length; i++) { | ||
for (var j = 0; j < ptFC.features.length; j++) { | ||
var isInside = inside(ptFC.features[j], polyFC.features[i]); | ||
if(isInside){ | ||
pointsWithin.features.push(ptFC.features[j]); | ||
} | ||
module.exports = function (ptFC, polyFC) { | ||
var pointsWithin = featureCollection([]); | ||
for (var i = 0; i < polyFC.features.length; i++) { | ||
for (var j = 0; j < ptFC.features.length; j++) { | ||
var isInside = inside(ptFC.features[j], polyFC.features[i]); | ||
if (isInside) { | ||
pointsWithin.features.push(ptFC.features[j]); | ||
} | ||
} | ||
} | ||
} | ||
return pointsWithin; | ||
return pointsWithin; | ||
}; |
{ | ||
"name": "turf-within", | ||
"version": "1.0.1", | ||
"version": "3.0.0-canary.2f5f7167", | ||
"description": "turf within module", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "tape test.js", | ||
"doc": "dox -r < index.js | doxme --readme > README.md" | ||
"test": "tape test.js" | ||
}, | ||
@@ -30,11 +29,8 @@ "repository": { | ||
"tape": "^3.5.0", | ||
"turf-point": "^2.0.0", | ||
"turf-polygon": "^1.0.2", | ||
"dox": "^0.6.1", | ||
"doxme": "^1.4.3" | ||
"turf-helpers": "^3.0.0-canary.2f5f7167" | ||
}, | ||
"dependencies": { | ||
"turf-featurecollection": "^1.0.0", | ||
"turf-inside": "^1.1.3" | ||
"turf-inside": "^3.0.0-canary.2f5f7167", | ||
"turf-helpers": "^3.0.0-canary.2f5f7167" | ||
} | ||
} |
@@ -10,4 +10,3 @@ # turf-within | ||
Returns a FeatureCollection of points representing all points that fall | ||
within a collection of polygons. | ||
Takes a set of Point|points and a set of Polygon|polygons and returns the points that fall within the polygons. | ||
@@ -17,6 +16,6 @@ | ||
| parameter | type | description | | ||
| ---------- | ----------------- | ----------- | | ||
| `points` | FeatureCollection | | | ||
| `polygons` | FeatureCollection | | | ||
| parameter | type | description | | ||
| ---------- | ------------------------------ | -------------- | | ||
| `points` | FeatureCollection\.\<Point\> | input points | | ||
| `polygons` | FeatureCollection\.\<Polygon\> | input polygons | | ||
@@ -27,25 +26,77 @@ | ||
```js | ||
var searchWithin = turf.featurecollection([ | ||
turf.polygon([ | ||
[[-46.653,-23.543], | ||
[-46.634,-23.5346], | ||
[-46.613,-23.543], | ||
[-46.614,-23.559], | ||
[-46.631,-23.567], | ||
[-46.653,-23.560], | ||
[-46.653,-23.543]] | ||
]) | ||
]); | ||
var points = turf.featurecollection([ | ||
turf.point([-46.6318, -23.5523]), | ||
turf.point([-46.6246, -23.5325]), | ||
turf.point([-46.6062, -23.5513]), | ||
turf.point([-46.663, -23.554]), | ||
turf.point([-46.643, -23.557])]); | ||
var searchWithin = { | ||
"type": "FeatureCollection", | ||
"features": [ | ||
{ | ||
"type": "Feature", | ||
"properties": {}, | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [[ | ||
[-46.653,-23.543], | ||
[-46.634,-23.5346], | ||
[-46.613,-23.543], | ||
[-46.614,-23.559], | ||
[-46.631,-23.567], | ||
[-46.653,-23.560], | ||
[-46.653,-23.543] | ||
]] | ||
} | ||
} | ||
] | ||
}; | ||
var points = { | ||
"type": "FeatureCollection", | ||
"features": [ | ||
{ | ||
"type": "Feature", | ||
"properties": {}, | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [-46.6318, -23.5523] | ||
} | ||
}, { | ||
"type": "Feature", | ||
"properties": {}, | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [-46.6246, -23.5325] | ||
} | ||
}, { | ||
"type": "Feature", | ||
"properties": {}, | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [-46.6062, -23.5513] | ||
} | ||
}, { | ||
"type": "Feature", | ||
"properties": {}, | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [-46.663, -23.554] | ||
} | ||
}, { | ||
"type": "Feature", | ||
"properties": {}, | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [-46.643, -23.557] | ||
} | ||
} | ||
] | ||
}; | ||
var ptsWithin = turf.within(points, searchWithin); | ||
//=points | ||
//=searchWithin | ||
//=ptsWithin | ||
``` | ||
**Returns** `FeatureCollection.<Point>`, points that land within at least one polygon | ||
## Installation | ||
@@ -65,1 +116,2 @@ | ||
var test = require('tape'); | ||
var within = require('./'); | ||
var point = require('turf-point'); | ||
var polygon = require('turf-polygon'); | ||
var featureCollection = require('turf-featurecollection'); | ||
var point = require('turf-helpers').point; | ||
var polygon = require('turf-helpers').polygon; | ||
var featureCollection = require('turf-helpers').featureCollection; | ||
@@ -7,0 +7,0 @@ test('within', function(t){ |
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
8982
3
0
114
7
154
1
1
+ Addedturf-helpers@3.0.12(transitive)
+ Addedturf-inside@3.0.12(transitive)
+ Addedturf-invariant@3.0.12(transitive)
- Removedturf-featurecollection@^1.0.0
- Removedminimist@1.2.8(transitive)
- Removedturf-featurecollection@1.0.1(transitive)
- Removedturf-inside@1.1.4(transitive)