Analytics Toolbox for Snowflake

Analytics Toolbox for Snowflake

s2

Our S2 module is based on a port of the official s2 geometry library created by Google. For more information about S2 check the library’s website or the Overview section of this documentation.

HILBERTQUADKEY_FROMID

Description

Returns the conversion of a S2 cell ID into a Hilbert quadkey (a.k.a Hilbert curve quadtree ID).

  • id: BIGINT S2 cell ID to be converted.

Return type

STRING

Example

1
2
SELECT sfcarto.s2.HILBERTQUADKEY_FROMID(1735346007979327488);
-- 0/30002221

ID_FROMHILBERTQUADKEY

Description

Returns the conversion of a Hilbert quadkey (a.k.a Hilbert curve quadtree ID) into a S2 cell ID.

  • hquadkey: STRING Hilbert quadkey to be converted.

Return type

BIGINT

Example

1
2
SELECT sfcarto.s2.ID_FROMHILBERTQUADKEY('0/30002221');
-- 1735346007979327488

LONGLAT_ASID

Description

Returns the S2 cell ID for a given longitude, latitude and zoom resolution.

  • longitude: DOUBLE horizontal coordinate on the map.
  • latitude: DOUBLE vertical coordinate on the map.
  • resolution: INT level of detail or zoom.

Return type

BIGINT

Example

1
2
SELECT sfcarto.s2.LONGLAT_ASID(40.4168, -3.7038, 8);
-- 1735346007979327488

ST_ASID

Description

Returns the S2 cell ID of a given point at a given level of detail.

  • point: GEOGRAPHY point to get the ID from.
  • resolution: INT level of detail or zoom.

Return type

BIGINT

Example

1
2
SELECT sfcarto.s2.ST_ASID(ST_POINT(40.4168, -3.7038), 8);
-- 1735346007979327488

ST_BOUNDARY

Description

Returns the boundary for a given S2 cell ID. We extract the boundary by getting the corner longitudes and latitudes, then enclose it in a GeoJSON and finally transform it into geography.

  • id: BIGINT S2 cell ID to get the boundary geography from.

Return type

GEOGRAPHY

Example

1
2
SELECT sfcarto.s2.ST_BOUNDARY(1735346007979327488);
-- { "coordinates": [ [ [ 40.30886257091771, -3.8626948530725476 ], [ 40.30886257091771, -3.6086596856604585 ] ...

VERSION

Description

Returns the current version of the s2 module.

Return type

STRING

Example

1
2
SELECT sfcarto.s2.VERSION();
-- 1.0.0