UNPKG

2.08 kBMarkdownView Raw
1# turf-convex
2
3[![build status](https://secure.travis-ci.org/Turfjs/turf-convex.png)](http://travis-ci.org/Turfjs/turf-convex)
4
5
6
7
8### `turf.convex(input)`
9
10Takes a set of Point|points and returns a
11[convex hull](http://en.wikipedia.org/wiki/Convex_hull) polygon.
12
13Internally this uses
14the [convex-hull](https://github.com/mikolalysenko/convex-hull) module that
15implements a [monotone chain hull](http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain).
16
17
18### Parameters
19
20| parameter | type | description |
21| --------- | ---------------------------- | ------------ |
22| `input` | FeatureCollection\.\<Point\> | input points |
23
24
25### Example
26
27```js
28var points = {
29 "type": "FeatureCollection",
30 "features": [
31 {
32 "type": "Feature",
33 "properties": {},
34 "geometry": {
35 "type": "Point",
36 "coordinates": [10.195312, 43.755225]
37 }
38 }, {
39 "type": "Feature",
40 "properties": {},
41 "geometry": {
42 "type": "Point",
43 "coordinates": [10.404052, 43.8424511]
44 }
45 }, {
46 "type": "Feature",
47 "properties": {},
48 "geometry": {
49 "type": "Point",
50 "coordinates": [10.579833, 43.659924]
51 }
52 }, {
53 "type": "Feature",
54 "properties": {},
55 "geometry": {
56 "type": "Point",
57 "coordinates": [10.360107, 43.516688]
58 }
59 }, {
60 "type": "Feature",
61 "properties": {},
62 "geometry": {
63 "type": "Point",
64 "coordinates": [10.14038, 43.588348]
65 }
66 }, {
67 "type": "Feature",
68 "properties": {},
69 "geometry": {
70 "type": "Point",
71 "coordinates": [10.195312, 43.755225]
72 }
73 }
74 ]
75};
76
77var hull = turf.convex(points);
78
79var resultFeatures = points.features.concat(hull);
80var result = {
81 "type": "FeatureCollection",
82 "features": resultFeatures
83};
84
85//=result
86```
87
88
89**Returns** `Feature.<Polygon>`, a convex hull
90
91## Installation
92
93Requires [nodejs](http://nodejs.org/).
94
95```sh
96$ npm install turf-convex
97```
98
99## Tests
100
101```sh
102$ npm test
103```
104
105