line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::Coordinates::Parser; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
23536
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
7
|
1
|
|
|
1
|
|
858
|
use Geo::Coordinates::DecimalDegrees qw(dms2decimal dm2decimal); |
|
1
|
|
|
|
|
417
|
|
|
1
|
|
|
|
|
418
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=pod |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Geo::Coordinates::Parser - A coordinate parser class. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use Geo::Coordinates::Parser; |
18
|
|
|
|
|
|
|
my $coordinateparser = Geo::Coordinates::Parser->new('.'); |
19
|
|
|
|
|
|
|
my $decimaldegree = $coordinateparser->parse(q{E25°42'60"}); |
20
|
|
|
|
|
|
|
$decimaldegree = $coordinateparser->parse(q{E25.12346"}); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
This module provides a method for parsing a coordinate string. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 METHODS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
This module provides the following methods: |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=over 4 |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=item new($decimal_delimiter) |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Returns a new Geo::Coordinates::Parser object. The decimal |
37
|
|
|
|
|
|
|
delimiter can be given as an argument. If no argument is |
38
|
|
|
|
|
|
|
given then period "." character is used as decimal delimiter. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Usage: |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $coordinateparser = Geo::Coordinates::Parser->new(); # or |
43
|
|
|
|
|
|
|
my $coordinateparser = Geo::Coordinates::Parser->new('.'); # same as above, or |
44
|
|
|
|
|
|
|
my $coordinateparser = Geo::Coordinates::Parser->new(','); # , is the decimal delimiter |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
sub new { |
48
|
2
|
|
|
2
|
1
|
13
|
my $class = shift; |
49
|
2
|
|
100
|
|
|
11
|
my $decimal_delimiter = shift || '.'; |
50
|
2
|
|
|
|
|
6
|
my $self = {'decimal_delimiter' => $decimal_delimiter}; |
51
|
2
|
|
|
|
|
5
|
bless($self, $class); |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
6
|
return $self; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=pod |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item parse($coordinatestring) |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Parses the coordinate string and returns it's decimal value. |
61
|
|
|
|
|
|
|
It uses L to turn degrees, |
62
|
|
|
|
|
|
|
minutes and seconds into the equivalent decimal degree. The |
63
|
|
|
|
|
|
|
argument can be either a longitude or a latitude. It doesn't |
64
|
|
|
|
|
|
|
test the sanity of the data. The method simply removes all |
65
|
|
|
|
|
|
|
unnecessary characters and then converts the degrees, |
66
|
|
|
|
|
|
|
minutes and seconds to a decimal degree. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Usage: |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $decimal = $coordinateparser->parse('E25'42'60'); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
sub parse { |
74
|
10
|
|
|
10
|
1
|
2664
|
my $self = shift; |
75
|
10
|
|
|
|
|
15
|
my $coordinatestring = shift; |
76
|
10
|
100
|
|
|
|
26
|
unless ($coordinatestring) { |
77
|
2
|
|
|
|
|
10
|
return undef; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Remove all extra |
81
|
8
|
|
|
|
|
54
|
my $decimal_delimiter = $self->decimal_delimiter; |
82
|
8
|
|
|
|
|
91
|
$coordinatestring =~ s/[^0-9$decimal_delimiter]/ /g; |
83
|
8
|
|
|
|
|
24
|
$coordinatestring =~ s/^\s+//; |
84
|
8
|
|
|
|
|
19
|
$coordinatestring =~ s/\s+$//; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# Split into degrees, minutes and seconds |
87
|
8
|
|
|
|
|
25
|
my ($degrees, $minutes, $seconds) = split(/\s+/, $coordinatestring); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# Return in decimal format with the right delimiter |
90
|
8
|
100
|
100
|
|
|
53
|
if ($minutes and $seconds) { |
|
|
100
|
66
|
|
|
|
|
91
|
3
|
|
|
|
|
11
|
return dms2decimal($degrees, $minutes, $seconds); |
92
|
|
|
|
|
|
|
} elsif ($minutes and not $seconds) { |
93
|
3
|
|
|
|
|
9
|
return dm2decimal($degrees, $minutes); |
94
|
|
|
|
|
|
|
} else { |
95
|
2
|
|
|
|
|
9
|
return $degrees; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=pod |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item decimal_delimiter($decimal_delimiter) |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Returns the decimal delimiter. If an argument is given then |
104
|
|
|
|
|
|
|
it's sets the delimiter to the given value. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Usage: |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
$coordinateparser->decimal_delimiter; # Returns the delimiter |
109
|
|
|
|
|
|
|
$coordinateparser->decimal_delimiter(','); # Sets and returns , as the delimiter |
110
|
|
|
|
|
|
|
$coordinateparser->decimal_delimiter; # Returns now , as the delimiter |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
113
|
|
|
|
|
|
|
sub decimal_delimiter { |
114
|
12
|
|
|
12
|
1
|
2209
|
my $self = shift; |
115
|
12
|
|
|
|
|
14
|
my $decimal_delimiter = shift; |
116
|
12
|
100
|
|
|
|
29
|
if ($decimal_delimiter) { |
117
|
2
|
|
|
|
|
3
|
$self->{'decimal_delimiter'} = $decimal_delimiter; |
118
|
|
|
|
|
|
|
} |
119
|
12
|
|
|
|
|
40
|
return $self->{'decimal_delimiter'}; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=pod |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=back |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 REQUIRES |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
L |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 SEE ALSO |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
L |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 AUTHOR |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Carl Räihä, |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Copyright 2005 by Carl Räihä / Frantic Media |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
149
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |