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

@turf/intersect

Package Overview
Dependencies
Maintainers
4
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.1.1 to 6.1.2

index.d.ts

56

index.js
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
}
Object.defineProperty(exports, "__esModule", { value: true });
var martinez = require("martinez-polygon-clipping");
var helpers_1 = require("@turf/helpers");
var invariant_1 = require("@turf/invariant");
var helpers_1 = require("@turf/helpers");
var martinez = __importStar(require("martinez-polygon-clipping"));
/**
* Takes two {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and finds their polygonal intersection. If they don't intersect, returns null.
* Takes two {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and
* finds their polygonal intersection. If they don't intersect, returns null.
*

@@ -14,3 +22,4 @@ * @name intersect

* @param {Object} [options.properties={}] Translate GeoJSON Properties to Feature
* @returns {Feature|null} returns a feature representing the area they share (either a {@link Polygon} or {@link MultiPolygon}). If they do not share any area, returns `null`.
* @returns {Feature|null} returns a feature representing the area they share (either a {@link Polygon} or
* {@link MultiPolygon}). If they do not share any area, returns `null`.
* @example

@@ -45,11 +54,13 @@ * var poly1 = turf.polygon([[

var geom2 = invariant_1.getGeom(poly2);
if (geom1.type === 'Polygon' && geom2.type === 'Polygon') {
if (geom1.type === "Polygon" && geom2.type === "Polygon") {
var intersection = martinez.intersection(geom1.coordinates, geom2.coordinates);
if (intersection === null || intersection.length === 0)
if (intersection === null || intersection.length === 0) {
return null;
}
if (intersection.length === 1) {
var start = intersection[0][0][0];
var end = intersection[0][0][intersection[0][0].length - 1];
if (start[0] === end[0] && start[1] === end[1])
if (start[0] === end[0] && start[1] === end[1]) {
return helpers_1.polygon(intersection[0], options.properties);
}
return null;

@@ -59,27 +70,34 @@ }

}
else if (geom1.type === 'MultiPolygon') {
else if (geom1.type === "MultiPolygon") {
var resultCoords = [];
// iterate through the polygon and run intersect with each part, adding to the resultCoords.
for (var i = 0; i < geom1.coordinates.length; i++) {
var subGeom = invariant_1.getGeom(helpers_1.polygon(geom1.coordinates[i]));
for (var _i = 0, _a = geom1.coordinates; _i < _a.length; _i++) {
var coords = _a[_i];
var subGeom = invariant_1.getGeom(helpers_1.polygon(coords));
var subIntersection = intersect(subGeom, geom2);
if (subIntersection) {
var subIntGeom = invariant_1.getGeom(subIntersection);
if (subIntGeom.type === 'Polygon')
if (subIntGeom.type === "Polygon") {
resultCoords.push(subIntGeom.coordinates);
else if (subIntGeom.type === 'MultiPolygon')
}
else if (subIntGeom.type === "MultiPolygon") {
resultCoords = resultCoords.concat(subIntGeom.coordinates);
else
throw new Error('intersection is invalid');
}
else {
throw new Error("intersection is invalid");
}
}
}
// Make a polygon with the result
if (resultCoords.length === 0)
if (resultCoords.length === 0) {
return null;
if (resultCoords.length === 1)
}
if (resultCoords.length === 1) {
return helpers_1.polygon(resultCoords[0], options.properties);
else
}
else {
return helpers_1.multiPolygon(resultCoords, options.properties);
}
}
else if (geom2.type === 'MultiPolygon') {
else if (geom2.type === "MultiPolygon") {
// geom1 is a polygon and geom2 a multiPolygon,

@@ -91,5 +109,5 @@ // put the multiPolygon first and fallback to the previous case.

// handle invalid geometry types
throw new Error('poly1 and poly2 must be either polygons or multiPolygons');
throw new Error("poly1 and poly2 must be either polygons or multiPolygons");
}
}
exports.default = intersect;
{
"name": "@turf/intersect",
"version": "6.1.1",
"version": "6.1.2",
"description": "turf intersect module",

@@ -5,0 +5,0 @@ "main": "index",

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