Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
@turf/difference
Advanced tools
@turf/difference is a module in the Turf.js library that allows you to compute the geometric difference between two polygons. This is useful in geospatial analysis for determining the area that is unique to one polygon when compared to another.
Compute Difference Between Two Polygons
This feature allows you to compute the difference between two polygons. The resulting polygon represents the area that is unique to the first polygon when compared to the second polygon.
const turf = require('@turf/turf');
const polygon1 = turf.polygon([[
[-82.574787, 35.594087],
[-82.574787, 35.615581],
[-82.545261, 35.615581],
[-82.545261, 35.594087],
[-82.574787, 35.594087]
]]);
const polygon2 = turf.polygon([[
[-82.560024, 35.585153],
[-82.560024, 35.602602],
[-82.52964, 35.602602],
[-82.52964, 35.585153],
[-82.560024, 35.585153]
]]);
const difference = turf.difference(polygon1, polygon2);
console.log(difference);
JSTS is a JavaScript library of spatial predicates and functions for processing geometry. It is a port of the Java Topology Suite (JTS). JSTS provides a more comprehensive set of geometric operations compared to @turf/difference, including union, intersection, and buffer operations.
Martinez Polygon Clipping is a library for performing boolean operations on polygons, such as union, intersection, and difference. It is known for its performance and accuracy, making it a good alternative to @turf/difference for complex polygon operations.
Finds the difference between multiple polygons by clipping the subsequent polygon from the first.
features
FeatureCollection<(Polygon | MultiPolygon)> input Polygon featuresvar polygon1 = turf.polygon([[
[128, -26],
[141, -26],
[141, -21],
[128, -21],
[128, -26]
]], {
"fill": "#F00",
"fill-opacity": 0.1
});
var polygon2 = turf.polygon([[
[126, -28],
[140, -28],
[140, -20],
[126, -20],
[126, -28]
]], {
"fill": "#00F",
"fill-opacity": 0.1
});
var difference = turf.difference(turf.featureCollection([polygon1, polygon2]));
//addToMap
var addToMap = [polygon1, polygon2, difference];
Returns (Feature<(Polygon | MultiPolygon)> | null) a Polygon or MultiPolygon feature showing the area of polygon1
excluding the area of polygon2
(if empty returns null
)
This module is part of the Turfjs project, an open source module collection dedicated to geographic algorithms. It is maintained in the Turfjs/turf repository, where you can create PRs and issues.
Install this single module individually:
$ npm install @turf/difference
Or install the all-encompassing @turf/turf module that includes all modules as functions:
$ npm install @turf/turf
FAQs
turf difference module
The npm package @turf/difference receives a total of 242,427 weekly downloads. As such, @turf/difference popularity was classified as popular.
We found that @turf/difference demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.