line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package GIS::Distance::Haversine; |
2
|
1
|
|
|
1
|
|
19
|
use 5.008001; |
|
1
|
|
|
|
|
3
|
|
3
|
1
|
|
|
1
|
|
6
|
use strictures 2; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
35
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.19'; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
185
|
use parent 'GIS::Distance::Formula'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
58
|
use Math::Trig qw( deg2rad ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
9
|
1
|
|
|
1
|
|
5
|
use GIS::Distance::Constants qw( :all ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
110
|
|
10
|
1
|
|
|
1
|
|
7
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _distance { |
13
|
5
|
|
|
5
|
|
11
|
my ($lat1, $lon1, $lat2, $lon2) = @_; |
14
|
|
|
|
|
|
|
|
15
|
5
|
|
|
|
|
15
|
$lon1 = deg2rad($lon1); |
16
|
5
|
|
|
|
|
47
|
$lat1 = deg2rad($lat1); |
17
|
5
|
|
|
|
|
35
|
$lon2 = deg2rad($lon2); |
18
|
5
|
|
|
|
|
34
|
$lat2 = deg2rad($lat2); |
19
|
|
|
|
|
|
|
|
20
|
5
|
|
|
|
|
30
|
my $dlon = $lon2 - $lon1; |
21
|
5
|
|
|
|
|
6
|
my $dlat = $lat2 - $lat1; |
22
|
5
|
|
|
|
|
21
|
my $a = (sin($dlat/2)) ** 2 + cos($lat1) * cos($lat2) * (sin($dlon/2)) ** 2; |
23
|
5
|
|
|
|
|
16
|
my $c = 2 * atan2(sqrt($a), sqrt(abs(1-$a))); |
24
|
|
|
|
|
|
|
|
25
|
5
|
|
|
|
|
18
|
return $KILOMETER_RHO * $c; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Eric Samuelson recommended this formula. |
29
|
|
|
|
|
|
|
# http://forums.devshed.com/t54655/sc3d021a264676b9b440ea7cbe1f775a1.html |
30
|
|
|
|
|
|
|
# http://williams.best.vwh.net/avform.htm |
31
|
|
|
|
|
|
|
# It seems to produce the same results at the hsin formula, so... |
32
|
|
|
|
|
|
|
# |
33
|
|
|
|
|
|
|
# my $dlon = $lon2 - $lon1; |
34
|
|
|
|
|
|
|
# my $dlat = $lat2 - $lat1; |
35
|
|
|
|
|
|
|
# my $a = (sin($dlat / 2)) ** 2 |
36
|
|
|
|
|
|
|
# + cos($lat1) * cos($lat2) * (sin($dlon / 2)) ** 2; |
37
|
|
|
|
|
|
|
# $c = 2 * atan2(sqrt($a), sqrt(1 - $a)); |
38
|
|
|
|
|
|
|
# |
39
|
|
|
|
|
|
|
# Maybe test for speed before tossing? |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
__END__ |