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:INT64S2 cell ID to get the boundary geography from.
Return type
GEOGRAPHY
Example
SELECT `carto-un`.carto.S2_BOUNDARY(955378847514099712);
-- POLYGON((-3.41955272426037 40.25850071217, -3.41955272426037 ...SELECT `carto-un-eu`.carto.S2_BOUNDARY(955378847514099712);
-- POLYGON((-3.41955272426037 40.25850071217, -3.41955272426037 ...SELECT carto.S2_BOUNDARY(955378847514099712);
-- POLYGON((-3.41955272426037 40.25850071217, -3.41955272426037 ...S2_CENTER
S2_CENTER(id)Description
Returns a POINT corresponding to the centroid of an S2 cell, given its ID.
id:INT64S2 cell ID to get the boundary geography from.
Return type
GEOGRAPHY
Example
S2_FROMGEOGPOINT
Description
Returns the S2 cell ID of a given point at a requested resolution.
point:GEOGRAPHYpoint to get the ID from.resolution:INT64level of detail or zoom.
Return type
INT64
Example
S2_FROMHILBERTQUADKEY
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
INT64
Example
S2_FROMLONGLAT
Description
Returns the S2 cell ID for a given longitude, latitude and zoom resolution.
longitude:FLOAT64horizontal coordinate on the map.latitude:FLOAT64vertical coordinate on the map.resolution:INT64level of detail or zoom.
Return type
INT64
Example
S2_FROMTOKEN
Description
Returns the conversion of a token into a S2 cell ID.
token:STRINGS2 cell hexified ID.
Return type
INT64
Example
S2_FROMUINT64REPR
Description
Returns the cell ID from a UINT64 representation.
uid:STRINGUINT64 representation of a S2 cell ID.
Return type
INT64
Example
S2_RESOLUTION
Description
Returns the S2 cell resolution as an integer.
index:STRINGThe S2 cell index.
Return type
INT64
Example
S2_TOCHILDREN
Description
Returns an array with the S2 indexes of the children/descendents of the given hexagon at the given resolution.
index:STRINGThe S2 cell index.resolution:INT64number between 0 and 30 with the S2 resolution.
Return type
ARRAY<STRING>
Example
S2_TOHILBERTQUADKEY
Description
Returns the conversion of a S2 cell ID into a Hilbert quadkey (a.k.a Hilbert curve quadtree ID).
id:INT64S2 cell ID to be converted.
Return type
STRING
Example
S2_TOTOKEN
Description
Returns the conversion of a S2 cell ID into a token (S2 cell hexified ID).
id:INT64S2 cell ID.
Return type
STRING
Example
S2_TOUINT64REPR
Description
Returns the UINT64 representation of a cell ID.
id:INT64S2 cell ID.
Return type
STRING
Example
This project has received funding from the European Union’s Horizon 2020 research and innovation programme under grant agreement No 960401.
Last updated
Was this helpful?
