|
4 | 4 |
|
5 | 5 | ## union |
6 | 6 |
|
7 | | -Takes input [(Multi)Polygon(s)][1] and returns a combined polygon. If the input polygons are not contiguous, this function returns a [MultiPolygon][2] feature. |
| 7 | +Takes a collection of input polygons and returns a combined polygon. If the |
| 8 | +input polygons are not contiguous, this function returns a multi-polygon |
| 9 | +feature. |
8 | 10 |
|
9 | 11 | ### Parameters |
10 | 12 |
|
11 | | -* `features` **[FeatureCollection][3]<([Polygon][1] | [MultiPolygon][2])>**  |
| 13 | +* `features` **[FeatureCollection][1]<([Polygon][2] | [MultiPolygon][3])>** input polygon features |
12 | 14 | * `options` **[Object][4]** Optional Parameters (optional, default `{}`) |
13 | 15 |
|
14 | | - * `options.properties` **[Object][4]** Translate Properties to output Feature (optional, default `{}`) |
15 | | -* `polygon1` **[Feature][5]<([Polygon][1] | [MultiPolygon][2])>** input Polygon features |
| 16 | + * `options.properties` **[GeoJsonProperties][5]** properties to assign to output feature (optional, default `{}`) |
16 | 17 |
|
17 | 18 | ### Examples |
18 | 19 |
|
19 | 20 | ```javascript |
20 | | -var poly1 = turf.polygon([[ |
21 | | - [-82.574787, 35.594087], |
22 | | - [-82.574787, 35.615581], |
23 | | - [-82.545261, 35.615581], |
24 | | - [-82.545261, 35.594087], |
25 | | - [-82.574787, 35.594087] |
26 | | -]], {"fill": "#0f0"}); |
27 | | -var poly2 = turf.polygon([[ |
28 | | - [-82.560024, 35.585153], |
29 | | - [-82.560024, 35.602602], |
30 | | - [-82.52964, 35.602602], |
31 | | - [-82.52964, 35.585153], |
32 | | - [-82.560024, 35.585153] |
33 | | -]], {"fill": "#00f"}); |
34 | | - |
35 | | -var union = turf.union(turf.featureCollection([poly1, poly2])); |
| 21 | +const poly1 = turf.polygon( |
| 22 | + [ |
| 23 | + [ |
| 24 | + [-82.574787, 35.594087], |
| 25 | + [-82.574787, 35.615581], |
| 26 | + [-82.545261, 35.615581], |
| 27 | + [-82.545261, 35.594087], |
| 28 | + [-82.574787, 35.594087], |
| 29 | + ], |
| 30 | + ], |
| 31 | + { fill: "#0f0" } |
| 32 | +); |
| 33 | + |
| 34 | +const poly2 = turf.polygon( |
| 35 | + [ |
| 36 | + [ |
| 37 | + [-82.560024, 35.585153], |
| 38 | + [-82.560024, 35.602602], |
| 39 | + [-82.52964, 35.602602], |
| 40 | + [-82.52964, 35.585153], |
| 41 | + [-82.560024, 35.585153], |
| 42 | + ], |
| 43 | + ], |
| 44 | +); |
| 45 | + |
| 46 | +const union = turf.union(turf.featureCollection([poly1, poly2])); |
36 | 47 |
|
37 | 48 | //addToMap |
38 | | -var addToMap = [poly1, poly2, union]; |
| 49 | +const addToMap = { poly1, poly2, union }; |
| 50 | + |
| 51 | +poly1.properties.fill = "#0f0"; |
| 52 | +poly2.properties.fill = "#00f"; |
| 53 | +union.properties.stroke = "red"; |
| 54 | +union.properties["stroke-width"] = 4; |
| 55 | +union.properties.fill = "transparent"; |
39 | 56 | ``` |
40 | 57 |
|
41 | | -Returns **[Feature][5]<([Polygon][1] | [MultiPolygon][2])>** a combined [Polygon][1] or [MultiPolygon][2] feature, or null if the inputs are empty |
| 58 | +Returns **([Feature][5]<([Polygon][2] | [MultiPolygon][3])> | null)** a combined polygon or multi-polygon feature, or null if there were no input polygons to combine |
42 | 59 |
|
43 | | -[1]: https://tools.ietf.org/html/rfc7946#section-3.1.6 |
| 60 | +[1]: https://tools.ietf.org/html/rfc7946#section-3.3 |
44 | 61 |
|
45 | | -[2]: https://tools.ietf.org/html/rfc7946#section-3.1.7 |
| 62 | +[2]: https://tools.ietf.org/html/rfc7946#section-3.1.6 |
46 | 63 |
|
47 | | -[3]: https://tools.ietf.org/html/rfc7946#section-3.3 |
| 64 | +[3]: https://tools.ietf.org/html/rfc7946#section-3.1.7 |
48 | 65 |
|
49 | 66 | [4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object |
50 | 67 |
|
|
0 commit comments