ClickHouse function reference
geoToS2
Converts geographical coordinates to an S2 cell index. Syntax:lon
(Float64
): Longitude of the point.lat
(Float64
): Latitude of the point.
- S2 cell index (
UInt64
).
S2 is a hierarchical geocoding system that represents the Earth’s surface as a hierarchy of cells. It’s useful for spatial indexing and querying in geographical applications.
s2ToGeo
Converts an S2 cell index to geographic coordinates (longitude, latitude). Syntax:s2Index
(UInt64
): The S2 cell index to convert.
Float64
values:
- Longitude
- Latitude
The S2 indexing system is used for efficient geospatial indexing and querying. It’s particularly useful for location-based services and geospatial analysis in ClickHouse.
s2GetNeighbors
Returns the S2 neighbor indexes corresponding to the provided S2 index. Each cell in the S2 system is a quadrilateral bounded by four geodesics, so each cell has 4 neighbors. Syntax:s2index
(UInt64
): The S2 index for which to find neighbors.
[s2index1, s2index2, s2index3, s2index4]
(Array(UInt64)
).
Example:
The order of the returned neighbors is consistent but not guaranteed to be in any particular orientation relative to the input cell.
s2CellsIntersect
Determines if two S2 cells intersect. Syntax:s2Index1
(UInt64
): The first S2 cell index.s2Index2
(UInt64
): The second S2 cell index.
1
if the cells intersect,0
otherwise. [UInt8
]
0
indicates that the cells don’t intersect, suggesting the taco truck is not within the specified area.
This function is useful for efficient geospatial queries, such as determining if two areas on Earth overlap or are adjacent.
s2CapContains
Determines if a spherical cap contains a given S2 point. Syntax:center
(UInt64
): S2 point index representing the center of the cap.degrees
(Float64
): Radius of the cap in degrees.point
(UInt64
): S2 point index to check for containment.
1
if the cap contains the S2 point. [UInt8
]0
if the cap does not contain the S2 point. [UInt8
]
1
indicates that the point is indeed within the specified cap.
The S2 geometry system represents geographical points as 64-bit integers. Use the
geoToS2
function to convert latitude and longitude to S2 point indexes.s2CapUnion
Determines the smallest cap that contains the given two input caps. A cap represents a portion of the sphere that has been cut off by a plane. It is defined by a point on a sphere and a radius in degrees. Syntax:center1
,center2
(UInt64
): S2 point indexes corresponding to the two input caps.radius1
,radius2
(Float64
): Radius of the two input caps in degrees.
center
(UInt64
): S2 point index corresponding to the center of the smallest cap containing the two input caps.radius
(Float64
): Radius of the smallest cap containing the two input caps.
s2RectAdd
Increases the size of a bounding rectangle to include a given S2 point. Syntax:s2PointLow
(UInt64
): Low S2 point index of the rectangle.s2PointHigh
(UInt64
): High S2 point index of the rectangle.s2Point
(UInt64
): Target S2 point index to include in the rectangle.
UInt64
values:
- Low S2 cell id of the expanded rectangle.
- High S2 cell id of the expanded rectangle.
The S2 cell ids returned by this function can be converted back to geographic coordinates using the
s2ToGeo
function if needed.s2RectContains
Determines if a given rectangle contains an S2 point. In the S2 system, a rectangle is represented by a type of S2Region called an S2LatLngRect that represents a rectangle in latitude-longitude space. Syntax:s2PointLow
(UInt64
): Low S2 point index corresponding to the rectangle.s2PointHigh
(UInt64
): High S2 point index corresponding to the rectangle.s2Point
(UInt64
): Target S2 point index to check for containment.
1
if the rectangle contains the given S2 point.0
if the rectangle doesn’t contain the given S2 point.
0
indicates that the taco truck is not within this “fast-casual Mexican food” rectangle.
This function is useful for efficient geospatial queries, such as determining if a point of interest falls within a specific geographical area defined by two corner points.
s2RectUnion
Returns the smallest rectangle containing the union of two given rectangles in the S2 coordinate system. Syntax:s2Rect1PointLow
,s2Rect1PointHi
(UInt64
): Low and High S2 point indexes corresponding to the first rectangle.s2Rect2PointLow
,s2Rect2PointHi
(UInt64
): Low and High S2 point indexes corresponding to the second rectangle.
- A tuple containing two
UInt64
values:s2UnionRect2PointLow
— Low S2 cell id corresponding to the union rectangle.s2UnionRect2PointHi
— High S2 cell id corresponding to the union rectangle.
In the S2 system, a rectangle is represented by a type of S2Region called an S2LatLngRect, which represents a rectangle in latitude-longitude space.
s2RectIntersection
Returns the smallest rectangle containing the intersection of two given rectangles in the S2 coordinate system. Syntax:s2Rect1PointLow
,s2Rect1PointHi
(UInt64
): Low and High S2 point indexes corresponding to the first rectangle.s2Rect2PointLow
,s2Rect2PointHi
(UInt64
): Low and High S2 point indexes corresponding to the second rectangle.
- A tuple containing two
UInt64
values:- Low S2 cell id corresponding to the intersection rectangle.
- High S2 cell id corresponding to the intersection rectangle.
In the S2 system, a rectangle is represented by a type of S2Region called S2LatLngRect, which represents a rectangle in latitude-longitude space.