public final class Location extends Object implements Comparable<Location>
Location represents a point with reference to the earth's
ellipsoid. It is expressed in terms of latitude, longitude, and depth. As in
seismology, the convention adopted in here is for depth to be positive-down,
always. Locations may be defined using longitude values in the range: [-180°,
360°]. Location instances are immutable.
Note that although static factory methods take arguments in the order:
[lat, lon, depth], String representations of a location are
in the order: [lon, lat, depth], consistent with KML, GeoJSON, and
other digital coordinate formats that match standard plotting coordinate
order: [x, y, z].
For computational convenience, latitude and longitude values are converted
and stored internally in radians. Special get***Rad() methods are
provided to access this native format.
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Location loc)
Compare this
Location to another and sort first by latitude, then
by longitude. |
static Location |
create(double lat,
double lon)
Create a new
Location with the supplied latitude and longitude and
a depth of 0 km. |
static Location |
create(double lat,
double lon,
double depth)
Create a new
Location with the supplied latitude, longitude, and
depth. |
double |
depth()
Returns the depth of this
Location in km. |
boolean |
equals(Object obj) |
static Location |
fromString(String s)
Generate a new
Location by parsing the supplied String. |
int |
hashCode() |
double |
lat()
The latitude of this
Location in decimal degrees. |
double |
latRad()
The latitude of this
Location in radians. |
double |
lon()
The longitude of this
Location in decimal degrees. |
double |
lonRad()
The longitude of this
Location in radians. |
static Converter<Location,String> |
stringConverter()
|
String |
toString()
Return a KML compatible tuple: 'lon,lat,depth' (no spaces).
|
public static Location create(double lat, double lon)
Location with the supplied latitude and longitude and
a depth of 0 km.lat - latitude in decimal degreeslon - longitude in decimal degreesIllegalArgumentException - if any supplied values are out of rangeCoordinatespublic static Location create(double lat, double lon, double depth)
Location with the supplied latitude, longitude, and
depth.lat - latitude in decimal degreeslon - longitude in decimal degreesdepth - in km (positive down)IllegalArgumentException - if any supplied values are out of rangeCoordinatespublic static Location fromString(String s)
Location by parsing the supplied String.
Method is intended for use with the result of toString().s - string to parseNumberFormatException - if s is unparseableIndexOutOfBoundsException - if s contains fewer than 3
comma-separated values; any additional values in the suppied string
are ignoredtoString(),
stringConverter()public double depth()
Location in km.public double lat()
Location in decimal degrees.public double lon()
Location in decimal degrees.public double latRad()
Location in radians.public double lonRad()
Location in radians.public String toString()
toString in class ObjectfromString(String),
stringConverter()public static Converter<Location,String> stringConverter()
Converter that converts between Locations and
Strings.
Calls to converter.reverse().convert(String) will throw a
NumberFormatException if the values in the supplied string are
unparseable; or an IndexOutOfBoundsException if the supplied string
contains fewer than 3 comma-separated values; any additional values in the
suppied string are ignored.
public int compareTo(Location loc)
Location to another and sort first by latitude, then
by longitude. When sorting a list of Locations, the resultant
ordering is left-to-right, bottom-to-top.compareTo in interface Comparable<Location>loc - Location to compare this toLocation is less than, equal to, or greater than the
specified Location.