@turf/intersect
Advanced tools
Comparing version 5.1.6 to 6.0.1
58
index.js
@@ -1,8 +0,6 @@ | ||
// depend on jsts for now http://bjornharrtell.github.io/jsts/ | ||
import { GeoJSONReader, GeoJSONWriter, OverlayOp } from 'turf-jsts'; | ||
import truncate from '@turf/truncate'; | ||
import { getGeom } from '@turf/invariant'; | ||
import { feature } from '@turf/helpers'; | ||
import cleanCoords from '@turf/clean-coords'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var martinez = require("martinez-polygon-clipping"); | ||
var invariant_1 = require("@turf/invariant"); | ||
var helpers_1 = require("@turf/helpers"); | ||
/** | ||
@@ -14,2 +12,4 @@ * Takes two {@link Polygon|polygons} and finds their intersection. If they share a border, returns the border; if they don't intersect, returns undefined. | ||
* @param {Feature<Polygon>} poly2 the second polygon | ||
* @param {Object} [options={}] Optional Parameters | ||
* @param {Object} [options.properties={}] Translate GeoJSON Properties to Feature | ||
* @returns {Feature|null} returns a feature representing the point(s) they share (in case of a {@link Point} or {@link MultiPoint}), the borders they share (in case of a {@link LineString} or a {@link MultiLineString}), the area they share (in case of {@link Polygon} or {@link MultiPolygon}). If they do not share any point, returns `null`. | ||
@@ -41,26 +41,22 @@ * @example | ||
*/ | ||
function intersect(poly1, poly2) { | ||
var geom1 = getGeom(poly1); | ||
var geom2 = getGeom(poly2); | ||
// Return null if geometry is too narrow in coordinate precision | ||
// fixes topology errors with JSTS | ||
// https://github.com/Turfjs/turf/issues/463 | ||
// https://github.com/Turfjs/turf/pull/1004 | ||
if (cleanCoords(truncate(geom2, {precision: 4})).coordinates[0].length < 4) return null; | ||
if (cleanCoords(truncate(geom1, {precision: 4})).coordinates[0].length < 4) return null; | ||
var reader = new GeoJSONReader(); | ||
var a = reader.read(truncate(geom1)); | ||
var b = reader.read(truncate(geom2)); | ||
var intersection = OverlayOp.intersection(a, b); | ||
// https://github.com/Turfjs/turf/issues/951 | ||
if (intersection.isEmpty()) return null; | ||
var writer = new GeoJSONWriter(); | ||
var geom = writer.write(intersection); | ||
return feature(geom); | ||
function intersect(poly1, poly2, options) { | ||
if (options === void 0) { options = {}; } | ||
var geom1 = invariant_1.getGeom(poly1); | ||
var geom2 = invariant_1.getGeom(poly2); | ||
if (geom1.type !== 'Polygon') | ||
throw new Error('poly1 must be a Polygon'); | ||
if (geom2.type !== 'Polygon') | ||
throw new Error('poly2 must be a Polygon'); | ||
var intersection = martinez.intersection(geom1.coordinates, geom2.coordinates); | ||
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]) | ||
return helpers_1.polygon(intersection[0], options.properties); | ||
return null; | ||
} | ||
return helpers_1.multiPolygon(intersection, options.properties); | ||
} | ||
export default intersect; | ||
exports.default = intersect; |
{ | ||
"name": "@turf/intersect", | ||
"version": "5.1.6", | ||
"version": "6.0.1", | ||
"description": "turf intersect module", | ||
"main": "main.js", | ||
"module": "main.es.js", | ||
"types": "index.d.ts", | ||
"main": "index", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"main.js", | ||
"main.es.js" | ||
"index.ts" | ||
], | ||
"scripts": { | ||
"pretest": "rollup -c ../../rollup.config.js", | ||
"test": "node -r @std/esm test.js", | ||
"posttest": "node -r @std/esm ../../scripts/validate-es5-dependencies.js", | ||
"bench": "node -r @std/esm bench.js", | ||
"prepare": "tsc", | ||
"pretest": "tsc", | ||
"test": "node test.js", | ||
"bench": "node bench.js", | ||
"docs": "node ../../scripts/generate-readmes" | ||
@@ -37,4 +33,4 @@ }, | ||
"devDependencies": { | ||
"@std/esm": "*", | ||
"benchmark": "*", | ||
"glob": "*", | ||
"load-json-file": "*", | ||
@@ -46,12 +42,6 @@ "rollup": "*", | ||
"dependencies": { | ||
"@turf/clean-coords": "^5.1.5", | ||
"@turf/helpers": "^5.1.5", | ||
"@turf/invariant": "^5.1.5", | ||
"@turf/truncate": "^5.1.5", | ||
"turf-jsts": "*" | ||
}, | ||
"@std/esm": { | ||
"esm": "js", | ||
"cjs": true | ||
"@turf/helpers": "6.x", | ||
"@turf/invariant": "6.x", | ||
"martinez-polygon-clipping": "*" | ||
} | ||
} |
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
3
9608
5
121
1
+ Addedmartinez-polygon-clipping@*
+ Added@turf/helpers@6.5.0(transitive)
+ Added@turf/invariant@6.5.0(transitive)
+ Addedmartinez-polygon-clipping@0.7.4(transitive)
+ Addedrobust-predicates@2.0.4(transitive)
+ Addedsplaytree@0.1.4(transitive)
+ Addedtinyqueue@1.2.3(transitive)
- Removed@turf/clean-coords@^5.1.5
- Removed@turf/truncate@^5.1.5
- Removedturf-jsts@*
- Removed@turf/clean-coords@5.1.5(transitive)
- Removed@turf/helpers@5.1.5(transitive)
- Removed@turf/invariant@5.2.0(transitive)
- Removed@turf/meta@5.2.0(transitive)
- Removed@turf/truncate@5.1.5(transitive)
- Removedturf-jsts@1.2.3(transitive)
Updated@turf/helpers@6.x
Updated@turf/invariant@6.x