FUNCTION  fHTM_Cover

Returns a table of (HtmIdStart, HtmIdEnd) that covers the area.

This is the main access function to the HTM spatial index.

The result is a record set with the schema
(HtmIdStart bigint, HtmIdEnd bigint)
The area is specified as a CIRCLE, CONVEX, or DOMAIN.
Each of these can use J2000 (ra,dec), or cartesian (xyz) coordinates.
The area parameter begins with a
[CIRCLE | CONVEX] [J2000 | CARTESIAN]
header, then it has the following params:

  • Depth is an int between 0...24, it specifies how fine a triangular mesh is desired.
  • ra is right ascencion is float64 units are degrees
  • dec is right declination is float64 units are degrees
  • rad is circle radius in arcminutes float64
  • x,y,z are coordinates in cartesian space, float64
  • d is a distance along the x, y, z vector when defining a cone (d in -1...+1).


    The following examples request a 6-deep htm list covering a
    a circular region, convex hull or a domain

    CIRCLE J2000 6 41.4 47.9 20
    CIRCLE CARTESIAN 6 1.0 0.0 0.0 10.0
    CONVEX J2000 6 41.4 47.9 41.2 47.9 41.0 47.5 41.4 48
    CONVEX CARTESIAN depth x1 y1 z1 x2 y2 z2 ... xn yn zn
    CONVEX CARTESIAN 6 1 1 1 0 1 1 1 0
    DOMAIN 1 n x1 y1 z1 d1 x2 y2 z2 d2... xn yn zn dn

    (See also fHTM_Cover_ErrorMessage)
  • NameTypeLengthinoutpnum
    @AreaVARCHAR8000input1
    HTMIDstartBIGINT8output1
    HTMIDendBIGINT8output2

    FUNCTION  fHtmLookupEq

    Returns 20-deep HTMid of a given Equatorial point (@ra,@dec).

    Sample call to get the HTMid of ra,dec 185,0

    SELECT dbo.fGetNearbyObjEq(185,0)


    NameTypeLengthinoutpnum
    @rafloat8input1
    @decfloat8input2
     bigint8output1

    FUNCTION  fGetNearbyObjEq

    Returns table of objects from @table within @r arcmins of an Equatorial point (@ra,@dec).

    There is no limit on the number of objects returned, but there are about 40 per sq arcmin.

    returned table:

  • objID bigint PRIMARY KEY, -- Photo object identifier
  • htmID bigint, -- Hierarchical Trangular Mesh id of this object
  • cx float NOT NULL, -- x,y,z of unit vector to this object
  • cy float NOT NULL,
  • cz float NOT NULL,
  • distance float -- distance in arc minutes to this object from the ra,dec.


    Sample call to find all the Galaxies within 5 arcminutes of ra,dec 185,0

    SELECT *
    FROM Galaxy AS G,
    dbo.fGetNearbyObjEq(185,0,5,1) AS N
    WHERE G.objID = N.objID

    (see also fGetNearestObjEq, fGetNearbyObjXYZ, fGetNearestObjXYZ)
  • NameTypeLengthinoutpnum
    @rafloat8input1
    @decfloat8input2
    @rfloat8input3
    @tabletinyint1input4
    objIDbigint8output1
    cxfloat8output2
    cyfloat8output3
    czfloat8output4
    htmIDbigint8output5
    distancefloat8output6

    FUNCTION  fGetNearestObjEq

    Returns table holding a record describing the closest object within @r arcminutes of (@ra,@dec).

    returned table:

  • objID bigint PRIMARY KEY, -- Photo object identifier
  • cx float NOT NULL, -- x,y,z of unit vector to this object
  • cy float NOT NULL,
  • cz float NOT NULL,
  • htmID bigint, -- Hierarchical Trangular Mesh id of this object
  • distance float -- distance in arc minutes to this object from the ra,dec.

    Sample call to find the table 1 object within 2 arcminutes of ra,dec 185

    SELECT N.*
    FROM dbo.fGetNearestObjEq(185,0,2,1)

    (see also fGetNearbyObjEq, fGetNearbyObjXYZ, fGetNearestObjXYZ)
  • NameTypeLengthinoutpnum
    @rafloat8input1
    @decfloat8input2
    @rfloat8input3
    @tabletinyint1input4
    objIDbigint8output1
    cxfloat8output2
    cyfloat8output3
    czfloat8output4
    htmIDbigint8output5
    distancefloat8output6

    FUNCTION  fGetNearestObjIdEq

    Returns the objId of nearest @table object within @r arcmins.

    This scalar function is used for matchups of external catalogs.
    It calls the fGetNearestObjEq(@ra,@dec,@r), and selects
    the objId (a bigint). This can be called by a single SELECT from an uploaded
    (ra,dec) table.

    An example:

    SELECT id, ra,dec, dbo.fGetNearestObjIdEq(ra,dec,3.0,1) AS objId
    FROM #upload
    WHERE dbo.fGetNearestObjIdEq(ra,dec,3.0,1) IS NOT NULL


    NameTypeLengthinoutpnum
    @rafloat8input1
    @decfloat8input2
    @rfloat8input3
    @tabletinyint1input4
     bigint8output1

    FUNCTION  fGreatCircleDist

    Returns float holding great circle distance between two points (ra1,dec1) & (ra2,dec2)

    The great circle distance is in arcmins, the ras and decs are in degrees.

    NameTypeLengthinoutpnum
    @ra1float8input1
    @dec1float8input2
    @ra2float8input3
    @dec2float8input4
     float8output1