Worldwind public release 0.2
[worldwind-tracker.git] / gov / nasa / worldwind / formats / gpx / GpxTrackPoint.java
blobb5385d2ed25fe54161d99c94f97a9c9ac13c4b18
1 /*
2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
5 All Rights Reserved.
6 */
7 package gov.nasa.worldwind.formats.gpx;
9 import gov.nasa.worldwind.*;
11 /**
12 * @author tag
13 * @version $Id: GpxTrackPoint.java 515 2007-01-18 05:09:19Z ericdalgliesh $
15 public class GpxTrackPoint extends gov.nasa.worldwind.formats.gpx.ElementParser implements gov.nasa.worldwind.TrackPoint
17 private double latitude;
18 private double longitude;
19 private double elevation;
20 private String time;
22 /**
23 * @param uri
24 * @param lname
25 * @param qname
26 * @param attributes
27 * @throws IllegalArgumentException if attribues is null
29 @SuppressWarnings({"UnusedDeclaration"})
30 public GpxTrackPoint(String uri, String lname, String qname, org.xml.sax.Attributes attributes)
32 super("trkpt");
34 //don't validate uri, lname or qname - they aren't used.
36 if (attributes == null)
38 String msg = WorldWind.retrieveErrMsg("nullValue.org.xml.sax.AttributesIsNull");
39 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
40 throw new IllegalArgumentException(msg);
43 for (int i = 0; i < attributes.getLength(); i++)
45 String attrName = attributes.getLocalName(i);
46 String attrValue = attributes.getValue(i);
47 if (attrName.equalsIgnoreCase("lat"))
49 this.latitude = Double.parseDouble(attrValue);
51 else if (attrName.equalsIgnoreCase("lon"))
53 this.longitude = Double.parseDouble(attrValue);
58 @Override
59 public void doStartElement(String uri, String lname, String qname, org.xml.sax.Attributes attributes)
60 throws org.xml.sax.SAXException
62 //don't perform validation here - no parameters are actually used
65 /**
66 * @param uri
67 * @param lname
68 * @param qname
69 * @throws IllegalArgumentException if <code>lname</code> is null
70 * @throws org.xml.sax.SAXException
72 @Override
73 public void doEndElement(String uri, String lname, String qname) throws org.xml.sax.SAXException
75 if (lname == null)
77 String msg = WorldWind.retrieveErrMsg("nullValue.LNameIsNull");
78 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
79 throw new IllegalArgumentException(msg);
81 // don't validate uri or qname - they aren't used.
83 if (lname.equalsIgnoreCase("ele"))
85 this.elevation = Double.parseDouble(this.currentCharacters);
87 else if (lname.equalsIgnoreCase("time"))
89 this.time = this.currentCharacters.trim();
93 public double getLatitude()
95 return latitude;
98 /**
99 * @param latitude
100 * @throws IllegalArgumentException if <code>latitude</code> is less than -90 or greater than 90
102 public void setLatitude(double latitude)
104 if (latitude > 90 || latitude < -90)
106 String msg = WorldWind.retrieveErrMsg("generic.angleOutOfRange") + WorldWind.retrieveErrMsg(
107 "punctuation.space") + latitude;
108 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
109 throw new IllegalArgumentException(msg);
112 this.latitude = latitude;
115 public double getLongitude()
117 return longitude;
121 * @param longitude
122 * @throws IllegalArgumentException if <code>longitude</code> is less than -180 or greater than 180
124 public void setLongitude(double longitude)
126 if (longitude > 180 || longitude < -180)
128 String msg = WorldWind.retrieveErrMsg("generic.angleOutOfRange") + WorldWind.retrieveErrMsg(
129 "punctuation.space") + longitude;
130 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
131 throw new IllegalArgumentException(msg);
134 this.longitude = longitude;
137 public double getElevation()
139 return elevation;
142 public void setElevation(double elevation)
144 this.elevation = elevation;
147 public String getTime()
149 return time;
153 * @param time
154 * @throws IllegalArgumentException if <code>time</code> is null
156 public void setTime(String time)
158 if (time == null)
160 String msg = WorldWind.retrieveErrMsg("nullValue.TimeIsNull");
161 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
162 throw new IllegalArgumentException(msg);
164 this.time = time;
167 @Override
168 public String toString()
170 return String.format("(%10.6f\u00B0, %11.6f\u00B0, %10.4g m, %s)", this.latitude, this.longitude,
171 this.elevation, this.time);