2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
7 package gov
.nasa
.worldwind
.formats
.nmea
;
9 import gov
.nasa
.worldwind
.tracks
.TrackPoint
;
10 import gov
.nasa
.worldwind
.util
.Logging
;
14 * @version $Id: NmeaTrackPoint.java 2471 2007-07-31 21:50:57Z tgaskins $
16 public class NmeaTrackPoint
implements TrackPoint
18 private double latitude
;
19 private double longitude
;
20 private double altitude
;
21 private double geoidHeight
;
26 * @throws IllegalArgumentException if <code>words</code> is null or has length less than 1
28 public NmeaTrackPoint(String
[] words
)
32 String msg
= Logging
.getMessage("nullValue.ArrayIsNull");
33 Logging
.logger().severe(msg
);
34 throw new IllegalArgumentException(msg
);
38 String msg
= Logging
.getMessage("generic.ArrayInvalidLength", words
.length
);
39 Logging
.logger().severe(msg
);
40 throw new IllegalArgumentException(msg
);
43 if (words
[0].equalsIgnoreCase("GPGGA"))
45 else if (words
[0].equalsIgnoreCase("GPRMC"))
51 * @throws IllegalArgumentException if <code>words</code> is null or has length less than 6
53 private void doGGA(String
[] words
)
55 // words won't be null, but it could be the wrong length
58 String msg
= Logging
.getMessage("generic.ArrayInvalidLength", words
.length
);
59 Logging
.logger().severe(msg
);
60 throw new IllegalArgumentException(msg
);
64 this.latitude
= this.parseLatitude(words
[2], words
[3]);
65 this.longitude
= this.parseLongitude(words
[4], words
[5]);
66 if (words
.length
>= 11)
67 this.altitude
= this.parseElevation(words
[9], words
[10]);
68 if (words
.length
>= 13)
69 this.geoidHeight
= this.parseElevation(words
[11], words
[12]);
72 private void doRMC(String
[] words
)
76 private double parseLatitude(String angle
, String direction
)
78 if (angle
.length() == 0)
81 double minutes
= angle
.length() > 2 ? Double
.parseDouble(angle
.substring(2, angle
.length())) : 0d
;
82 double degrees
= Double
.parseDouble(angle
.substring(0, 2)) + minutes
/ 60d
;
84 return direction
.equalsIgnoreCase("S") ?
-degrees
: degrees
;
87 private double parseLongitude(String angle
, String direction
)
89 if (angle
.length() == 0)
92 double minutes
= angle
.length() > 3 ? Double
.parseDouble(angle
.substring(3, angle
.length())) : 0d
;
93 double degrees
= Double
.parseDouble(angle
.substring(0, 3)) + minutes
/ 60d
;
95 return direction
.equalsIgnoreCase("W") ?
-degrees
: degrees
;
98 private double parseElevation(String height
, String units
)
100 if (height
.length() == 0)
103 return Double
.parseDouble(height
) * unitsToMeters(units
);
106 private double unitsToMeters(String units
)
110 if (units
.equals("M")) // meters
112 else if (units
.equals("f")) // feet
114 else if (units
.equals("F")) // fathoms
122 public double getLatitude()
129 * @throws IllegalArgumentException if <code>latitude</code> is less than -90 or greater than 90
131 public void setLatitude(double latitude
)
133 if (latitude
> 90 || latitude
< -90)
135 String msg
= Logging
.getMessage("generic.AngleOutOfRange", latitude
);
136 Logging
.logger().severe(msg
);
137 throw new IllegalArgumentException(msg
);
140 this.latitude
= latitude
;
143 public double getLongitude()
150 * @throws IllegalArgumentException if <code>longitude</code> is less than -180 or greater than 180
152 public void setLongitude(double longitude
)
154 if (longitude
> 180 || longitude
< -180)
156 String msg
= Logging
.getMessage("generic.AngleOutOfRange", longitude
);
157 Logging
.logger().severe(msg
);
158 throw new IllegalArgumentException(msg
);
161 this.longitude
= longitude
;
164 public double getElevation()
166 return this.altitude
+ this.geoidHeight
;
169 public void setElevation(double elevation
)
171 this.altitude
= elevation
;
172 this.geoidHeight
= 0;
175 public String
getTime()
180 public void setTime(String time
)
186 public String
toString()
188 return String
.format("(%10.8f\u00B0, %11.8f\u00B0, %10.4g m, %10.4g m, %s)", this.latitude
, this.longitude
,
189 this.altitude
, this.geoidHeight
, this.time
);