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
.*;
13 * @version $Id: NmeaTrackPoint.java 513 2007-01-18 00:33:16Z ericdalgliesh $
15 public class NmeaTrackPoint
implements gov
.nasa
.worldwind
.TrackPoint
17 private double latitude
;
18 private double longitude
;
19 private double altitude
;
20 private double geoidHeight
;
25 * @throws IllegalArgumentException if <code>words</code> is null or has length less than 1
27 public NmeaTrackPoint(String
[] words
)
31 String msg
= WorldWind
.retrieveErrMsg("nullValue.ArrayIsNull");
32 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, msg
);
33 throw new IllegalArgumentException(msg
);
37 String msg
= WorldWind
.retrieveErrMsg("generic.arrayInvalidLength") + WorldWind
.retrieveErrMsg(
38 "punctuation.space") + words
.length
;
39 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, 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
= WorldWind
.retrieveErrMsg("generic.arrayInvalidLength") + WorldWind
.retrieveErrMsg(
59 "punctuation.space") + words
.length
;
60 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, msg
);
61 throw new IllegalArgumentException(msg
);
65 this.latitude
= this.parseLatitude(words
[2], words
[3]);
66 this.longitude
= this.parseLongitude(words
[4], words
[5]);
67 if (words
.length
>= 11)
68 this.altitude
= this.parseElevation(words
[9], words
[10]);
69 if (words
.length
>= 13)
70 this.geoidHeight
= this.parseElevation(words
[11], words
[12]);
73 private void doRMC(String
[] words
)
77 private double parseLatitude(String angle
, String direction
)
79 if (angle
.length() == 0)
82 double minutes
= angle
.length() > 2 ? Double
.parseDouble(angle
.substring(2, angle
.length())) : 0d
;
83 double degrees
= Double
.parseDouble(angle
.substring(0, 2)) + minutes
/ 60d
;
85 return direction
.equalsIgnoreCase("S") ?
-degrees
: degrees
;
88 private double parseLongitude(String angle
, String direction
)
90 if (angle
.length() == 0)
93 double minutes
= angle
.length() > 3 ? Double
.parseDouble(angle
.substring(3, angle
.length())) : 0d
;
94 double degrees
= Double
.parseDouble(angle
.substring(0, 3)) + minutes
/ 60d
;
96 return direction
.equalsIgnoreCase("W") ?
-degrees
: degrees
;
99 private double parseElevation(String height
, String units
)
101 if (height
.length() == 0)
104 return Double
.parseDouble(height
) * unitsToMeters(units
);
107 private double unitsToMeters(String units
)
111 if (units
.equals("M")) // meters
113 else if (units
.equals("f")) // feet
115 else if (units
.equals("F")) // fathoms
123 public double getLatitude()
130 * @throws IllegalArgumentException if <code>latitude</code> is less than -90 or greater than 90
132 public void setLatitude(double latitude
)
134 if (latitude
> 90 || latitude
< -90)
136 String msg
= WorldWind
.retrieveErrMsg("generic.angleOutOfRange") + WorldWind
.retrieveErrMsg(
137 "punctuation.space") + latitude
;
138 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, msg
);
139 throw new IllegalArgumentException(msg
);
142 this.latitude
= latitude
;
145 public double getLongitude()
152 * @throws IllegalArgumentException if <code>longitude</code> is less than -180 or greater than 180
154 public void setLongitude(double longitude
)
156 if (longitude
> 180 || longitude
< -180)
158 String msg
= WorldWind
.retrieveErrMsg("generic.angleOutOfRange") + WorldWind
.retrieveErrMsg(
159 "punctuation.space") + longitude
;
160 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, msg
);
161 throw new IllegalArgumentException(msg
);
164 this.longitude
= longitude
;
167 public double getElevation()
169 return this.altitude
+ this.geoidHeight
;
172 public void setElevation(double elevation
)
174 this.altitude
= elevation
;
175 this.geoidHeight
= 0;
178 public String
getTime()
183 public void setTime(String time
)
189 public String
toString()
191 return String
.format("(%10.8f\u00B0, %11.8f\u00B0, %10.4g m, %10.4g m, %s)", this.latitude
, this.longitude
,
192 this.altitude
, this.geoidHeight
, this.time
);