@turf/points-within-polygon
Advanced tools
Comparing version 5.0.4 to 5.1.0
@@ -1,2 +0,2 @@ | ||
import { FeatureCollection, Polygon, Point } from '@turf/helpers' | ||
import { Feature, FeatureCollection, Polygon, MultiPolygon, Point } from '@turf/helpers' | ||
@@ -6,5 +6,5 @@ /** | ||
*/ | ||
export default function pointsWithinPolygon( | ||
points: FeatureCollection<Point>, | ||
polygons: FeatureCollection<Polygon> | ||
export default function pointsWithinPolygon<G extends Polygon | MultiPolygon>( | ||
points: Feature<Point> | FeatureCollection<Point>, | ||
polygons: Feature<G> | FeatureCollection<G> | G | ||
): FeatureCollection<Point>; |
59
index.js
@@ -1,31 +0,31 @@ | ||
import booleanPointInPolygon from '@turf/boolean-point-in-polygon'; | ||
import pointInPolygon from '@turf/boolean-point-in-polygon'; | ||
import { featureCollection } from '@turf/helpers'; | ||
import { geomEach, featureEach } from '@turf/meta'; | ||
/** | ||
* Takes a set of {@link Point|points} and a set of {@link Polygon|polygons} and returns the points that fall within the polygons. | ||
* Finds {@link Points} that fall within {@link (Multi)Polygon(s)}. | ||
* | ||
* @name pointsWithinPolygon | ||
* @param {FeatureCollection<Point>} points input points | ||
* @param {FeatureCollection<Polygon>} polygons input polygons | ||
* @param {Feauture|FeatureCollection<Point>} points Points as input search | ||
* @param {FeatureCollection|Geoemtry|Feature<Polygon|MultiPolygon>} polygons Points must be within these (Multi)Polygon(s) | ||
* @returns {FeatureCollection<Point>} points that land within at least one polygon | ||
* @example | ||
* 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.points([ | ||
* [-46.6318, -23.5523], | ||
* [-46.6246, -23.5325], | ||
* [-46.6062, -23.5513], | ||
* [-46.663, -23.554], | ||
* [-46.643, -23.557] | ||
* ]); | ||
* 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 = 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 ptsWithin = turf.pointsWithinPolygon(points, searchWithin); | ||
@@ -41,14 +41,11 @@ * | ||
function pointsWithinPolygon(points, polygons) { | ||
var pointsWithin = featureCollection([]); | ||
for (var i = 0; i < polygons.features.length; i++) { | ||
for (var j = 0; j < points.features.length; j++) { | ||
var isInside = booleanPointInPolygon(points.features[j], polygons.features[i]); | ||
if (isInside) { | ||
pointsWithin.features.push(points.features[j]); | ||
} | ||
} | ||
} | ||
return pointsWithin; | ||
var results = []; | ||
geomEach(polygons, function (polygon) { | ||
featureEach(points, function (point) { | ||
if (pointInPolygon(point, polygon)) results.push(point); | ||
}); | ||
}); | ||
return featureCollection(results); | ||
} | ||
export default pointsWithinPolygon; |
59
main.js
@@ -5,32 +5,32 @@ 'use strict'; | ||
var booleanPointInPolygon = _interopDefault(require('@turf/boolean-point-in-polygon')); | ||
var pointInPolygon = _interopDefault(require('@turf/boolean-point-in-polygon')); | ||
var helpers = require('@turf/helpers'); | ||
var meta = require('@turf/meta'); | ||
/** | ||
* Takes a set of {@link Point|points} and a set of {@link Polygon|polygons} and returns the points that fall within the polygons. | ||
* Finds {@link Points} that fall within {@link (Multi)Polygon(s)}. | ||
* | ||
* @name pointsWithinPolygon | ||
* @param {FeatureCollection<Point>} points input points | ||
* @param {FeatureCollection<Polygon>} polygons input polygons | ||
* @param {Feauture|FeatureCollection<Point>} points Points as input search | ||
* @param {FeatureCollection|Geoemtry|Feature<Polygon|MultiPolygon>} polygons Points must be within these (Multi)Polygon(s) | ||
* @returns {FeatureCollection<Point>} points that land within at least one polygon | ||
* @example | ||
* 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.points([ | ||
* [-46.6318, -23.5523], | ||
* [-46.6246, -23.5325], | ||
* [-46.6062, -23.5513], | ||
* [-46.663, -23.554], | ||
* [-46.643, -23.557] | ||
* ]); | ||
* 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 = 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 ptsWithin = turf.pointsWithinPolygon(points, searchWithin); | ||
@@ -46,12 +46,9 @@ * | ||
function pointsWithinPolygon(points, polygons) { | ||
var pointsWithin = helpers.featureCollection([]); | ||
for (var i = 0; i < polygons.features.length; i++) { | ||
for (var j = 0; j < points.features.length; j++) { | ||
var isInside = booleanPointInPolygon(points.features[j], polygons.features[i]); | ||
if (isInside) { | ||
pointsWithin.features.push(points.features[j]); | ||
} | ||
} | ||
} | ||
return pointsWithin; | ||
var results = []; | ||
meta.geomEach(polygons, function (polygon) { | ||
meta.featureEach(points, function (point) { | ||
if (pointInPolygon(point, polygon)) { results.push(point); } | ||
}); | ||
}); | ||
return helpers.featureCollection(results); | ||
} | ||
@@ -58,0 +55,0 @@ |
{ | ||
"name": "@turf/points-within-polygon", | ||
"version": "5.0.4", | ||
"version": "5.1.0", | ||
"description": "turf points-within-polygon module", | ||
"main": "main", | ||
"module": "index", | ||
"jsnext:main": "index", | ||
"main": "main.js", | ||
"module": "main.mjs", | ||
"types": "index.d.ts", | ||
@@ -12,3 +11,4 @@ "files": [ | ||
"index.d.ts", | ||
"main.js" | ||
"main.js", | ||
"main.mjs" | ||
], | ||
@@ -18,3 +18,4 @@ "scripts": { | ||
"test": "node -r @std/esm test.js", | ||
"bench": "node -r @std/esm bench.js" | ||
"bench": "node -r @std/esm bench.js", | ||
"docs": "node ../../scripts/generate-readmes" | ||
}, | ||
@@ -42,7 +43,9 @@ "repository": { | ||
"rollup": "*", | ||
"rollup-plugin-buble": "*", | ||
"tape": "*" | ||
}, | ||
"dependencies": { | ||
"@turf/boolean-point-in-polygon": "^5.0.4", | ||
"@turf/helpers": "^5.0.4" | ||
"@turf/boolean-point-in-polygon": "^5.1.0", | ||
"@turf/helpers": "^5.1.0", | ||
"@turf/meta": "^5.1.0" | ||
}, | ||
@@ -49,0 +52,0 @@ "@std/esm": { |
@@ -7,8 +7,8 @@ # @turf/points-within-polygon | ||
Takes a set of [points](http://geojson.org/geojson-spec.html#point) and a set of [polygons](http://geojson.org/geojson-spec.html#polygon) and returns the points that fall within the polygons. | ||
Finds [Points](https://tools.ietf.org/html/rfc7946#section-3.1.2) that fall within [(Multi)Polygon(s)](https://tools.ietf.org/html/rfc7946#section-3.1.6). | ||
**Parameters** | ||
- `points` **[FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)<[Point](http://geojson.org/geojson-spec.html#point)>** input points | ||
- `polygons` **[FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)<[Polygon](http://geojson.org/geojson-spec.html#polygon)>** input polygons | ||
- `points` **(Feauture | [FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3)<[Point](https://tools.ietf.org/html/rfc7946#section-3.1.2)>)** Points as input search | ||
- `polygons` **([FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) | Geoemtry | [Feature](https://tools.ietf.org/html/rfc7946#section-3.2)<([Polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6) \| [MultiPolygon](https://tools.ietf.org/html/rfc7946#section-3.1.7))>)** Points must be within these (Multi)Polygon(s) | ||
@@ -18,21 +18,20 @@ **Examples** | ||
```javascript | ||
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.points([ | ||
[-46.6318, -23.5523], | ||
[-46.6246, -23.5325], | ||
[-46.6062, -23.5513], | ||
[-46.663, -23.554], | ||
[-46.643, -23.557] | ||
]); | ||
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 = 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 ptsWithin = turf.pointsWithinPolygon(points, searchWithin); | ||
@@ -48,3 +47,3 @@ | ||
Returns **[FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)<[Point](http://geojson.org/geojson-spec.html#point)>** points that land within at least one polygon | ||
Returns **[FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3)<[Point](https://tools.ietf.org/html/rfc7946#section-3.1.2)>** points that land within at least one polygon | ||
@@ -51,0 +50,0 @@ <!-- This file is automatically generated. Please don't edit it directly: |
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
10040
7
155
3
5
71
+ Added@turf/meta@^5.1.0
+ Added@turf/meta@5.2.0(transitive)
Updated@turf/helpers@^5.1.0