All Products
Search
Document Center

PolarDB:ST_AsH3Grid

Last Updated:Feb 29, 2024

This topic describes the ST_AsH3Grid function. This function converts a 2D geometry object into an H3 grid representation.

Syntax

h3grid[] ST_AsH3Grid(geometry geom, integer precision, bool degenerated default false);

Parameters

Parameter

Description

geom

The geometry object.

precision

The precision level. Valid values: 0 to 15.

degenerated

Specifies whether to use a degenerated grid.

Description

  • Degenerated grids work in the same way as H3.

  • The SRID can be any projection. This function automatically converts the projection.

Examples

-- POINT
select ST_AsH3Grid(st_geomfromtext('POINT(2932234 234234)',28992),4);

st_ash3grid
--------------------------
{010101FFFFFFFF09D54208}

--LINESTRING
select st_ash3grid('SRID=4326;LINESTRING(122.48077 51.72814,122.47416 51.73714)'::geometry, 10);

st_ash3grid
--------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------
-----------------------------------
{010100FFFF59698658A108,010100FF7F58698658A108,010100FFFF5A698658A108,010100FF7F51698658A108,010100FF7F50698658A108,010100FF7F52698658A108,010100FF7FCD698658A108,010100FF7FCF698658A108,010100FF7FCE698658A108,010100FFFFC0698658A108,010100FF7FC7698658A108,010100FFFFD5698658A108}
(1 row)

-- MULTIPOLYGON
SELECT ST_AsH3Grid('SRID=4326;MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(2 2,2 5,5 5,5 2,2 2))) '::geometry, 2);

st_ash3grid
--------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------
-----
 {010100FFFFFFFF7F882508,010100FFFFFFFF7F2C2808,010100FFFFFFFF7F2D2808,010100FFFFFFFF7F8B2508,010100FFFFFFFF7F2F2808,010100FFFFFFFF7F8D2508,010100FFFFFFFF7F892508,010100FFFFFFFF7F8F2508,010100FFFFFFFF7F542708,010100FFFFFFFF7F572708,010100FFFFFFFFFF882508,010100FFFFFFFFFF892508,010100FFFFFFFFFF2D2808,010100FFFFFFFFFF2E2808,010100FFFFFFFFFF8A2508,010100FFFFFFFFFF5708}
(1 row)