Converts a latitude and longitude coordinate pair to an H3Grid object at the specified resolution level.
Syntax
h3grid ST_H3FromLatLng(float lat, float lng, Integer level)Parameters
| Parameter | Type | Description |
|---|---|---|
lat | float | The latitude of the coordinate. |
lng | float | The longitude of the coordinate. |
level | Integer | The H3 resolution level. Default value: 15. |
Examples
The following examples convert the coordinate (20.5, 128.2) to an H3Grid object and return its text representation using ST_AsText.
Example 1: Use the default resolution level (15)
SELECT ST_AsText(ST_H3FromLatLng(20.5, 128.2));Output:
st_astext
-----------------
8f4a1266884c4f0Example 2: Specify a resolution level
SELECT ST_AsText(ST_H3FromLatLng(20.5, 128.2, 8));Output:
st_astext
-----------------
884a126689fffffA lower resolution level produces a larger, coarser grid cell. In Example 2, level 8 returns the cell 884a126689fffff, which covers a broader area than the level-15 cell returned in Example 1.