14. DISTANCE

ADQL has a DISTANCE function to compute the spherical distance between two points:

DISTANCE(lon1, lat1, lon2, lat2)

You can also use distance with the POINT geometry, like this:

DISTANCE(POINT (lon1, lat1), POINT (lon2, lat2) )

– but this probably only makes sense if you have native POINT-s in a table.

The DISTANCE function can be used to make cone selections and is the prefered way to perform crossmatches on sky positions in ADQL 2.1.

SELECT TOP 1000
  raj2000, dej2000, parallax
  FROM arihip.main
  WHERE
    DISTANCE(raj2000, dej2000,
             189.2, 62.21) < 10

Note that there are still many TAP services out there that do not support DISTANCE or become very slow when you use it. You can always fall back to the CONTAINS/CIRCLE pattern introduced above in such cases.


Markus Demleitner, Hendrik Heinl

Copyright Notice