org.opensha.commons.geo
Class Location

java.lang.Object
  extended by org.opensha.commons.geo.Location
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<Location>, XMLSaveable
Direct Known Subclasses:
Vertex

public class Location
extends java.lang.Object
implements java.io.Serializable, XMLSaveable, java.lang.Cloneable, java.lang.Comparable<Location>

A 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 OpenSHA is for depth to be positive-down, always. All utility methods in this package assume this to be the case.

For computational cenvenience, latitude and longitude values are converted and stored internally in radians. Special get***Rad() methods are provided to access this native format.

Location instances are immutable.

Version:
$Id: Location.java 8034 2011-07-07 15:35:54Z pmpowers $
Author:
Peter Powers, Sid Hellman, Steven W. Rock
See Also:
Serialized Form

Field Summary
static java.lang.String XML_METADATA_DEPTH
           
static java.lang.String XML_METADATA_LATITUDE
           
static java.lang.String XML_METADATA_LONGITUDE
           
static java.lang.String XML_METADATA_NAME
           
 
Constructor Summary
Location(double lat, double lon)
          Constructs a new Location with the supplied latitude and longitude and sets the depth to 0.
Location(double lat, double lon, double depth)
          Constructs a new Location with the supplied latitude, longitude, and depth values.
 
Method Summary
 Location clone()
           
 int compareTo(Location loc)
          Compares this Location to another and sorts first by latitude, then by longitude.
 boolean equals(java.lang.Object obj)
           
static Location fromXMLMetadata(Element root)
           
 double getDepth()
          Returns the depth of this Location.
 double getLatitude()
          Returns the latitude of this Location.
 double getLatRad()
          Returns the latitude of this Location.
 double getLongitude()
          Returns the longitude of this Location.
 double getLonRad()
          Returns the longitude of this Location.
 int hashCode()
           
 java.lang.String toKML()
          Returns this Location formatted as a "lon,lat,depth" String for use in KML documents.
 java.lang.String toString()
           
 Element toXMLMetadata(Element root)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

XML_METADATA_NAME

public static final java.lang.String XML_METADATA_NAME
See Also:
Constant Field Values

XML_METADATA_LONGITUDE

public static final java.lang.String XML_METADATA_LONGITUDE
See Also:
Constant Field Values

XML_METADATA_LATITUDE

public static final java.lang.String XML_METADATA_LATITUDE
See Also:
Constant Field Values

XML_METADATA_DEPTH

public static final java.lang.String XML_METADATA_DEPTH
See Also:
Constant Field Values
Constructor Detail

Location

public Location(double lat,
                double lon)
Constructs a new Location with the supplied latitude and longitude and sets the depth to 0.

Parameters:
lat - latitude in decimal degrees to set
lon - longitude in decimal degrees to set
Throws:
java.lang.IllegalArgumentException - if any supplied values are out of range
See Also:
GeoTools

Location

public Location(double lat,
                double lon,
                double depth)
Constructs a new Location with the supplied latitude, longitude, and depth values.

Parameters:
lat - latitude in decimal degrees to set
lon - longitude in decimal degrees to set
depth - in km to set (positive down)
Throws:
java.lang.IllegalArgumentException - if any supplied values are out of range
See Also:
GeoTools
Method Detail

getDepth

public double getDepth()
Returns the depth of this Location.

Returns:
the Location depth in km

getLatitude

public double getLatitude()
Returns the latitude of this Location.

Returns:
the Location latitude in decimal degrees

getLongitude

public double getLongitude()
Returns the longitude of this Location.

Returns:
the Location longitude in decimal degrees

getLatRad

public double getLatRad()
Returns the latitude of this Location.

Returns:
the Location latitude in radians

getLonRad

public double getLonRad()
Returns the longitude of this Location.

Returns:
the Location longitude in radians

toKML

public java.lang.String toKML()
Returns this Location formatted as a "lon,lat,depth" String for use in KML documents. This differs from toString() in that the output lat-lon order are reversed.

Returns:
the location as a String for use with KML markup

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

clone

public Location clone()
Overrides:
clone in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

compareTo

public int compareTo(Location loc)
Compares this Location to another and sorts first by latitude, then by longitude. When sorting a list of randomized but evenly spaced grid of Locations, the resultant ordering will be left to right across rows of uniform latitude, ascending to the leftmost next higher latitude at the end of each row (left-to-right, bottom-to-top).

Specified by:
compareTo in interface java.lang.Comparable<Location>
Parameters:
loc - Location to compare this to
Returns:
a negative integer, zero, or a positive integer if this Location is less than, equal to, or greater than the specified Location.

toXMLMetadata

public Element toXMLMetadata(Element root)
Specified by:
toXMLMetadata in interface XMLSaveable

fromXMLMetadata

public static Location fromXMLMetadata(Element root)