Skip to main content

ST_HILBERT

Introduced or updated: v1.2.885

Encodes a GEOMETRY or GEOGRAPHY object into a Hilbert curve index. The function uses the center of the geometry's bounding box as the point to encode. When bounds are provided, the point is normalized into the specified bounding box before encoding.

Syntax

ST_HILBERT(<geometry_or_geography>)
ST_HILBERT(<geometry_or_geography>, <bounds>)

Arguments

ArgumentsDescription
<geometry_or_geography>The argument must be an expression of type GEOMETRY or GEOGRAPHY.
<bounds>Optional. An array [xmin, ymin, xmax, ymax] used to normalize the point before encoding.
note
  • Geometry: If no bounding box is provided, GEOMETRY coordinates are not normalized to a specific bounding box. Instead, the center point values are mapped to the full float32 domain, and then encoded into the Hilbert index.
  • Geography: If no bounding box is provided, the default bounds are [-180, -90, 180, 90].

Return Type

UInt64.

Examples

GEOMETRY examples

SELECT ST_HILBERT(TO_GEOMETRY('POINT(1 2)')) AS hilbert1, ST_HILBERT(TO_GEOMETRY('POINT(5 5)')) AS hilbert2;

╭───────────────────────────╮
│ hilbert1 │ hilbert2 │
├─────────────┼─────────────┤
33554432002155872256
╰───────────────────────────╯

SELECT ST_HILBERT(TO_GEOMETRY('POINT(1 2)'), [0, 0, 1, 1]) AS hilbert1, ST_HILBERT(TO_GEOMETRY('POINT(5 5)'), [0, 0, 5, 5]) AS hilbert2;

╭───────────────────────────╮
│ hilbert1 │ hilbert2 │
├─────────────┼─────────────┤
28633115302863311530
╰───────────────────────────╯

GEOGRAPHY examples

SELECT ST_HILBERT(TO_GEOGRAPHY('POINT(113.15 23.06)')) AS hilbert1, ST_HILBERT(TO_GEOGRAPHY('POINT(116.25 39.54)')) AS hilbert2;

╭───────────────────────────╮
│ hilbert1 │ hilbert2 │
├─────────────┼─────────────┤
30702590603033451300
╰───────────────────────────╯

SELECT ST_HILBERT(TO_GEOGRAPHY('POINT(113.15 23.06)'), [73, 4, 135, 53]) AS hilbert1, ST_HILBERT(TO_GEOGRAPHY('POINT(116.25 39.54)'), [73, 4, 135, 53]) AS hilbert2;

╭───────────────────────────╮
│ hilbert1 │ hilbert2 │
├─────────────┼─────────────┤
35336071942330429279
╰───────────────────────────╯
Try Databend Cloud for FREE

Multimodal, object-storage-native warehouse for BI, vectors, search, and geo.

Snowflake-compatible SQL with automatic scaling.

Sign up and get $200 in credits.

Try it today