Skip to content

Commit 212d166

Browse files
turf-hexgrid: fix issue #2841 (#2856)
* turf-hexgrid: fix issue #2841 Typing of mask does not allow for MultiPolygon while the documentation obviously states that this is allowed * feat: update readme of turf-hexgrid to include MultiPolygon
1 parent e6d540a commit 212d166

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

packages/turf-hex-grid/README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ described in [Hexagonal Grids][3].
1717

1818
* `options.units` **[string][7]** used in calculating cell size, can be degrees, radians, miles, or kilometers (optional, default `'kilometers'`)
1919
* `options.properties` **[Object][6]** passed to each hexagon or triangle of the grid (optional, default `{}`)
20-
* `options.mask` **[Feature][8]<[Polygon][2]>?** if passed a Polygon or MultiPolygon, the grid Points will be created only inside it
21-
* `options.triangles` **[boolean][9]** whether to return as triangles instead of hexagons (optional, default `false`)
20+
* `options.mask` **[Feature][8]<([Polygon][2] | [MultiPolygon][9])>?** if passed a Polygon or MultiPolygon, the grid Points will be created only inside it
21+
* `options.triangles` **[boolean][10]** whether to return as triangles instead of hexagons (optional, default `false`)
2222

2323
### Examples
2424

@@ -51,7 +51,9 @@ Returns **[FeatureCollection][1]<[Polygon][2]>** a hexagonal grid
5151

5252
[8]: https://tools.ietf.org/html/rfc7946#section-3.2
5353

54-
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
54+
[9]: https://tools.ietf.org/html/rfc7946#section-3.1.7
55+
56+
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
5557

5658
<!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
5759

packages/turf-hex-grid/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
GeoJsonProperties,
77
Polygon,
88
BBox,
9+
MultiPolygon,
910
} from "geojson";
1011
import { polygon, featureCollection, Units } from "@turf/helpers";
1112

@@ -21,7 +22,7 @@ import { polygon, featureCollection, Units } from "@turf/helpers";
2122
* @param {Object} [options={}] Optional parameters
2223
* @param {string} [options.units='kilometers'] used in calculating cell size, can be degrees, radians, miles, or kilometers
2324
* @param {Object} [options.properties={}] passed to each hexagon or triangle of the grid
24-
* @param {Feature<Polygon>} [options.mask] if passed a Polygon or MultiPolygon, the grid Points will be created only inside it
25+
* @param {Feature<Polygon | MultiPolygon>} [options.mask] if passed a Polygon or MultiPolygon, the grid Points will be created only inside it
2526
* @param {boolean} [options.triangles=false] whether to return as triangles instead of hexagons
2627
* @returns {FeatureCollection<Polygon>} a hexagonal grid
2728
* @example
@@ -41,7 +42,7 @@ function hexGrid<P extends GeoJsonProperties = GeoJsonProperties>(
4142
units?: Units;
4243
triangles?: boolean;
4344
properties?: P;
44-
mask?: Feature<Polygon>;
45+
mask?: Feature<Polygon | MultiPolygon>;
4546
} = {}
4647
): FeatureCollection<Polygon, P> {
4748
// Issue => https://github.com/Turfjs/turf/issues/1284

packages/turf-hex-grid/test/in/properties.json

+9-7
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
"type": "Feature",
99
"properties": {},
1010
"geometry": {
11-
"type": "Polygon",
11+
"type": "MultiPolygon",
1212
"coordinates": [
1313
[
14-
[2.223186492919922, 41.416856461155575],
15-
[2.1716880798339844, 41.44182560856202],
16-
[2.1636199951171875, 41.41608406639095],
17-
[2.1334075927734375, 41.407200866420744],
18-
[2.1845626831054683, 41.37977115211044],
19-
[2.223186492919922, 41.416856461155575]
14+
[
15+
[2.223186492919922, 41.416856461155575],
16+
[2.1716880798339844, 41.44182560856202],
17+
[2.1636199951171875, 41.41608406639095],
18+
[2.1334075927734375, 41.407200866420744],
19+
[2.1845626831054683, 41.37977115211044],
20+
[2.223186492919922, 41.416856461155575]
21+
]
2022
]
2123
]
2224
}

packages/turf-hex-grid/test/out/properties.geojson

+9-7
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,17 @@
292292
"fill-opacity": 0
293293
},
294294
"geometry": {
295-
"type": "Polygon",
295+
"type": "MultiPolygon",
296296
"coordinates": [
297297
[
298-
[2.223186492919922, 41.416856461155575],
299-
[2.1716880798339844, 41.44182560856202],
300-
[2.1636199951171875, 41.41608406639095],
301-
[2.1334075927734375, 41.407200866420744],
302-
[2.1845626831054683, 41.37977115211044],
303-
[2.223186492919922, 41.416856461155575]
298+
[
299+
[2.223186492919922, 41.416856461155575],
300+
[2.1716880798339844, 41.44182560856202],
301+
[2.1636199951171875, 41.41608406639095],
302+
[2.1334075927734375, 41.407200866420744],
303+
[2.1845626831054683, 41.37977115211044],
304+
[2.223186492919922, 41.416856461155575]
305+
]
304306
]
305307
]
306308
}

0 commit comments

Comments
 (0)