Skip to content

Commit 61fba3d

Browse files
authoredJan 27, 2025··
add docs for polygonToCellsExperimental (#959)
* add docs for polygonToCellsExperimental * remove * python flags * update for uber/h3-py#436
1 parent f5f5ab4 commit 61fba3d

File tree

1 file changed

+177
-0
lines changed

1 file changed

+177
-0
lines changed
 

‎website/docs/api/regions.mdx

+177
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,183 @@ $ h3 maxPolygonToCellsSize -r 7 -p "[[37.813318999983238, -122.4089866999972145]
182182
</TabItem>
183183
</Tabs>
184184

185+
## polygonToCellsExperimental
186+
187+
Each binding's version of `polygonToCellsExperimental` takes as input a
188+
GeoJSON-like data structure describing a polygon (i.e., an outer ring and
189+
optional holes) and a target cell resolution.
190+
It produces a collection of cells that are contained within the polygon.
191+
192+
This function differs from `polygonToCells` in that it uses an experimental
193+
new algorithm which supports center-based, fully-contained, and
194+
overlapping containment modes.
195+
196+
<Tabs
197+
groupId="language"
198+
defaultValue="c"
199+
values={[
200+
{label: 'C', value: 'c'},
201+
{label: 'Java', value: 'java'},
202+
{label: 'JavaScript (Live)', value: 'javascript'},
203+
{label: 'Python', value: 'python'},
204+
{label: 'Shell', value: 'shell'},
205+
]
206+
}>
207+
<TabItem value="c">
208+
209+
```c
210+
H3Error polygonToCellsExperimental(const GeoPolygon *geoPolygon, int res, uint32_t flags, int64_t size, H3Index *out);
211+
```
212+
213+
In C, `polygonToCellsExperimental` takes a `GeoPolygon` struct and preallocated,
214+
zeroed memory, and fills it with the covering cells.
215+
216+
`size` should be the size in number of `H3Index`s of `out`.
217+
218+
The valid values for `flags` are:
219+
220+
| Enum name | Integer value | Description
221+
| --------- | ------------- | -----------
222+
| `CONTAINMENT_CENTER` | 0 | Cell center is contained in the shape
223+
| `CONTAINMENT_FULL` | 1 | Cell is fully contained in the shape
224+
| `CONTAINMENT_OVERLAPPING` | 2 | Cell overlaps the shape at any point
225+
| `CONTAINMENT_OVERLAPPING_BBOX` | 3 | Cell bounding box overlaps shape
226+
227+
Returns 0 (`E_SUCCESS`) on success.
228+
229+
</TabItem>
230+
<TabItem value="java">
231+
232+
```java
233+
List<Long> polygonToCellsExperimental(List<LatLng> points, List<List<LatLng>> holes, PolygonToCellsFlags flags, int res);
234+
List<String> polygonToCellExperimentalAddresses(List<LatLng> points, List<List<LatLng>> holes, PolygonToCellsFlags flags, int res);
235+
```
236+
237+
The valid values for `flags` are:
238+
239+
| Enum name | Description
240+
| --------- | -----------
241+
| `PolygonToCellsFlags.containment_center` | Cell center is contained in the shape
242+
| `PolygonToCellsFlags.containment_full` | Cell is fully contained in the shape
243+
| `PolygonToCellsFlags.containment_overlapping` | Cell overlaps the shape at any point
244+
| `PolygonToCellsFlags.containment_overlapping_bbox` | Cell bounding box overlaps shape
245+
246+
</TabItem>
247+
<TabItem value="javascript">
248+
249+
```js
250+
h3.polygonToCellsExperimental(polygon, res, flags, isGeoJson)
251+
```
252+
253+
```js live
254+
function example() {
255+
const polygon = [
256+
[37.813318999983238, -122.4089866999972145],
257+
[37.7198061999978478, -122.3544736999993603],
258+
[37.8151571999998453, -122.4798767000009008]
259+
];
260+
const res = 7;
261+
return h3.polygonToCellsExperimental(polygon, h3.POLYGON_TO_CELLS_FLAGS.containmentOverlapping, res);
262+
}
263+
```
264+
265+
The valid values for `flags` are:
266+
267+
| Enum name | Description
268+
| --------- | -----------
269+
| `POLYGON_TO_CELLS_FLAGS.containment_center` | Cell center is contained in the shape
270+
| `POLYGON_TO_CELLS_FLAGS.containment_full` | Cell is fully contained in the shape
271+
| `POLYGON_TO_CELLS_FLAGS.containment_overlapping` | Cell overlaps the shape at any point
272+
| `POLYGON_TO_CELLS_FLAGS.containment_overlapping_bbox` | Cell bounding box overlaps shape
273+
274+
</TabItem>
275+
<TabItem value="python">
276+
277+
```py
278+
h3.h3shape_to_cells_experimental(h3shape, res, contain='overlap')
279+
```
280+
281+
In Python, `h3shape_to_cells_experimental` takes an `H3Shape` object
282+
(`LatLngPoly` or `LatLngMultiPoly`).
283+
For more info, see the [`h3-py` docs](https://uber.github.io/h3-py/api_quick.html#polygon-interface).
284+
285+
The valid values for `contain` are:
286+
287+
| String value | Description
288+
| ------------ | -----------
289+
| `center` | Cell center is contained in the shape (default)
290+
| `full` | Cell is fully contained in the shape
291+
| `overlap` | Cell overlaps the shape at any point
292+
| `bbox_overlap` | Cell bounding box overlaps shape
293+
294+
</TabItem>
295+
<TabItem value="shell">
296+
297+
This function is not exposed in the CLI bindings.
298+
299+
</TabItem>
300+
</Tabs>
301+
302+
303+
## maxPolygonToCellsExperimentalSize
304+
305+
Provides an upper bound on the number of cells needed for memory allocation
306+
purposes when computing `polygonToCellsExperimental` on the given GeoJSON-like data structure.
307+
308+
<Tabs
309+
groupId="language"
310+
defaultValue="c"
311+
values={[
312+
{label: 'C', value: 'c'},
313+
{label: 'Java', value: 'java'},
314+
{label: 'JavaScript (Live)', value: 'javascript'},
315+
{label: 'Python', value: 'python'},
316+
{label: 'Shell', value: 'shell'},
317+
]
318+
}>
319+
<TabItem value="c">
320+
321+
```c
322+
H3Error maxPolygonToCellsExperimentalSize(const GeoPolygon *geoPolygon, int res, uint32_t flags, int64_t *out);
323+
```
324+
325+
Returns 0 (`E_SUCCESS`) on success.
326+
327+
</TabItem>
328+
<TabItem value="java">
329+
330+
:::note
331+
332+
This function exists for memory management and is not exposed.
333+
334+
:::
335+
336+
</TabItem>
337+
<TabItem value="javascript">
338+
339+
:::note
340+
341+
This function exists for memory management and is not exposed.
342+
343+
:::
344+
345+
</TabItem>
346+
<TabItem value="python">
347+
348+
:::note
349+
350+
This function exists for memory management and is not exposed.
351+
352+
:::
353+
354+
</TabItem>
355+
<TabItem value="shell">
356+
357+
This function is not exposed in the CLI bindings.
358+
359+
</TabItem>
360+
</Tabs>
361+
185362
186363
## cellsToLinkedMultiPolygon / cellsToMultiPolygon
187364

0 commit comments

Comments
 (0)
Please sign in to comment.