Socket
Socket
Sign inDemoInstall

@turf/intersect

Package Overview
Dependencies
Maintainers
7
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/intersect - npm Package Compare versions

Comparing version 6.5.0 to 7.0.0-alpha.0

25

dist/es/index.js

@@ -1,11 +0,10 @@

import { multiPolygon, polygon, } from "@turf/helpers";
import { getGeom } from "@turf/invariant";
import { multiPolygon, polygon } from "@turf/helpers";
import { geomEach } from "@turf/meta";
import polygonClipping from "polygon-clipping";
/**
* Takes two {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and
* Takes {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and
* finds their polygonal intersection. If they don't intersect, returns null.
*
* @name intersect
* @param {Feature<Polygon | MultiPolygon>} poly1 the first polygon or multipolygon
* @param {Feature<Polygon | MultiPolygon>} poly2 the second polygon or multipolygon
* @param {FeatureCollection<Polygon | MultiPolygon>} features the features to intersect
* @param {Object} [options={}] Optional Parameters

@@ -35,3 +34,3 @@ * @param {Object} [options.properties={}] Translate GeoJSON Properties to Feature

*
* var intersection = turf.intersect(poly1, poly2);
* var intersection = turf.intersect(turf.featureCollection([poly1, poly2]));
*

@@ -41,7 +40,11 @@ * //addToMap

*/
export default function intersect(poly1, poly2, options) {
if (options === void 0) { options = {}; }
var geom1 = getGeom(poly1);
var geom2 = getGeom(poly2);
var intersection = polygonClipping.intersection(geom1.coordinates, geom2.coordinates);
export default function intersect(features, options = {}) {
const geoms = [];
geomEach(features, (geom) => {
geoms.push(geom.coordinates);
});
if (geoms.length < 2) {
throw new Error("Must specify at least 2 geometries");
}
const intersection = polygonClipping.intersection(geoms[0], ...geoms.slice(1));
if (intersection.length === 0)

@@ -48,0 +51,0 @@ return null;

@@ -1,9 +0,8 @@

import { Feature, MultiPolygon, Polygon, Properties } from "@turf/helpers";
import { Feature, GeoJsonProperties, MultiPolygon, Polygon, FeatureCollection } from "geojson";
/**
* Takes two {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and
* Takes {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and
* finds their polygonal intersection. If they don't intersect, returns null.
*
* @name intersect
* @param {Feature<Polygon | MultiPolygon>} poly1 the first polygon or multipolygon
* @param {Feature<Polygon | MultiPolygon>} poly2 the second polygon or multipolygon
* @param {FeatureCollection<Polygon | MultiPolygon>} features the features to intersect
* @param {Object} [options={}] Optional Parameters

@@ -33,3 +32,3 @@ * @param {Object} [options.properties={}] Translate GeoJSON Properties to Feature

*
* var intersection = turf.intersect(poly1, poly2);
* var intersection = turf.intersect(turf.featureCollection([poly1, poly2]));
*

@@ -39,4 +38,4 @@ * //addToMap

*/
export default function intersect<P = Properties>(poly1: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon, poly2: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon, options?: {
export default function intersect<P = GeoJsonProperties>(features: FeatureCollection<Polygon | MultiPolygon>, options?: {
properties?: P;
}): Feature<Polygon | MultiPolygon, P> | null;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var helpers_1 = require("@turf/helpers");
var invariant_1 = require("@turf/invariant");
var polygon_clipping_1 = __importDefault(require("polygon-clipping"));
const tslib_1 = require("tslib");
const helpers_1 = require("@turf/helpers");
const meta_1 = require("@turf/meta");
const polygon_clipping_1 = tslib_1.__importDefault(require("polygon-clipping"));
/**
* Takes two {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and
* Takes {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and
* finds their polygonal intersection. If they don't intersect, returns null.
*
* @name intersect
* @param {Feature<Polygon | MultiPolygon>} poly1 the first polygon or multipolygon
* @param {Feature<Polygon | MultiPolygon>} poly2 the second polygon or multipolygon
* @param {FeatureCollection<Polygon | MultiPolygon>} features the features to intersect
* @param {Object} [options={}] Optional Parameters

@@ -40,3 +37,3 @@ * @param {Object} [options.properties={}] Translate GeoJSON Properties to Feature

*
* var intersection = turf.intersect(poly1, poly2);
* var intersection = turf.intersect(turf.featureCollection([poly1, poly2]));
*

@@ -46,7 +43,11 @@ * //addToMap

*/
function intersect(poly1, poly2, options) {
if (options === void 0) { options = {}; }
var geom1 = invariant_1.getGeom(poly1);
var geom2 = invariant_1.getGeom(poly2);
var intersection = polygon_clipping_1.default.intersection(geom1.coordinates, geom2.coordinates);
function intersect(features, options = {}) {
const geoms = [];
meta_1.geomEach(features, (geom) => {
geoms.push(geom.coordinates);
});
if (geoms.length < 2) {
throw new Error("Must specify at least 2 geometries");
}
const intersection = polygon_clipping_1.default.intersection(geoms[0], ...geoms.slice(1));
if (intersection.length === 0)

@@ -53,0 +54,0 @@ return null;

{
"name": "@turf/intersect",
"version": "6.5.0",
"version": "7.0.0-alpha.0",
"description": "turf intersect module",

@@ -46,3 +46,3 @@ "author": "Turf Authors",

"test:tape": "ts-node -r esm test.js",
"test:types": "tsc --esModuleInterop --noEmit types.ts"
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
},

@@ -62,7 +62,8 @@ "devDependencies": {

"dependencies": {
"@turf/helpers": "^6.5.0",
"@turf/invariant": "^6.5.0",
"polygon-clipping": "^0.15.3"
"@turf/helpers": "^7.0.0-alpha.0",
"@turf/meta": "^7.0.0-alpha.0",
"polygon-clipping": "^0.15.3",
"tslib": "^2.3.0"
},
"gitHead": "5375941072b90d489389db22b43bfe809d5e451e"
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
}

@@ -7,13 +7,14 @@ # @turf/intersect

Takes two [polygon][1] or [multi-polygon][2] geometries and finds their polygonal intersection. If they don't intersect, returns null.
Takes [polygon][1] or [multi-polygon][2] geometries and
finds their polygonal intersection. If they don't intersect, returns null.
**Parameters**
### Parameters
- `poly1` **[Feature][3]&lt;([Polygon][4] \| [MultiPolygon][5])>** the first polygon or multipolygon
- `poly2` **[Feature][3]&lt;([Polygon][4] \| [MultiPolygon][5])>** the second polygon or multipolygon
- `options` **[Object][6]** Optional Parameters (optional, default `{}`)
- `options.properties` **[Object][6]** Translate GeoJSON Properties to Feature (optional, default `{}`)
* `features` **[FeatureCollection][3]<([Polygon][4] | [MultiPolygon][5])>** the features to intersect
* `options` **[Object][6]** Optional Parameters (optional, default `{}`)
**Examples**
* `options.properties` **[Object][6]** Translate GeoJSON Properties to Feature (optional, default `{}`)
### Examples
```javascript

@@ -39,3 +40,3 @@ var poly1 = turf.polygon([[

var intersection = turf.intersect(poly1, poly2);
var intersection = turf.intersect(turf.featureCollection([poly1, poly2]));

@@ -46,3 +47,4 @@ //addToMap

Returns **([Feature][3] | null)** returns a feature representing the area they share (either a [Polygon][1] or [MultiPolygon][2]). If they do not share any area, returns `null`.
Returns **([Feature][7] | null)** returns a feature representing the area they share (either a [Polygon][1] or
[MultiPolygon][2]). If they do not share any area, returns `null`.

@@ -53,3 +55,3 @@ [1]: https://tools.ietf.org/html/rfc7946#section-3.1.6

[3]: https://tools.ietf.org/html/rfc7946#section-3.2
[3]: https://tools.ietf.org/html/rfc7946#section-3.3

@@ -62,2 +64,4 @@ [4]: https://tools.ietf.org/html/rfc7946#section-3.1.6

[7]: https://tools.ietf.org/html/rfc7946#section-3.2
<!-- This file is automatically generated. Please don't edit it directly:

@@ -64,0 +68,0 @@ if you find an error, edit the source file (likely index.js), and re-run

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