Spatial Queries
part 3

SQL Extended Stored Procedures

A complete list of HTM related functions follows:

fHtmXyz

fHtmXyz(x,y,z) returns the level 20 HtmID of the given cartesian point. There are no error cases. All vectors are nomalized and (0,0,0) maps to (1,0,0)

 declare @HtmID bigint
 select @HtmID = dbo.fHtmXyz(1,0,0)

fHtmEq

fHtmEq(ra, dec) returns the level 20 HtmID of the given equatorial point. There are no error cases. all RA, folded to [0...360] and dec to [-90...90]

 declare @HtmID bigint
 select @HtmID = dbo.fHtmEq(0, 0)

fHtmToString

fHtmToString(HtmID) returns varchar(max)a string describing the HtmID

print dbo.fHtmToString(dbo.fHtmXyz(1,0,0))

fHtmToCenterPoint

fHtmToCenterPoint(HtmID) converts an HTM triangle ID to an (x,y,z) vector of the HTM triangle centerpoint. and returns that vector as the only row of a table.

select * from  fHtmToCenterPoint(dbo.fHtmXyz(.57735,.57735,.57735))


x                      y                      z
---------------------- ---------------------- ----------------------
0.577350269189626      0.577350269189626      0.577350269189626
(1 row(s) affected) 

fHtmToCornerPoints

fHtmToCornerPoints(HtmID) converts an HTM triangle ID to an table of three (x,y,z) vectors of the HTM triangle corners.

select * from  fHtmTovertices(8)
x                      y                      z
---------------------- ---------------------- ----------------------
1                      0                      0
0                      0                      -1
0                      1                      0

(3 row(s) affected)

fHtmCoverCircleEq

fHtmCoverCircleEq(ra,dec,radiusArcMin) returns a HtmID range table covering the circle centered at that J2000 ra,dec, within that arc-minute radius. The table is a list of HtmIDStart,HtmIDEnd pairs that describe the level 20 HTM triangles.

select * from fHtmCoverCircleEq(0,0,1)
HtmIDStart HtmIDEnd -------------------- -------------------- 8796093022208 8796093087743 8796093239296 8796093243391 8796093259776 8796093263871 8796093267968 8796093272063 12644383719424 12644383784959 12644383936512 12644383940607 12644383956992 12644383961087 12644383965184 12644383969279 13194139533312 13194139598847 13194139750400 13194139754495 13194139770880 13194139774975 13194139779072 13194139783167 17042430230528 17042430296063 17042430447616 17042430451711 17042430468096 17042430472191 17042430476288 17042430480383 (16 row(s) affected)

fHtmCoverCircleXyz

fHtmCoverCircleXyz(x, y, z,radiusArcMin) returns a trixel table (a list) covering the circle centered at that Cartesian coordinate, within that arc-minute radius. The table is a list of HtmIDStart,HtmIDEnd pairs that describe the level 20 HTM triangles.

select * from fHtmCoverCircleEq(1,0,0,1)
HtmIDStart HtmIDEnd -------------------- -------------------- 8796093022208 8796093087743 8796093239296 8796093243391 8796093259776 8796093263871 8796093267968 8796093272063 12644383719424 12644383784959 12644383936512 12644383940607 12644383956992 12644383961087 12644383965184 12644383969279 13194139533312 13194139598847 13194139750400 13194139754495 13194139770880 13194139774975 13194139779072 13194139783167 17042430230528 17042430296063 17042430447616 17042430451711 17042430468096 17042430472191 17042430476288 17042430480383 (16 row(s) affected)

fHtmCoverList

fHtmCoverList(coverspec) returns a list of HtmID's of trixels that cover the region.

select * from fHtmCoverList('CONVEX J2000 0 90 0') -- the Northern hemisphere
HtmID -------------------- 12 13 14 15 (4 row(s) affected)

fHtmCoverRegionSelect

fHtmCoverRegionSelect(regionspec) returns a the qualified list of HtmIDStart,HtmIDEnd pairs that describe the level 20 trixels covering the region. The qualifier is 'partial', 'full' or 'outer'.

select * from fHtmCoverRegionSelect('CIRCLE J2000 195 0 1', 'full')
HtmIDStart HtmIDEnd -------------------- -------------------- 11036347957248 11036347973631 11036348088320 11036348104703 14870894755840 14870894772223 14870894821376 14870894837759 (4 row(s) affected) select * from fHtmCoverRegionSelect('CIRCLE J2000 195 0 1', 'partial')
HtmIDStart HtmIDEnd -------------------- -------------------- 11036347465728 11036347482111 11036347875328 11036347957247 11036347973632 11036347990015 11036348055552 11036348088319 11036348104704 11036348121087 11036348186624 11036348203007 14870894411776 14870894428159 14870894624768 14870894673919 14870894739456 14870894755839 14870894772224 14870894821375 14870894837760 14870894870527 14870895263744 14870895280127 (12 row(s) affected)

fHtmCoverRegion

same as fHtmCoverRegionSelect(..., 'outer')

select * from fHtmCoverRegion('CIRCLE J2000 195 0 1')
HtmIDStart HtmIDEnd -------------------- -------------------- 11036347465728 11036347482111 11036347875328 11036347990015 11036348055552 11036348121087 11036348186624 11036348203007 14870894411776 14870894428159 14870894624768 14870894673919 14870894739456 14870894870527 14870895263744 14870895280127 (8 row(s) affected)

fHtmRegionToNormalForm

converts a region definiton to normal form

select dbo.fHtmRegionToNormalFormString('CIRCLE J2000 195 0 1')
-------------------------------------------------------------------------
REGION CONVEX CARTESIAN   -0.965925826289068   -0.258819045102521    0.000000000000000    0.999999957692025 

(1 row(s) affected)

fHtmRegionToError

returns diagnostic message appropriate for a bad region string or "OK" if there are no errors

select dbo.fHtmRegionError('CIRCLE J2000 5 0 1')
------------------------------------------------------------------ OK (1 row(s) affected) select dbo.fHtmRegionError('CIRCLE FOOBAR 5 0 1') -------------------------------------------------------------------------- Illegal number format (1 row(s) affected)

Back ...


Last update May 29, 2007 György Fekete version 3.1.2