2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
16
Task/Haversine-formula/XQuery/haversine-formula.xquery
Normal file
16
Task/Haversine-formula/XQuery/haversine-formula.xquery
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
declare namespace xsd = "http://www.w3.org/2001/XMLSchema";
|
||||
declare namespace math = "http://www.w3.org/2005/xpath-functions/math";
|
||||
|
||||
declare function local:haversine($lat1 as xsd:float, $lon1 as xsd:float, $lat2 as xsd:float, $lon2 as xsd:float)
|
||||
as xsd:float
|
||||
{
|
||||
let $dlat := ($lat2 - $lat1) * math:pi() div 180
|
||||
let $dlon := ($lon2 - $lon1) * math:pi() div 180
|
||||
let $rlat1 := $lat1 * math:pi() div 180
|
||||
let $rlat2 := $lat2 * math:pi() div 180
|
||||
let $a := math:sin($dlat div 2) * math:sin($dlat div 2) + math:sin($dlon div 2) * math:sin($dlon div 2) * math:cos($rlat1) * math:cos($rlat2)
|
||||
let $c := 2 * math:atan2(math:sqrt($a), math:sqrt(1-$a))
|
||||
return xsd:float($c * 6371.0)
|
||||
};
|
||||
|
||||
local:haversine(36.12, -86.67, 33.94, -118.4)
|
||||
Loading…
Add table
Add a link
Reference in a new issue