Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
@turf/convex
Advanced tools
@turf/convex is a module in the Turf.js library that allows you to compute the convex hull of a set of points. A convex hull is the smallest convex polygon that can enclose all the points in a given dataset. This is useful in various geospatial analyses, such as determining the boundary of a set of geographical points.
Compute Convex Hull
This feature allows you to compute the convex hull of a set of points. The code sample demonstrates how to create a collection of points and then compute the convex hull using the @turf/convex module.
const turf = require('@turf/turf');
const points = turf.featureCollection([
turf.point([10, 10]),
turf.point([20, 20]),
turf.point([30, 30]),
turf.point([40, 40]),
turf.point([50, 50])
]);
const convexHull = turf.convex(points);
console.log(convexHull);
hull.js is a JavaScript library for computing the convex hull of a set of 2D points. It is lightweight and easy to use, but it focuses solely on convex hull calculations, whereas @turf/convex is part of the larger Turf.js library, which offers a wide range of geospatial analysis tools.
concaveman is a fast 2D concave hull algorithm. While it focuses on concave hulls, it can also be used to compute convex hulls by setting the concavity parameter to 1. It is faster and more flexible for certain use cases compared to @turf/convex, but it is not as feature-rich in terms of geospatial analysis.
Takes a Feature or a FeatureCollection and returns a convex hull Polygon.
Internally this uses the convex-hull module that implements a monotone chain hull.
Parameters
feature
(Feature | FeatureCollection) input Feature or FeatureCollectionExamples
var points = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [10.195312, 43.755225]
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [10.404052, 43.8424511]
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [10.579833, 43.659924]
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [10.360107, 43.516688]
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [10.14038, 43.588348]
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [10.195312, 43.755225]
}
}
]
};
var hull = turf.convex(points);
var resultFeatures = points.features.concat(hull);
var result = {
"type": "FeatureCollection",
"features": resultFeatures
};
//=result
Returns Feature<Polygon> a convex hull
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 module individually:
$ npm install @turf/convex
Or install the Turf module that includes it as a function:
$ npm install @turf/turf
FAQs
turf convex module
We found that @turf/convex 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.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
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.