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

turf-within

Package Overview
Dependencies
Maintainers
9
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

turf-within - npm Package Compare versions

Comparing version 1.0.1 to 3.0.0-canary.2f5f7167

6

bench.js
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]]]);

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

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