public class EarthLocation
extends java.lang.Object
implements java.lang.Cloneable
Modifier and Type | Field and Description |
---|---|
static int |
D
Format style code for integer degrees: '124 W'.
|
static int |
DD
Format style code for 2-digit degrees: '124.36 W'.
|
static int |
DDDD
Format style code for 4-digit degrees: '124.3600 W'.
|
static int |
DDMM
Format style code for degrees, minutes: '124 21.60 W'.
|
static int |
DDMMSS
Format style code for degrees, minutes, seconds: '124 21 36.00 W'.
|
double |
lat
The earth location latitude in degrees.
|
static int |
LAT
Selection code for latitude.
|
double |
lon
The earth location longitude in degrees.
|
static int |
LON
Selection code for longitude.
|
static int |
RAW
Format style code for full precision degrees: '-124.360001453546473'.
|
Constructor and Description |
---|
EarthLocation()
Constructs a new earth location at the origin (0,0).
|
EarthLocation(Datum datum)
Constructs a new earth location at the origin (0,0) with the
specified datum.
|
EarthLocation(double lat,
double lon)
Constructs a new earth location from the specified parameters.
|
EarthLocation(double lat,
double lon,
Datum datum)
Constructs a new earth location from the specified parameters.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone() |
static double |
distance(double latA,
double lonA,
double latB,
double lonB)
Calculates the great circle distance between two locations A and B.
|
double |
distance(EarthLocation loc)
Calculates the great circle distance from this location to another.
|
boolean |
equals(java.lang.Object obj) |
java.lang.String |
format()
Formats this earth location to a string using the default format
style.
|
java.lang.String |
format(int style)
Formats this earth location to a string.
|
static java.lang.String |
formatSingle(double deg,
int style,
int select)
Formats a single coordinate from an earth location to a string.
|
java.lang.String |
formatSingle(int select)
Formats a single coordinate from this earth location coordinate
to a string using the default format style.
|
java.lang.String |
formatSingle(int style,
int select)
Formats a single coordinate from this earth location to a string.
|
double[] |
getCoords()
Gets the coordinates as [lat, lon].
|
Datum |
getDatum()
Gets the location geodetic datum.
|
static int |
getFormatStyle()
Gets the default format style used by location formatting
routines.
|
boolean |
isEast(EarthLocation loc)
Returns true if this location is east of the specified location.
|
boolean |
isNorth(EarthLocation loc)
Returns true if this location is north of the specified location.
|
boolean |
isSouth(EarthLocation loc)
Returns true if this location is south of the specified location.
|
boolean |
isValid()
Checks if this earth location is valid.
|
boolean |
isWest(EarthLocation loc)
Returns true if this location is west of the specified location.
|
static double |
latRange(double lat)
Returns a latitude in the range [-90..90].
|
static double |
lonRange(double lon)
Returns a longitude value in the range [-180..180).
|
static void |
main(java.lang.String[] argv)
Tests this class.
|
void |
markInvalid()
Marks this location as invalid.
|
void |
render(java.awt.Graphics2D g,
EarthImageTransform trans)
Renders this earth location to a graphics context as a point.
|
void |
setCoords(double lat,
double lon)
Sets the latitude and longitude coordinate values.
|
void |
setDatum(Datum newDatum)
Sets the location geodetic datum.
|
static void |
setFormatStyle(int style)
Sets the default format style used by location formatting
methods.
|
void |
shiftDatum(Datum newDatum)
Sets the location geodetic datum and shifts the latitude and
longitude coordinates so that they reflect the newly specified
datum.
|
java.lang.String |
toString() |
EarthLocation |
translate(double latInc,
double lonInc)
Translates an earth location by the specified increments.
|
public static final int D
public static final int DD
public static final int DDDD
public static final int RAW
public static final int DDMM
public static final int DDMMSS
public static final int LAT
public static final int LON
public double lat
public double lon
public EarthLocation()
public EarthLocation(double lat, double lon)
lat
- the latitude in degrees.lon
- the longitude in degrees.public EarthLocation(Datum datum)
datum
- the geodetic datum.public EarthLocation(double lat, double lon, Datum datum)
lat
- the latitude in degrees.lon
- the longitude in degrees.datum
- the geodetic datum.public void setDatum(Datum newDatum)
newDatum
- the location geodetic datum.shiftDatum(noaa.coastwatch.util.trans.Datum)
public Datum getDatum()
public void shiftDatum(Datum newDatum)
newDatum
- the new datum to convert to.public static void setFormatStyle(int style)
style
- the location format style to use.public static int getFormatStyle()
setFormatStyle(int)
public double[] getCoords()
public void setCoords(double lat, double lon)
lat
- the latitude in degrees.lon
- the longitude in degrees.public static double distance(double latA, double lonA, double latB, double lonB)
Haversine Formula (from R.W. Sinnott, "Virtues of the Haversine", Sky and Telescope, vol. 68, no. 2, 1984, p. 159):
dlon = lon2 - lon1 dlat = lat2 - lat1 a = sin^2(dlat/2) + cos(lat1) * cos(lat2) * sin^2(dlon/2) c = 2 * arcsin(min(1,sqrt(a))) d = R * c
latA
- the latitude of point A in degrees.lonA
- the longitude of point A in degrees.latB
- the latitude of point B in degrees.lonB
- the longitude of point B in degrees.distance(EarthLocation)
public double distance(EarthLocation loc)
loc
- the location for which to calculate the distance.distance(double,double,double,double)
public EarthLocation translate(double latInc, double lonInc)
latInc
- the latitude increment.lonInc
- the longitude increment.public boolean isNorth(EarthLocation loc)
public boolean isSouth(EarthLocation loc)
public boolean isEast(EarthLocation loc)
public boolean isWest(EarthLocation loc)
public static java.lang.String formatSingle(double deg, int style, int select)
deg
- the latitude or longitude value in degrees.style
- the format style to use.select
- the coordinate selection. Use LAT
for
latitude and LON
for longitude.public java.lang.String formatSingle(int style, int select)
style
- the format style to use.select
- the coordinate selection. Use LAT
for
latitude and LON
for longitude.public java.lang.String formatSingle(int select)
select
- the coordinate selection. Use LAT
for
latitude and LON
for longitude.public java.lang.String format(int style)
style
- the format style to use.public java.lang.String format()
public java.lang.Object clone()
clone
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public boolean isValid()
markInvalid()
public void markInvalid()
isValid()
public static double latRange(double lat)
public static double lonRange(double lon)
public void render(java.awt.Graphics2D g, EarthImageTransform trans)
g
- the graphics context for drawing.trans
- the earth image transform for converting Earth
locations to image points.public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public static void main(java.lang.String[] argv) throws java.lang.Exception
argv
- the array of command line parameters.java.lang.Exception