ClickHouse function reference
greatCircleDistance
Calculates the distance between two points on the Earth’s surface using the great-circle formula. Syntax:lon1Deg
(Float64
): Longitude of the first point in degrees. Range: [-180°, 180°].lat1Deg
(Float64
): Latitude of the first point in degrees. Range: [-90°, 90°].lon2Deg
(Float64
): Longitude of the second point in degrees. Range: [-180°, 180°].lat2Deg
(Float64
): Latitude of the second point in degrees. Range: [-90°, 90°].
Float64
]
Exception:
Throws an exception when input parameter values fall outside the specified ranges.
Example:
While
greatCircleDistance
provides a good approximation, for more precise calculations on the Earth’s surface, consider using the geoDistance
function, which uses the WGS-84 ellipsoid model.geoDistance
Calculates the distance between two points on the Earth’s surface using the WGS-84 ellipsoid model. Syntax:lon1Deg
(Float64
): Longitude of the first point in degrees. Range: [-180°, 180°].lat1Deg
(Float64
): Latitude of the first point in degrees. Range: [-90°, 90°].lon2Deg
(Float64
): Longitude of the second point in degrees. Range: [-180°, 180°].lat2Deg
(Float64
): Latitude of the second point in degrees. Range: [-90°, 90°].
Float64
]
Exception:
Throws an exception when input parameter values fall outside the specified ranges.
- This function is more precise than
greatCircleDistance
as it uses the WGS-84 ellipsoid model instead of a sphere. - For close points, it calculates the distance using planar approximation with the metric on the tangent plane at the midpoint of the coordinates.
- The performance is the same as
greatCircleDistance
(no performance drawback).
It is recommended to use
geoDistance
over greatCircleDistance
for more accurate calculations of distances on Earth.greatCircleAngle
Calculates the central angle between two points on the Earth’s surface using the great-circle formula. Syntax:lon1Deg
(Float64
): Longitude of the first point in degrees. Range: [-180°, 180°].lat1Deg
(Float64
): Latitude of the first point in degrees. Range: [-90°, 90°].lon2Deg
(Float64
): Longitude of the second point in degrees. Range: [-180°, 180°].lat2Deg
(Float64
): Latitude of the second point in degrees. Range: [-90°, 90°].
Float64
]
Example:
The
greatCircleAngle
function is useful for calculating angular distances on a spherical model of the Earth. For more precise distance calculations that take into account the Earth’s ellipsoidal shape, consider using the geoDistance
function.pointInEllipses
Checks whether a point belongs to at least one of the specified ellipses on a 2D plane. Syntax:x, y
(Float64
): Coordinates of the point to check.xi, yi
(Float64
): Coordinates of the center of the i-th ellipse.ai, bi
(Float64
): Lengths of the semi-major and semi-minor axes of the i-th ellipse.
1
if the point is inside at least one of the ellipses, 0
otherwise. [UInt8
]
Example:
1
indicates that the point is inside at least one of the ellipses, suggesting it’s in a taco zone.
The function uses the Cartesian coordinate system. Make sure to convert geographical coordinates to an appropriate projection if working with map data.
(x, y)
(Tuple(Float64, Float64)
): Coordinates of a point on the plane.[(a, b), (c, d) ...]
(Array(Tuple(Float64, Float64))
): Polygon vertices.- Each vertex is represented by a pair of coordinates
(a, b)
. - Vertices should be specified in a clockwise or counterclockwise order.
- The minimum number of vertices is 3.
- The polygon must be constant.
- Each vertex is represented by a pair of coordinates
1
if the point is inside the polygon,0
if it is not. (UInt8
)
- If the point is on the polygon boundary, the function may return either 0 or 1.
- The function supports polygons with holes (cut out sections). Add polygons that define the cut out sections using additional arguments of the function.
- The function does not support non-simply-connected polygons.