blib/lib/GPS/Point.pm

filter: Statementstmt 56.4% 114 / 202 Branchbran 40.2% 33 / 82 Conditioncond 37.3% 28 / 75 MC/DCmcdc 2.7% 1 / 36 Subroutinesub 77.1% 27 / 35 Podpod 100% 31 / 31 totaltotal 50.7% 234 / 461 CC 76 SCAR 40.6
CC
76
Cov
49%
initializeMulti
192.2
track
42.0
forward
30.0
CRAP 58.1
↑ Summary
1 package GPS::Point;
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use Scalar::Util qw{reftype};
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 our $VERSION = '0.20';
7  
8 =head1 NAME
9  
10 GPS::Point - Provides an object interface for a GPS point.
11  
12 =head1 SYNOPSIS
13  
14 use GPS::Point;
15 my $obj=GPS::Point->newGPSD($GPSD_O_line);#e.g. GPSD,O=....
16 my $obj=GPS::Point->new(
17 time => $time, #float seconds from the unix epoch
18 lat => $lat, #signed degrees
19 lon => $lon, #signed degrees
20 alt => $hae, #meters above the WGS-84 ellipsoid
21 speed => $speed, #meters/second (over ground)
22 heading => $heading, #degrees clockwise from North
23 climb => $climb, #meters/second
24 etime => $etime, #float seconds
25 ehorizontal => $ehz, #float meters
26 evertical => $evert, #float meters
27 espeed => $espeed, #meters/second
28 eheading => $ehead, #degrees
29 eclimb => $eclimb, #meters/second
30 mode => $mode, #GPS mode [?=>undef,None=>1,2D=>2,3D=>3]
31 tag => $tag, #Name of the GPS message for data
32 );
33  
34 =head1 DESCRIPTION
35  
36 This is a re-write of L<Net::GPSD::Point> with the goal of being more re-usable.
37  
38 GPS::Point - Provides an object interface for a GPS fix (e.g. Position, Velocity and Time).
39  
40 Note: Please use Geo::Point, if you want 2D or projection support.
41  
42 =head1 USAGE
43  
44 print scalar($point->latlon), "\n"; #latlon in scalar context
45 my ($x,$y,$z)=$point->ecef; #if Geo::ECEF is available
46 my $GeoPointObject=$point->GeoPoint; #if Geo::Point is available
47 my @distance=$point->distance($point2); #if Geo::Inverse is available
48 my $distance=$point->distance($point2); #if Geo::Inverse->VERSION >=0.05
49  
50 =head1 USAGE TODO
51  
52 my $obj=GPS::Point->newNMEA($NMEA_lines); #e.g. GGA+GSA+RMC
53  
54 =head1 CONSTRUCTORS
55  
56 =head2 new
57  
58 my $obj = GPS::Point->new();
59  
60 =cut
61  
62 5 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
63 5 my $this = shift();
64 5 ▶ my $class = ref($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
050
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
65 5 my $self = {};
66 5 bless $self, $class;
67 5 $self->initialize(@_);
68 5 return $self;
69 }
70  
71 =head2 newGPSD
72  
73 my $obj=GPS::Point->newGPSD($GPSD_O_line);#e.g. GPSD,O=....
74  
75 Note: GPSD protocol 2 is soon to be defunct.
76  
77 =cut
78  
79 1 ▶sub newGPSD {
Subroutine newGPSD: called CC=2 SCAR=7.1
Pod documented
80 1 my $this = shift();
81 1 ▶ my $class = ref($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
82 1 my $self = {};
83 1 bless $self, $class;
84 1 $self->initializeGPSD(@_);
85 1 return $self;
86 }
87  
88 =head2 newMulti
89  
90 Constructs a GPS::Point from a Multitude of arguments. Arguments can be a L<GPS::Point>, L<Geo::Point>, {lat=>$lat,lon=>$lon} (can be blessed), [$lat, $lon] (can be blessed) or a ($lat, $lon) pair.
91  
92 my $point=GPS::Point->newMulti( $lat, $lon, $alt ); #supports lat, lon and alt
93 my $point=GPS::Point->newMulti([$lat, $lon, $alt]); #supports lat, lon and alt
94 my $point=GPS::Point->newMulti({lat=>$lat, lon=>$lon, ...});
95 my $point=GPS::Point->newMulti(GPS::Point->new(lat=>$lat, lon=>$lon));
96 my $point=GPS::Point->newMulti(Geo::Point->new(lat=>$lat, long=>$lon, proj=>'wgs84'));
97 my $point=GPS::Point->newMulti({latitude=>$lat, longtude=>$lon});
98  
99 Note: Hash reference context supports the following keys lat, lon, alt, latitude, longitude, long, altitude, elevation, hae, elev.
100  
101 Note: Units are always decimal degrees for latitude and longitude and meters above the WGS-84 ellipsoid for altitude.
102  
103 =cut
104  
105 7 ▶sub newMulti {
Subroutine newMulti: called CC=2 SCAR=7.1
Pod documented
106 7 my $this = shift();
107 7 ▶ my $class = ref($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
070
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
108 7 my $self = {};
109 7 bless $self, $class;
110 7 $self->initializeMulti(@_);
111 7 return $self;
112 }
113  
114 =head2 initialize, initializeGPSD, initializeMulti
115  
116 =cut
117  
118 5 ▶sub initialize {
Subroutine initialize: called CC=1 SCAR=0.0
Pod documented
119 5 my $self = shift();
120 5 %$self=@_;
121 }
122  
123 1 ▶sub initializeGPSD {
Subroutine initializeGPSD: called CC=4 SCAR=13.9
Pod documented
124 1 my $self=shift();
125 1 my $line=shift(); #GPSD,O=MID2 1175911006.190 ? 53.527185 -113.530093 705.51 4.00 3.49 0.0000 0.074 0.101 ? 8.00 6.99 3
126 1 my @line=split(/,/, $line);
127 1 ▶ warn("Warning: Expected GPSD formatted line.") unless $line[0] eq "GPSD";
Branch: 1 branch
BranchTrueFalseTotal
unless $line[0] eq "GPSD" 0 1 1
128 1 my $obj=undef();
129 1 foreach (@line) { #I pull the last one if O=?,O=?,...
130 2 my @rpt=split(/=/, $_);
131 2 ▶ if ($rpt[0] eq 'O') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rpt[0] eq "O") 1 1 2
132 1 my @data=map {&_q2u($_)} split(/\s+/, $rpt[1]);
133 1 %$self=(tag => $data[ 0],
134 time => $data[ 1],
135 etime => $data[ 2],
136 lat => $data[ 3],
137 lon => $data[ 4],
138 alt => $data[ 5],
139 ehorizontal => $data[ 6],
140 evertical => $data[ 7],
141 heading => $data[ 8],
142 speed => $data[ 9],
143 climb => $data[10],
144 eheading => $data[11],
145 espeed => $data[12],
146 eclimb => $data[13],
147 mode => $data[14]);
148 }
149 }
150 }
151  
152 7 ▶sub initializeMulti {
Subroutine initializeMulti: called CC=29 SCAR=52.6
Pod documented
153 7 my $self=shift;
154 7 my $point=shift;
155 7 ▶ if (!ref($point)) {
Branch: 6 branches
BranchTrueFalseTotal
if (not ref $point) { } 0 7 7
elsif (ref $point eq 'Geo::Point') { } 0 7 7
elsif (ref $point eq 'GPS::Point') { } 0 7 7
elsif (ref $point eq 'Net::GPSD::Point') { } 0 7 7
elsif (builtin::reftype($point) eq 'HASH') { } 5 2 7
elsif (builtin::reftype($point) eq 'ARRAY') { } 2 0 2
156 0 ▶ $self->{'lat'}=$point ||0;
Condition0%0/2
$point || 0
l!l
00
MC/DC0%0/1
$point || 0
$point
Truth table0%0/2
A
A= $point
Aresult
11
00
157 0 ▶ $self->{'lon'}=shift ||0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
158 0 ▶ $self->{'alt'}=shift ||0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
159 } elsif (ref($point) eq "Geo::Point") {
160 0 ▶ $point=$point->in('wgs84') unless $point->proj eq "wgs84";
Branch: 1 branch
BranchTrueFalseTotal
unless $point->proj eq "wgs84" 0 0 0
161 0 ▶ $self->{'lat'}=$point->latitude ||0;
Condition0%0/2
$point->latitude || 0
l!l
00
MC/DC0%0/1
$point->latitude || 0
$point->latitude
Truth table0%0/2
A
A= $point->latitude
Aresult
11
00
162 0 ▶ $self->{'lon'}=$point->longitude ||0;
Condition0%0/2
$point->longitude || 0
l!l
00
MC/DC0%0/1
$point->longitude || 0
$point->longitude
Truth table0%0/2
A
A= $point->longitude
Aresult
11
00
163 } elsif (ref($point) eq "GPS::Point") {
164 0 %$self=%$point;
165 } elsif (ref($point) eq "Net::GPSD::Point") {
166 0 $self->{'time'}=$point->time;
167 0 ▶ $self->{'lat'}=$point->latitude ||0;
Condition0%0/2
$point->latitude || 0
l!l
00
MC/DC0%0/1
$point->latitude || 0
$point->latitude
Truth table0%0/2
A
A= $point->latitude
Aresult
11
00
168 0 ▶ $self->{'lon'}=$point->longitude ||0;
Condition0%0/2
$point->longitude || 0
l!l
00
MC/DC0%0/1
$point->longitude || 0
$point->longitude
Truth table0%0/2
A
A= $point->longitude
Aresult
11
00
169 0 ▶ $self->{'alt'}=$point->altitude ||0;
Condition0%0/2
$point->altitude || 0
l!l
00
MC/DC0%0/1
$point->altitude || 0
$point->altitude
Truth table0%0/2
A
A= $point->altitude
Aresult
11
00
170 0 $self->{'speed'}=$point->speed;
171 0 $self->{'heading'}=$point->heading;
172 0 $self->{'climb'}=$point->climb;
173 0 $self->{'etime'}=$point->errortime;
174 0 $self->{'ehorizontal'}=$point->errorhorizontal;
175 0 $self->{'evertical'}=$point->errorvertical;
176 0 $self->{'espeed'}=$point->errorspeed;
177 0 $self->{'eheading'}=$point->errorheading;
178 0 $self->{'eclimb'}=$point->errorclimb;
179 0 $self->{'mode'}=$point->mode;
180 0 $self->{'tag'}=$point->tag;
181 } elsif (reftype($point) eq "HASH") {
182 5 %$self=%$point;
183 $self->{'lat'}=$point->{'lat'} ||
184 5 ▶ delete($point->{'latitude'}) ||0;
Condition60%3/5
$point->{'lat'} || delete $point->{'latitude'} || 0
l!l
50
$point->{"lat"} or delete $point->{"latitude"}
l!l&&r!l&&!r
320
MC/DC0%0/2
$point->{'lat'} || delete $point->{'latitude'} || 0
$point->{"lat"} delete $point->{"latitude"}
Truth table66%2/3
A or B
A= $point->{"lat"}B= delete $point->{"latitude"}
ABresult
1X1
011
000
185 $self->{'lon'}=$point->{'lon'} ||
186 delete($point->{'long'}) ||
187 5 ▶ delete($point->{'longitude'}) ||0;
Condition75%6/8
$point->{'lon'} || delete $point->{'long'} || delete $point->{'longitude'} || 0
l!l
50
$point->{"lon"} or delete $point->{"long"} or delete $point->{"longitude"}
l!l&&r!l&&!r
410
$point->{"lon"} or delete $point->{"long"}
l!l&&r!l&&!r
221
MC/DC0%0/3
$point->{'lon'} || delete $point->{'long'} || delete $point->{'longitude'} || 0
$point->{"lon"} delete $point->{"long"} delete $point->{"longitude"}
Truth table75%3/4
A or B or C
A= $point->{"lon"}B= delete $point->{"long"}C= delete $point->{"longitude"}
ABCresult
1XX1
01X1
0011
0000
188 $self->{'alt'}=$point->{'alt'} ||
189 delete($point->{'altitude'}) ||
190 delete($point->{'elevation'}) ||
191 delete($point->{'hae'}) ||
192 5 ▶ delete($point->{'elev'}) ||0;
Condition78%11/14
$point->{'alt'} || delete $point->{'altitude'} || delete $point->{'elevation'} || delete $point->{'hae'} || delete $point->{'elev'} || 0
l!l
50
$point->{"alt"} or delete $point->{"altitude"} or delete $point->{"elevation"} or delete $point->{"hae"} or delete $point->{"elev"}
l!l&&r!l&&!r
410
$point->{"alt"} or delete $point->{"altitude"} or delete $point->{"elevation"} or delete $point->{"hae"}
l!l&&r!l&&!r
401
$point->{"alt"} or delete $point->{"altitude"} or delete $point->{"elevation"}
l!l&&r!l&&!r
311
$point->{"alt"} or delete $point->{"altitude"}
l!l&&r!l&&!r
212
MC/DC0%0/5
$point->{'alt'} || delete $point->{'altitude'} || delete $point->{'elevation'} || delete $point->{'hae'} || delete $point->{'elev'} || 0
$point->{"alt"} delete $point->{"altitude"} delete $point->{"elevation"} delete $point->{"hae"} delete $point->{"elev"}
Truth table66%4/6
A or B or C or D or E
A= $point->{"alt"}B= delete $point->{"altitude"}C= delete $point->{"elevation"}D= delete $point->{"hae"}E= delete $point->{"elev"}
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
193 } elsif (reftype($point) eq "ARRAY") {
194 2 ▶ $self->{'lat'}=$point->[0] ||0;
Condition50%1/2
$point->[0] || 0
l!l
20
MC/DC0%0/1
$point->[0] || 0
$point->[0]
Truth table50%1/2
A
A= $point->[0]
Aresult
11
00
195 2 ▶ $self->{'lon'}=$point->[1] ||0;
Condition50%1/2
$point->[1] || 0
l!l
20
MC/DC0%0/1
$point->[1] || 0
$point->[1]
Truth table50%1/2
A
A= $point->[1]
Aresult
11
00
196 2 ▶ $self->{'alt'}=$point->[2] ||0;
Condition50%1/2
$point->[2] || 0
l!l
20
MC/DC0%0/1
$point->[2] || 0
$point->[2]
Truth table50%1/2
A
A= $point->[2]
Aresult
11
00
197 }
198 }
199  
200 =head1 METHODS (Base)
201  
202 =head2 time
203  
204 Sets or returns seconds since the Unix epoch, UTC (float, seconds)
205  
206 print $obj->time, "\n";
207  
208 =cut
209  
210 2 ▶sub time {
Subroutine time: called CC=2 SCAR=7.1
Pod documented
211 2 my $self = shift();
212 2 ▶ $self->{'time'}=shift() if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
213 2 return $self->{'time'};
214 }
215  
216 =head2 lat, latitude
217  
218 Sets or returns Latitude (float, degrees)
219  
220 print $obj->lat, "\n";
221  
222 =cut
223  
224 6 *latitude=\&lat;
225  
226 17 ▶sub lat {
Subroutine lat: called CC=2 SCAR=6.9
Pod documented
227 17 my $self=shift;
228 17 ▶ $self->{'lat'}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 16 17
229 17 return $self->{'lat'};
230 }
231  
232 =head2 lon, long, longitude
233  
234 Sets or returns Longitude (float, degrees)
235  
236 print $obj->lon, "\n";
237  
238 =cut
239  
240 6 *longitude=\&lon;
241 6 *long=\&lon;
242  
243 13 ▶sub lon {
Subroutine lon: called CC=2 SCAR=7.1
Pod documented
244 13 my $self = shift();
245 13 ▶ $self->{'lon'}=shift() if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 13 13
246 13 return $self->{'lon'};
247 }
248  
249 =head2 alt, altitude, hae, elevation
250  
251 Sets or returns Altitude (float, meters)
252  
253 print $obj->alt, "\n";
254  
255 =cut
256  
257 6 *altitude=\&alt;
258 6 *hae=\&alt;
259 6 *elevation=\&alt;
260  
261 9 ▶sub alt {
Subroutine alt: called CC=2 SCAR=7.1
Pod documented
262 9 my $self = shift();
263 9 ▶ $self->{'alt'}=shift() if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 9 9
264 9 return $self->{'alt'};
265 }
266  
267 =head2 speed
268  
269 Sets or returns speed (float, meters/sec)
270  
271 print $obj->speed, "\n";
272  
273 =cut
274  
275 1 ▶sub speed {
Subroutine speed: called CC=2 SCAR=7.1
Pod documented
276 1 my $self = shift();
277 1 ▶ $self->{'speed'}=shift() if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
278 1 return $self->{'speed'};
279 }
280  
281 =head2 heading, bearing
282  
283 Sets or returns heading (float, degrees)
284  
285 print $obj->heading, "\n";
286  
287 =cut
288  
289 6 *bearing=\&heading;
290  
291 2 ▶sub heading {
Subroutine heading: called CC=2 SCAR=7.1
Pod documented
292 2 my $self = shift();
293 2 ▶ $self->{'heading'}=shift() if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
294 2 return $self->{'heading'};
295 }
296  
297 =head2 climb
298  
299 Sets or returns vertical velocity (float, meters/sec)
300  
301 print $obj->climb, "\n";
302  
303 =cut
304  
305 1 ▶sub climb {
Subroutine climb: called CC=2 SCAR=7.1
Pod documented
306 1 my $self = shift();
307 1 ▶ $self->{'climb'}=shift() if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
308 1 return $self->{'climb'};
309 }
310  
311 =head2 etime
312  
313 Sets or returns estimated timestamp error (float, seconds, 95% confidence)
314  
315 print $obj->etime, "\n";
316  
317 =cut
318  
319 1 ▶sub etime {
Subroutine etime: called CC=2 SCAR=7.1
Pod documented
320 1 my $self = shift();
321 1 ▶ $self->{'etime'}=shift() if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
322 1 return $self->{'etime'};
323 }
324  
325 =head2 ehorizontal
326  
327 Sets or returns horizontal error estimate (float, meters)
328  
329 print $obj->ehorizontal, "\n";
330  
331 =cut
332  
333 1 ▶sub ehorizontal {
Subroutine ehorizontal: called CC=2 SCAR=7.1
Pod documented
334 1 my $self = shift();
335 1 ▶ $self->{'ehorizontal'}=shift() if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
336 1 return $self->{'ehorizontal'};
337 }
338  
339 =head2 evertical
340  
341 Sets or returns vertical error estimate (float, meters)
342  
343 print $obj->evertical, "\n";
344  
345 =cut
346  
347 1 ▶sub evertical {
Subroutine evertical: called CC=2 SCAR=7.1
Pod documented
348 1 my $self = shift();
349 1 ▶ $self->{'evertical'}=shift() if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
350 1 return $self->{'evertical'};
351 }
352  
353 =head2 espeed
354  
355 Sets or returns error estimate for speed (float, meters/sec, 95% confidence)
356  
357 print $obj->espeed, "\n";
358  
359 =cut
360  
361 1 ▶sub espeed {
Subroutine espeed: called CC=2 SCAR=7.1
Pod documented
362 1 my $self = shift();
363 1 ▶ $self->{'espeed'}=shift() if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
364 1 return $self->{'espeed'};
365 }
366  
367 =head2 eheading
368  
369 Sets or returns error estimate for course (float, degrees, 95% confidence)
370  
371 print $obj->eheading, "\n";
372  
373 =cut
374  
375 1 ▶sub eheading {
Subroutine eheading: called CC=2 SCAR=7.1
Pod documented
376 1 my $self = shift();
377 1 ▶ $self->{'eheading'}=shift() if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
378 1 return $self->{'eheading'};
379 }
380  
381 =head2 eclimb
382  
383 Sets or returns Estimated error for climb/sink (float, meters/sec, 95% confidence)
384  
385 print $obj->eclimb, "\n";
386  
387 =cut
388  
389 1 ▶sub eclimb {
Subroutine eclimb: called CC=2 SCAR=7.1
Pod documented
390 1 my $self = shift();
391 1 ▶ $self->{'eclimb'}=shift() if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
392 1 return $self->{'eclimb'};
393 }
394  
395 =head2 mode
396  
397 Sets or returns the NMEA mode (integer; undef=>no mode value yet seen, 1=>no fix, 2=>2D, 3=>3D)
398  
399 print $obj->mode, "\n";
400  
401 =cut
402  
403 11 ▶sub mode {
Subroutine mode: called CC=2 SCAR=6.9
Pod documented
404 11 my $self = shift();
405 11 ▶ $self->{'mode'}=shift() if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 2 9 11
406 11 return $self->{'mode'};
407 }
408  
409 =head2 tag
410  
411 Sets or returns a tag identifying the last sentence received. For NMEA devices this is just the NMEA sentence name; the talker-ID portion may be useful for distinguishing among results produced by different NMEA talkers in the same wire. (string)
412  
413 print $obj->tag, "\n";
414  
415 =cut
416  
417 1 ▶sub tag {
Subroutine tag: called CC=2 SCAR=7.1
Pod documented
418 1 my $self = shift();
419 1 ▶ $self->{'tag'}=shift() if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
420 1 return $self->{'tag'};
421 }
422  
423 =head1 METHODS (Value Added)
424  
425 =head2 fix
426  
427 Returns either 1 or 0 based upon if the GPS point is from a valid fix or not.
428  
429 print $obj->fix, "\n";
430  
431 At a minimum this method requires mode to be set.
432  
433 =cut
434  
435 4 ▶sub fix {
Subroutine fix: called CC=3 SCAR=11.0
Pod documented
436 4 my $self=shift;
437 4 ▶ if (defined($self->mode) and $self->mode > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->mode and $self->mode > 1) { } 3 1 4
Condition66%2/3
defined $self->mode and $self->mode > 1
!ll&&!rl&&r
103
MC/DC50%1/2
defined $self->mode and $self->mode > 1
defined $self->mode $self->mode > 1
Truth table66%2/3
A and B
A= defined $self->modeB= $self->mode > 1
ABresult
0X0
100
111
438 3 return 1;
439 } else {
440 1 return 0;
441 }
442 }
443  
444 =head2 datetime
445  
446 Returns a L<DateTime> object from time
447  
448 my $dt=$point->datetime;
449  
450 At a minimum this method requires time to be set.
451  
452 =cut
453  
454 0 ▶sub datetime {
Subroutine datetime: not called CC=2 SCAR=17.9
Pod documented
455 0 my $self=shift;
456 0 eval 'use DateTime';
457 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
458 0 die("Error: The datetime method requires DateTime");
459 } else {
460 0 return DateTime->from_epoch(epoch=>$self->time);
461 }
462 }
463  
464 =head2 latlon, latlong
465  
466 Returns Latitude, Longitude as an array in array context and as a space joined string in scalar context
467  
468 my @latlon=$point->latlon;
469 my $latlon=$point->latlon;
470  
471 At a minimum this method requires lat and lon to be set.
472  
473 =cut
474  
475 6 *latlong=\&latlon;
476  
477 2 ▶sub latlon {
Subroutine latlon: called CC=2 SCAR=6.9
Pod documented
478 2 my $self = shift();
479 2 my @latlon=($self->lat, $self->lon);
480 2 ▶ return wantarray ? @latlon : join(" ", @latlon);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 1 2
481 }
482  
483 =head2 setAltitude
484  
485 Sets altitude from USGS web service and then returns the GPS::Point object. This method is a wrapper around L<Geo::WebService::Elevation::USGS>.
486  
487 my $point=GPS::Point->new(lat=>$lat, lon=>$lon)->setAltitude;
488 $point->setAltitude;
489 my $alt=$point->alt;
490  
491 At a minimum this method requires lat and lon to be set and alt to be undef.
492  
493 =cut
494  
495 0 ▶sub setAltitude {
Subroutine setAltitude: not called CC=4 SCAR=30.0
Pod documented
496 0 my $self=shift;
497 0 ▶ unless (defined $self->alt) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->alt) 0 0 0
498 0 eval 'use Geo::WebService::Elevation::USGS';
499 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
500 0 die("Error: The setAltitude method requires Geo::WebService::Elevation::USGS");
501 } else {
502 0 my $eq=Geo::WebService::Elevation::USGS->new(units=>"METERS", croak=>0);
503 0 my $return=$eq->getElevation($self); #Assume this is HAE WGS-84
504 0 ▶ $self->alt($return->{'Elevation'}) if ref($return) eq "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if ref $return eq "HASH" 0 0 0
505 }
506 }
507 0 return $self;
508 }
509  
510 =head2 ecef
511  
512 Returns ECEF coordinates. This method is a wrapper around L<Geo::ECEF>.
513  
514 my ($x,$y,$z) = $point->ecef;
515 my @xyz = $point->ecef;
516 my $xyz_aref = $point->ecef; #if Geo::ECEF->VERSION >= 0.08
517  
518 At a minimum this method requires lat and lon to be set. (alt of 0 is assumed by Geo::ECEF->ecef).
519  
520 =cut
521  
522 0 ▶sub ecef {
Subroutine ecef: not called CC=3 SCAR=24.8
Pod documented
523 0 my $self=shift;
524 0 eval 'use Geo::ECEF';
525 0 ▶ die("Error: The ecef method requires Geo::ECEF") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
526 0 ▶ die("Error: The found geo::ecef not Geo::ECEF.") unless Geo::ECEF->can("new");
Branch: 1 branch
BranchTrueFalseTotal
unless "Geo::ECEF"->can("new") 0 0 0
527 0 my $obj=Geo::ECEF->new;
528 0 return $obj->ecef($self->lat, $self->lat, $self->alt);
529 }
530  
531 =head2 GeoPoint
532  
533 Returns a L<Geo::Point> Object in the WGS-84 projection.
534  
535 my $GeoPointObject = $point->GeoPoint;
536  
537 At a minimum this method requires lat and lon to be set.
538  
539 =cut
540  
541 0 ▶sub GeoPoint {
Subroutine GeoPoint: not called CC=2 SCAR=17.9
Pod documented
542 0 my $self = shift();
543 0 eval 'use Geo::Point';
544 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
545 0 die("Error: The GeoPoint method requires Geo::Point");
546 } else {
547 0 return Geo::Point->new(lat=>$self->lat, long=>$self->lon, proj=>'wgs84');
548 }
549 }
550  
551 =head2 distance
552  
553 Returns distance in meters between the object point and the argument point. The argument can be any valid argument of newMulti constructor. This method is a wrapper around Geo::Inverse.
554  
555 my ($faz, $baz, $dist) = $point->distance($pt2); #Array context
556 my $dist = $point->distance($lat, $lon); #if Geo::Inverse->VERSION >=0.05
557  
558 At a minimum this method requires lat and lon to be set.
559  
560 =cut
561  
562 0 ▶sub distance {
Subroutine distance: not called CC=4 SCAR=30.0
Pod documented
563 0 my $self=shift;
564 0 my $point=$_[0];
565 0 ▶ $point=GPS::Point->newMulti(@_) unless ref($point) eq "GPS::Point";
Branch: 1 branch
BranchTrueFalseTotal
unless ref $point eq "GPS::Point" 0 0 0
566 0 ▶ if (defined $point) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $point) { } 0 0 0
567 0 eval 'use Geo::Inverse';
568 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
569 0 die("Error: The distance method requires Geo::Inverse");
570 } else {
571 0 my $gi=Geo::Inverse->new;
572 0 return $gi->inverse($self->latlon, $point->latlon);
573 }
574 } else {
575 0 die(qq{Error: Could not create point from parameters.});
576 }
577 }
578  
579 =head2 track
580  
581 Returns a point object at the predicted location in time seconds assuming constant velocity. Using L<Geo::Forward> calculation.
582  
583 my $new_point=$point->track($seconds); #default $point->heading
584 my $new_point=$point->track($seconds => $heading);
585  
586 At a minimum this method requires lat and lon to be set. It might be very useful to have speed, heading and time set although they all default to zero.
587  
588 =cut
589  
590 0 ▶sub track {
Subroutine track: not called CC=6 SCAR=37.4
Pod documented
591 0 my $self=shift;
592 0 ▶ my $seconds=shift||0; #seconds
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
593 0 my $heading=shift; #degrees
594 0 ▶ $heading=$self->heading || 0 unless defined $heading; #support 0 degrees passed
Branch: 1 branch
BranchTrueFalseTotal
unless defined $heading 0 0 0
Condition0%0/2
$self->heading || 0
l!l
00
MC/DC0%0/1
$self->heading || 0
$self->heading
Truth table0%0/2
A
A= $self->heading
Aresult
11
00
595 0 ▶ my $speed=$self->speed || 0; #m/s
Condition0%0/2
$self->speed || 0
l!l
00
MC/DC0%0/1
$self->speed || 0
$self->speed
Truth table0%0/2
A
A= $self->speed
Aresult
11
00
596 0 my $dist=$speed * $seconds; #meters
597 0 my $point=$self->forward($dist => $heading);
598 0 ▶ $point->time(($self->time||0) + $seconds);
Condition0%0/2
$self->time || 0
l!l
00
MC/DC0%0/1
$self->time || 0
$self->time
Truth table0%0/2
A
A= $self->time
Aresult
11
00
599 0 return $point;
600 }
601  
602 =head2 forward
603  
604 Returns a point object at the distance and heading using L<Geo::Forward> calculations.
605  
606 my $point=$point->forward($dist); #default $point->heading
607 my $point=$point->forward($dist => $heading); #meters => degrees
608  
609 At a minimum this method requires lat and lon to be set. It might be useful to have heading set although the default is zero.
610  
611 =cut
612  
613 0 ▶sub forward {
Subroutine forward: not called CC=5 SCAR=34.0
Pod documented
614 0 my $self=shift;
615 0 ▶ my $dist=shift || 0; #meters
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
616 0 my $faz=shift; #degrees
617 0 ▶ $faz=$self->heading || 0 unless defined $faz;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $faz 0 0 0
Condition0%0/2
$self->heading || 0
l!l
00
MC/DC0%0/1
$self->heading || 0
$self->heading
Truth table0%0/2
A
A= $self->heading
Aresult
11
00
618 0 eval 'use Geo::Forward';
619 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
620 0 die("Error: The track method requires Geo::Forward");
621 } else {
622 0 my $gf=Geo::Forward->new;
623 0 my ($lat2,$lon2,$baz) = $gf->forward($self->latlon, $faz, $dist);
624 0 my $point=GPS::Point->new(%$self);
625 0 $point->lat($lat2);
626 0 $point->lon($lon2);
627 0 return $point;
628 }
629 }
630  
631 =head2 buffer
632  
633 Returns a list of L<GPS::Point> objects equidistant from the current object location.
634  
635 my @buffer=$point->buffer($radius_meters, $sections); #returns (GPS::Point, GPS::Point, ...)
636 my $buffer=$point->buffer($radius_meters, $sections); #returns [GPS::Point, GPS::Point, ...]
637  
638 =cut
639  
640 0 ▶sub buffer {
Subroutine buffer: not called CC=4 SCAR=30.0
Pod documented
641 0 my $self=shift;
642 0 my $radius=shift; #meters
643 0 ▶ my $sections=shift || 60; #60 sections = 61 verticies
Condition0%0/2
shift() || 60
l!l
00
MC/DC0%0/1
shift() || 60
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
644 0 my @buffer=();
645 0 my $arc=360/$sections; #not zero!
646 0 foreach my $step (0 .. $sections) {
647 0 my $angle=$arc * $step;
648  
649 0 push @buffer, $self->forward($radius => $angle);
650 }
651 0 ▶ return wantarray ? @buffer : \@buffer;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
652 }
653  
654 15 ▶sub _q2u {
Subroutine _q2u: called CC=2 SCAR=6.9
655 15 my $a=shift();
656 15 ▶ return $a eq '?' ? undef() : $a;
Branch: 1 branch
BranchTrueFalseTotal
$a eq '?' ? : 2 13 15
657 }
658  
659 =head1 BUGS
660  
661 Please log on RT and send email to GPSD-DEV or GEO-PERL email lists.
662  
663 =head1 SUPPORT
664  
665 DavisNetworks.com supports all Perl applications including this package.
666  
667 =head1 AUTHOR
668  
669 Michael R. Davis
670 CPAN ID: MRDVT
671 DavisNetworks.com
672 account=>perl,tld=>com,domain=>michaelrdavis
673 http://www.davisnetworks.com/
674  
675 =head1 COPYRIGHT
676  
677 This program is free software licensed under the...
678  
679 The BSD License
680  
681 The full text of the license can be found in the LICENSE file included with this module.
682  
683 =head1 SEE ALSO
684  
685 L<Geo::Point>, L<Net::GPSD>, L<Net::GPSD::Point>, L<Geo::ECEF>, L<Geo::Functions>, L<Geo::Forward>, L<Geo::Inverse>, L<Geo::Distance>, L<Geo::Ellipsoids>, L<Geo::WebService::Elevation::USGS>, L<DateTime>
686  
687 =cut
688  
689 6 1;
↑ Summary