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

@turf/points-within-polygon

Package Overview
Dependencies
Maintainers
6
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/points-within-polygon - npm Package Compare versions

Comparing version 6.4.0 to 6.5.0

39

dist/es/index.js
import pointInPolygon from '@turf/boolean-point-in-polygon';
import { featureCollection } from '@turf/helpers';
import { geomEach, featureEach } from '@turf/meta';
import { multiPoint, featureCollection } from '@turf/helpers';
import { featureEach, geomEach, coordEach } from '@turf/meta';
/**
* Finds {@link Points} that fall within {@link (Multi)Polygon(s)}.
* Finds {@link Points} or {@link MultiPoint} coordinate positions that fall within {@link (Multi)Polygon(s)}.
*
* @name pointsWithinPolygon
* @param {Feature|FeatureCollection<Point>} points Points as input search
* @param {FeatureCollection|Geometry|Feature<Polygon|MultiPolygon>} polygons Points must be within these (Multi)Polygon(s)
* @returns {FeatureCollection<Point>} points that land within at least one polygon
* @param {Feature|FeatureCollection<Point|MultiPoint>} points Point(s) or MultiPoint(s) as input search
* @param {FeatureCollection|Geometry|Feature<Polygon|MultiPolygon>} polygons (Multi)Polygon(s) to check if points are within
* @returns {FeatureCollection<Point|MultiPoint>} Point(s) or MultiPoint(s) with positions that land within at least one polygon. The geometry type will match what was passsed in
* @example

@@ -44,7 +44,24 @@ * var points = turf.points([

var contained = false;
geomEach(polygons, function (polygon) {
if (pointInPolygon(point, polygon)) contained = true;
});
if (contained) {
results.push(point);
if (point.geometry.type === "Point") {
geomEach(polygons, function (polygon) {
if (pointInPolygon(point, polygon)) contained = true;
});
if (contained) {
results.push(point);
}
} else if (point.geometry.type === "MultiPoint") {
var pointsWithin = [];
geomEach(polygons, function (polygon) {
coordEach(point, function (pointCoord) {
if (pointInPolygon(pointCoord, polygon)) {
contained = true;
pointsWithin.push(pointCoord);
}
});
});
if (contained) {
results.push(multiPoint(pointsWithin));
}
} else {
throw new Error("Input geometry must be a Point or MultiPoint");
}

@@ -51,0 +68,0 @@ });

'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var pointInPolygon = _interopDefault(require('@turf/boolean-point-in-polygon'));
var pointInPolygon = require('@turf/boolean-point-in-polygon');
var helpers = require('@turf/helpers');
var meta = require('@turf/meta');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var pointInPolygon__default = /*#__PURE__*/_interopDefaultLegacy(pointInPolygon);
/**
* Finds {@link Points} that fall within {@link (Multi)Polygon(s)}.
* Finds {@link Points} or {@link MultiPoint} coordinate positions that fall within {@link (Multi)Polygon(s)}.
*
* @name pointsWithinPolygon
* @param {Feature|FeatureCollection<Point>} points Points as input search
* @param {FeatureCollection|Geometry|Feature<Polygon|MultiPolygon>} polygons Points must be within these (Multi)Polygon(s)
* @returns {FeatureCollection<Point>} points that land within at least one polygon
* @param {Feature|FeatureCollection<Point|MultiPoint>} points Point(s) or MultiPoint(s) as input search
* @param {FeatureCollection|Geometry|Feature<Polygon|MultiPolygon>} polygons (Multi)Polygon(s) to check if points are within
* @returns {FeatureCollection<Point|MultiPoint>} Point(s) or MultiPoint(s) with positions that land within at least one polygon. The geometry type will match what was passsed in
* @example

@@ -48,7 +50,24 @@ * var points = turf.points([

var contained = false;
meta.geomEach(polygons, function (polygon) {
if (pointInPolygon(point, polygon)) contained = true;
});
if (contained) {
results.push(point);
if (point.geometry.type === "Point") {
meta.geomEach(polygons, function (polygon) {
if (pointInPolygon__default['default'](point, polygon)) contained = true;
});
if (contained) {
results.push(point);
}
} else if (point.geometry.type === "MultiPoint") {
var pointsWithin = [];
meta.geomEach(polygons, function (polygon) {
meta.coordEach(point, function (pointCoord) {
if (pointInPolygon__default['default'](pointCoord, polygon)) {
contained = true;
pointsWithin.push(pointCoord);
}
});
});
if (contained) {
results.push(helpers.multiPoint(pointsWithin));
}
} else {
throw new Error("Input geometry must be a Point or MultiPoint");
}

@@ -60,1 +79,2 @@ });

module.exports = pointsWithinPolygon;
module.exports.default = pointsWithinPolygon;

@@ -6,2 +6,3 @@ import {

MultiPolygon,
MultiPoint,
Point,

@@ -15,7 +16,8 @@ Properties,

export default function pointsWithinPolygon<
F extends Point | MultiPoint,
G extends Polygon | MultiPolygon,
P = Properties
>(
points: Feature<Point, P> | FeatureCollection<Point, P>,
points: Feature<F, P> | FeatureCollection<F, P>,
polygons: Feature<G> | FeatureCollection<G> | G
): FeatureCollection<Point, P>;
): FeatureCollection<F, P>;
{
"name": "@turf/points-within-polygon",
"version": "6.4.0",
"version": "6.5.0",
"description": "turf points-within-polygon module",

@@ -15,2 +15,3 @@ "author": "Turf Authors",

},
"funding": "https://opencollective.com/turf",
"publishConfig": {

@@ -56,7 +57,7 @@ "access": "public"

"dependencies": {
"@turf/boolean-point-in-polygon": "^6.4.0",
"@turf/helpers": "^6.4.0",
"@turf/meta": "^6.4.0"
"@turf/boolean-point-in-polygon": "^6.5.0",
"@turf/helpers": "^6.5.0",
"@turf/meta": "^6.5.0"
},
"gitHead": "1e62773cfc88c627cca8effcb5c14cfb65a905ac"
"gitHead": "5375941072b90d489389db22b43bfe809d5e451e"
}
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