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 Spatial Indexes section of this documentation.
S2_BOUNDARY
S2_BOUNDARY(id)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:BIGINTS2 cell ID to get the boundary geography from.
Return type
GEOGRAPHY
Example
SELECT CARTO.CARTO.S2_BOUNDARY(955378847514099712);
-- { "coordinates": [ [ [ -3.743508991266907, 40.24850114133136 ], [ -3.743508991266907, 40.57421345060903 ] ...S2_FROMGEOGPOINT
S2_FROMGEOGPOINT(point, resolution)Description
Returns the S2 cell ID of a given point at a requested resolution.
point:GEOGRAPHYpoint to get the ID from.resolution:INTlevel of detail or zoom.
Return type
BIGINT
Example
SELECT CARTO.CARTO.S2_FROMGEOGPOINT(ST_POINT(-3.7038, 40.4168), 8);
-- 955378847514099712S2_FROMHILBERTQUADKEY
S2_FROMHILBERTQUADKEY(hquadkey)Description
Returns the conversion of a Hilbert quadkey (a.k.a Hilbert curve quadtree ID) into a S2 cell ID.
hquadkey:STRINGHilbert quadkey to be converted.
Return type
BIGINT
Example
SELECT CARTO.CARTO.S2_FROMHILBERTQUADKEY('0/12220101');
-- 955378847514099712S2_FROMLONGLAT
S2_FROMLONGLAT(longitude, latitude, resolution)Description
Returns the S2 cell ID for a given longitude, latitude and zoom resolution.
longitude:DOUBLEhorizontal coordinate on the map.latitude:DOUBLEvertical coordinate on the map.resolution:INTlevel of detail or zoom.
Return type
BIGINT
Example
SELECT CARTO.CARTO.S2_FROMLONGLAT(-3.7038, 40.4168, 8);
-- 955378847514099712S2_TOHILBERTQUADKEY
S2_TOHILBERTQUADKEY(id)Description
Returns the conversion of a S2 cell ID into a Hilbert quadkey (a.k.a Hilbert curve quadtree ID).
id:BIGINTS2 cell ID to be converted.
Return type
STRING
Example
SELECT CARTO.CARTO.S2_TOHILBERTQUADKEY(955378847514099712);
-- 0/12220101Last updated
Was this helpful?
