@turf/convex 6.5.0 → 7.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -9
- package/dist/es/index.js +5 -6
- package/dist/js/index.d.ts +3 -2
- package/dist/js/index.js +8 -11
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -7,17 +7,18 @@
|
|
|
7
7
|
Takes a [Feature][1] or a [FeatureCollection][2] and returns a convex hull [Polygon][3].
|
|
8
8
|
|
|
9
9
|
Internally this uses
|
|
10
|
-
the [convex-hull][4] module that
|
|
11
|
-
|
|
10
|
+
the [convex-hull][4] module that implements a
|
|
11
|
+
[monotone chain hull][5].
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
### Parameters
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- `options.concavity` **[number][8]** 1 - thin shape. Infinity - convex hull. (optional, default `Infinity`)
|
|
18
|
-
- `options.properties` **[Object][7]** Translate Properties to Feature (optional, default `{}`)
|
|
15
|
+
* `geojson` **[GeoJSON][6]** input Feature or FeatureCollection
|
|
16
|
+
* `options` **[Object][7]** Optional parameters (optional, default `{}`)
|
|
19
17
|
|
|
20
|
-
**
|
|
18
|
+
* `options.concavity` **[number][8]** 1 - thin shape. Infinity - convex hull. (optional, default `Infinity`)
|
|
19
|
+
* `options.properties` **[Object][7]** Translate Properties to Feature (optional, default `{}`)
|
|
20
|
+
|
|
21
|
+
### Examples
|
|
21
22
|
|
|
22
23
|
```javascript
|
|
23
24
|
var points = turf.featureCollection([
|
|
@@ -35,7 +36,7 @@ var hull = turf.convex(points);
|
|
|
35
36
|
var addToMap = [points, hull]
|
|
36
37
|
```
|
|
37
38
|
|
|
38
|
-
Returns **[Feature][9]
|
|
39
|
+
Returns **[Feature][9]<[Polygon][10]>** a convex hull
|
|
39
40
|
|
|
40
41
|
[1]: https://tools.ietf.org/html/rfc7946#section-3.2
|
|
41
42
|
|
package/dist/es/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { polygon
|
|
1
|
+
import { polygon } from "@turf/helpers";
|
|
2
2
|
import { coordEach } from "@turf/meta";
|
|
3
3
|
import concaveman from "concaveman";
|
|
4
4
|
/**
|
|
@@ -29,20 +29,19 @@ import concaveman from "concaveman";
|
|
|
29
29
|
* //addToMap
|
|
30
30
|
* var addToMap = [points, hull]
|
|
31
31
|
*/
|
|
32
|
-
export default function convex(geojson, options) {
|
|
33
|
-
if (options === void 0) { options = {}; }
|
|
32
|
+
export default function convex(geojson, options = {}) {
|
|
34
33
|
// Default parameters
|
|
35
34
|
options.concavity = options.concavity || Infinity;
|
|
36
35
|
// Container
|
|
37
|
-
|
|
36
|
+
const points = [];
|
|
38
37
|
// Convert all points to flat 2D coordinate Array
|
|
39
|
-
coordEach(geojson,
|
|
38
|
+
coordEach(geojson, (coord) => {
|
|
40
39
|
points.push([coord[0], coord[1]]);
|
|
41
40
|
});
|
|
42
41
|
if (!points.length) {
|
|
43
42
|
return null;
|
|
44
43
|
}
|
|
45
|
-
|
|
44
|
+
const convexHull = concaveman(points, options.concavity);
|
|
46
45
|
// Convex hull should have at least 3 different vertices in order to create a valid polygon
|
|
47
46
|
if (convexHull.length > 3) {
|
|
48
47
|
return polygon([convexHull]);
|
package/dist/js/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Feature, GeoJsonProperties, Polygon } from "geojson";
|
|
2
|
+
import { AllGeoJSON } from "@turf/helpers";
|
|
2
3
|
/**
|
|
3
4
|
* Takes a {@link Feature} or a {@link FeatureCollection} and returns a convex hull {@link Polygon}.
|
|
4
5
|
*
|
|
@@ -27,7 +28,7 @@ import { AllGeoJSON, Feature, Polygon, Properties } from "@turf/helpers";
|
|
|
27
28
|
* //addToMap
|
|
28
29
|
* var addToMap = [points, hull]
|
|
29
30
|
*/
|
|
30
|
-
export default function convex<P =
|
|
31
|
+
export default function convex<P = GeoJsonProperties>(geojson: AllGeoJSON, options?: {
|
|
31
32
|
concavity?: number;
|
|
32
33
|
properties?: P;
|
|
33
34
|
}): Feature<Polygon, P> | null;
|
package/dist/js/index.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const helpers_1 = require("@turf/helpers");
|
|
5
|
+
const meta_1 = require("@turf/meta");
|
|
6
|
+
const concaveman_1 = tslib_1.__importDefault(require("concaveman"));
|
|
9
7
|
/**
|
|
10
8
|
* Takes a {@link Feature} or a {@link FeatureCollection} and returns a convex hull {@link Polygon}.
|
|
11
9
|
*
|
|
@@ -34,20 +32,19 @@ var concaveman_1 = __importDefault(require("concaveman"));
|
|
|
34
32
|
* //addToMap
|
|
35
33
|
* var addToMap = [points, hull]
|
|
36
34
|
*/
|
|
37
|
-
function convex(geojson, options) {
|
|
38
|
-
if (options === void 0) { options = {}; }
|
|
35
|
+
function convex(geojson, options = {}) {
|
|
39
36
|
// Default parameters
|
|
40
37
|
options.concavity = options.concavity || Infinity;
|
|
41
38
|
// Container
|
|
42
|
-
|
|
39
|
+
const points = [];
|
|
43
40
|
// Convert all points to flat 2D coordinate Array
|
|
44
|
-
meta_1.coordEach(geojson,
|
|
41
|
+
meta_1.coordEach(geojson, (coord) => {
|
|
45
42
|
points.push([coord[0], coord[1]]);
|
|
46
43
|
});
|
|
47
44
|
if (!points.length) {
|
|
48
45
|
return null;
|
|
49
46
|
}
|
|
50
|
-
|
|
47
|
+
const convexHull = concaveman_1.default(points, options.concavity);
|
|
51
48
|
// Convex hull should have at least 3 different vertices in order to create a valid polygon
|
|
52
49
|
if (convexHull.length > 3) {
|
|
53
50
|
return helpers_1.polygon([convexHull]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/convex",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-alpha.0",
|
|
4
4
|
"description": "turf convex module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"test:tape": "ts-node -r esm test.js"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@types/concaveman": "
|
|
47
|
+
"@types/concaveman": "^1.1.3",
|
|
48
48
|
"@types/tape": "*",
|
|
49
49
|
"benchmark": "*",
|
|
50
50
|
"glob": "*",
|
|
@@ -57,9 +57,10 @@
|
|
|
57
57
|
"write-json-file": "*"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@turf/helpers": "^
|
|
61
|
-
"@turf/meta": "^
|
|
62
|
-
"concaveman": "
|
|
60
|
+
"@turf/helpers": "^7.0.0-alpha.0",
|
|
61
|
+
"@turf/meta": "^7.0.0-alpha.0",
|
|
62
|
+
"concaveman": "^1.2.1",
|
|
63
|
+
"tslib": "^2.3.0"
|
|
63
64
|
},
|
|
64
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
|
|
65
66
|
}
|