Class DistanceFunction

All Implemented Interfaces:
ADQLObject, ADQLOperand

public class DistanceFunction extends GeometryFunction
It represents the DISTANCE function of the ADQL language.

This function computes the arc length along a great circle between two points and returns a numeric value expression in degrees.

The specification (2.1) defines two versions of the DISTANCE function, one that accepts two POINT values (the only supported in 2.0), and a second that accepts four separate numeric values.

Implementation note: In this current implementation, the 2-argument form allows 2 geometries instead of 2 points. The goal is to be more generic. POINT is supposed to be the main expected type of argument, but it could also be a CENTROID (which returns a POINT). Moreover, some extension of this library might want to support DISTANCE between any type of geometries instead of just points.

If an ADQL service implementation declares support for DISTANCE, then it must implement both the two parameter and four parameter forms of the function.

Example:

An expression calculating the distance between two points of coordinates (25,-19.5) and (25.4,-20) could be written as follows:

DISTANCE(POINT(25.0, -19.5), POINT(25.4, -20.0))

, where all numeric values and the returned arc length are in degrees.

The equivalent call to the four parameter form of the function would be:

DISTANCE(25.0, -19.5, 25.4, -20.0)

The DISTANCE function may be applied to any expression that returns a geometric POINT value.

Example:

The distance between two points stored in the database could be calculated as follows:

DISTANCE(t1.base, t2.target)

, where t1.base and t2.target are references to database columns that contain POINT values.

If the geometric arguments are expressed in different coordinate systems, the DISTANCE function is responsible for converting one, or both, of the arguments into a different coordinate system. If the DISTANCE function cannot perform the required conversion then it SHOULD throw an error. Details of the mechanism for reporting the error condition are implementation dependent.

It is assumed that the arguments for the four numeric parameter form all use the same coordinate system.