public class Coordinates
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private double |
altitude |
(package private) static float |
calculatedAzimuth |
(package private) static float |
calculatedDistance |
static int |
DD_MM
Identifier for string coordinate representation Degrees, Minutes, decimal fractions of a minute
See Also:Constant Field Values
|
static int |
DD_MM_SS
Identifier for string coordinate representation Degrees, Minutes, Seconds and decimal fractions of a second
See Also:Constant Field Values
|
(package private) static double |
EARTH_RADIUS |
private double |
latitude |
private double |
longitude |
Constructor and Description |
---|
Coordinates(double latitude,
double longitude) |
Coordinates(double latitude,
double longitude,
double altitude)
Create a Coordinate object with 3 parameters:
latitude, longitude and altitude
|
Modifier and Type | Method and Description |
---|---|
double |
azimuthTo(Coordinates to)
Calculates the azimuth between the two points according to
the ellipsoid model of WGS84.
|
private static void |
calculateDistanceAndAzimuth(double d,
double d1,
double d2,
double d3) |
static java.lang.String |
convert(double coordinate,
int outputType)
UNTESTED as of April 7, 2009 - BB
/
/**
Converts a double representation of a coordinate with decimal degrees into a string
representation.
|
static double |
convert(java.lang.String coordinate)
Converts a String representation of a coordinate into the double representation as
used in this API.
|
private static boolean |
convertIsValidChar(char element)
Helper method for
convert(String) |
private static java.lang.String[] |
convertSplit(java.lang.String in)
Helper method for
convert(String) |
double |
distance(Coordinates to)
Calculates the geodetic distance between the two points according
to the ellipsoid model of WGS84.
|
private static java.lang.String |
dropTrailingZeros(int number)
Takes an integer and removes trailing zeros.
|
double |
getAltitude()
Altitude above mean sea level.
|
double |
getLatitude()
Returns the latitude component of this coordinate.
|
double |
getLongitude()
Returns the longitude component of this coordinate.
|
private static double |
mod(double d,
double d1) |
void |
setAltitude(double altitude) |
void |
setLatitude(double latitude) |
void |
setLongitude(double longitude) |
private double latitude
private double longitude
private double altitude
public static final int DD_MM
public static final int DD_MM_SS
static final double EARTH_RADIUS
static float calculatedDistance
static float calculatedAzimuth
public Coordinates(double latitude, double longitude, double altitude)
latitude
- longitude
- altitude
- public Coordinates(double latitude, double longitude)
public double getLatitude()
Returns the latitude component of this coordinate. Positive values indicate northern latitude and negative values southern latitude.
The latitude is given in WGS84 datum.
setLatitude(double)
public void setLatitude(double latitude)
public void setLongitude(double longitude)
public double getLongitude()
Returns the longitude component of this coordinate. Positive values indicate eastern longitude and negative values western longitude.
The longitude is given in WGS84 datum.
setLongitude(double)
public void setAltitude(double altitude)
public double getAltitude()
public double azimuthTo(Coordinates to)
Calculates the azimuth between the two points according to the ellipsoid model of WGS84. The azimuth is relative to true north.
The Coordinates object on which this method is called is considered the origin for the calculation and the Coordinates object passed as a parameter is the destination which the azimuth is calculated to.
The azimuth (in degrees) increases clockwise. On this coordinate system, north is 0 degrees, east is 90 degrees, south is 180 degrees, and west is 270 degrees.
When the origin is the North pole and the destination is not the North pole, this method returns 180.0. When the origin is the South pole and the destination is not the South pole, this method returns 0.0. If the origin is equal to the destination, this method returns 0.0.
The implementation shall calculate the result as exactly as it can. However, it is required that the result is within 1 degree of the correct result.
public static java.lang.String convert(double coordinate, int outputType) throws java.lang.IllegalArgumentException
coordinate
- a double representation of a coordinateoutputType
- identifier of the type of the string representation wanted for output
The constant DD_MM_SS
identifies the syntax 1 and the constant
DD_MM
identifies the syntax 2.java.lang.IllegalArgumentException
- if the outputType is not one of the two constant values defined in this
class or if the coordinate value is not within the range [-180.0,
180.0) or is Double.NaNconvert(String)
private static java.lang.String dropTrailingZeros(int number)
number
- must be positivepublic static double convert(java.lang.String coordinate) throws java.lang.IllegalArgumentException, java.lang.NullPointerException
1. Degrees, minutes, seconds and decimal fractions of seconds. This is expressed as a string complying with the following BNF definition where the degrees are within the range [-179, 179] and the minutes and seconds are within the range [0, 59], or the degrees is -180 and the minutes, seconds and decimal fractions are 0:
coordinate = degrees ":" minutes ":" seconds "."
decimalfrac | degrees ":" minutes ":" seconds | degrees
":" minutes
degrees = degreedigits | "-" degreedigits
degreedigits = digit | nonzerodigit digit | "1" digit digit
minutes = minsecfirstdigit digit
seconds = minsecfirstdigit digit
decimalfrac = 1*3digit
digit = "0" | "1" | "2" | "3" |
"4" | "5" | "6" | "7" | "8" |
"9"
nonzerodigit = "1" | "2" | "3" | "4" |
"5" | "6" | "7" | "8" | "9"
minsecfirstdigit = "0" | "1" | "2" | "3" |
"4" | "5"
2. Degrees, minutes and decimal fractions of minutes. This is expressed as a string complying with the following BNF definition where the degrees are within the range [-179, 179] and the minutes are within the range [0, 59], or the degrees is -180 and the minutes and decimal fractions are 0:
coordinate = degrees ":" minutes "." decimalfrac | degrees
":" minutes
degrees = degreedigits | "-" degreedigits
degreedigits = digit | nonzerodigit digit | "1" digit digit
minutes =
minsecfirstdigit digit
decimalfrac = 1*5digit
digit = "0" |
"1" | "2" | "3" | "4" | "5" |
"6" | "7" | "8" | "9"
nonzerodigit =
"1" | "2" | "3" | "4" | "5" |
"6" | "7" | "8" | "9"
minsecfirstdigit = "0" | "1" | "2" | "3" |
"4" | "5"
For example, for the double value of the coordinate 61.51d, the corresponding syntax 1 string is "61:30:36" and the corresponding syntax 2 string is "61:30.6".
coordinate
- a String in either of the two representation specified abovejava.lang.IllegalArgumentException
- if the coordinate input parameter does not comply with the defined
syntax for the specified typesjava.lang.NullPointerException
- if the coordinate string is null convertprivate static boolean convertIsValidChar(char element)
convert(String)
element
- private static java.lang.String[] convertSplit(java.lang.String in) throws java.lang.IllegalArgumentException
convert(String)
in
- java.lang.IllegalArgumentException
public double distance(Coordinates to)
to
- the point to calculate the geodetic toprivate static void calculateDistanceAndAzimuth(double d, double d1, double d2, double d3)
private static double mod(double d, double d1)