Categories:

Geospatial functions

H3_POLYGON_TO_CELLS

Returns an array of INTEGER values of the IDs of H3 cells that have centroids contained by a Polygon (specified by a GEOGRAPHY object).

See also:

H3_POLYGON_TO_CELLS_STRINGS , H3_COVERAGE

语法

H3_POLYGON_TO_CELLS( <geography_polygon> , <target_resolution> )

实参

geography_polygon

表示多边形的 GEOGRAPHY 对象。

target_resolution

An INTEGER between 0 and 15 (inclusive) that specifies the H3 resolution (https://h3geo.org/docs/core-library/restable) that you want to use for the returned H3 cells.

指定其他任何 INTEGER 值都会导致错误。

返回

返回 H3 单元格的 IDs 的 INTEGER 值数组,H3 单元格的质心包含在指定的输入多边形内。

使用说明

  • The function uses planar approximation, which treats points on the Earth’s surface as if they were connected by straight lines, rather than curved arcs. If you need a spherical approximation, use H3_COVERAGE instead.
  • 如果单元格的质心包含在多边形内,则认为该单元格位于多边形内。
  • When you apply FLATTEN to the array returned by the function, cast each value explicitly to an integer.

示例

以下示例返回 H3 单元格 IDs 的 ARRAY,H3 单元格的质心包含在指定的多边形中。

SELECT H3_POLYGON_TO_CELLS(
  TO_GEOGRAPHY(
    'POLYGON((-122.481889 37.826683,-122.479487 37.808548,-122.474150 37.808904,-122.476510 37.826935,-122.481889 37.826683))'
  ),
  9) AS h3_cells_in_polygon;
+-----------------------+
| H3_CELLS_IN_POLYGON   |
%-----------------------%
| [                     |
|   617700171176476671, |
|   617700171168874495, |
|   617700171177525247, |
|   617700171167563775, |
|   617700171225497599, |
|   617700171188011007, |
|   617700171168350207, |
|   617700171168612351, |
|   617700171167825919  |
| ]                     |
+-----------------------+