KosherJava Zmanim Homepage

net.sourceforge.zmanim.util
Class GeoLocation

java.lang.Object
  extended by net.sourceforge.zmanim.util.GeoLocation
All Implemented Interfaces:
Cloneable

public class GeoLocation
extends Object
implements Cloneable

A class that contains location information such as latitude and longitude required for astronomical calculations. The elevation field is not used by most calculation engines and would be ignored if set. Check the documentation for specific implementations of the AstronomicalCalculator to see if elevation is calculated as part o the algorithm.

Version:
1.1
Author:
© Eliyahu Hershfeld 2004 - 2011

Constructor Summary
GeoLocation()
          Default GeoLocation constructor will set location to the Prime Meridian at Greenwich, England and a TimeZone of GMT.
GeoLocation(String name, double latitude, double longitude, double elevation, TimeZone timeZone)
          GeoLocation constructor with parameters for all required fields.
GeoLocation(String name, double latitude, double longitude, TimeZone timeZone)
          GeoLocation constructor with parameters for all required fields.
 
Method Summary
 Object clone()
          An implementation of the Object.clone() method that creates a deep copy of the object.
 boolean equals(Object object)
           
 double getElevation()
          Method to get the elevation in Meters.
 double getGeodesicDistance(GeoLocation location)
          Calculate geodesic distance in Meters between this Object and a second Object passed to this method using Thaddeus Vincenty's inverse formula See T Vincenty, "Direct and Inverse Solutions of Geodesics on the Ellipsoid with application of nested equations", Survey Review, vol XXII no 176, 1975
 double getGeodesicFinalBearing(GeoLocation location)
          Calculate the final geodesic bearing between this Object and a second Object passed to this method using Thaddeus Vincenty's inverse formula See T Vincenty, "Direct and Inverse Solutions of Geodesics on the Ellipsoid with application of nested equations", Survey Review, vol XXII no 176, 1975
 double getGeodesicInitialBearing(GeoLocation location)
          Calculate the initial geodesic bearing between this Object and a second Object passed to this method using Thaddeus Vincenty's inverse formula See T Vincenty, "Direct and Inverse Solutions of Geodesics on the Ellipsoid with application of nested equations", Survey Review, vol XXII no 176, 1975
 double getLatitude()
           
 long getLocalMeanTimeOffset()
          A method that will return the location's local mean time offset in milliseconds from local standard time.
 String getLocationName()
           
 double getLongitude()
           
 double getRhumbLineBearing(GeoLocation location)
          Returns the rhumb line bearing from the current location to the GeoLocation passed in.
 double getRhumbLineDistance(GeoLocation location)
          Returns the rhumb line distance from the current location to the GeoLocation passed in.
 TimeZone getTimeZone()
           
 int hashCode()
           
 void setElevation(double elevation)
          Method to set the elevation in Meters above sea level.
 void setLatitude(double latitude)
          Method to set the latitude.
 void setLatitude(int degrees, int minutes, double seconds, String direction)
          Method to set the latitude in degrees, minutes and seconds.
 void setLocationName(String name)
           
 void setLongitude(double longitude)
          Method to set the longitude in a double format.
 void setLongitude(int degrees, int minutes, double seconds, String direction)
          Method to set the longitude in degrees, minutes and seconds.
 void setTimeZone(TimeZone timeZone)
          Method to set the TimeZone.
 String toString()
           
 String toXML()
          A method that returns an XML formatted String representing the serialized Object.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GeoLocation

public GeoLocation(String name,
                   double latitude,
                   double longitude,
                   TimeZone timeZone)
GeoLocation constructor with parameters for all required fields.

Parameters:
name - The location name for display use such as "Lakewood, NJ"
latitude - the latitude in a double format such as 40.095965 for Lakewood, NJ
Note: For latitudes south of the equator, a negative value should be used.
longitude - double the longitude in a double format such as -74.222130 for Lakewood, NJ.
Note: For longitudes east of the Prime Meridian (Greenwich), a negative value should be used.
timeZone - the TimeZone for the location.

GeoLocation

public GeoLocation(String name,
                   double latitude,
                   double longitude,
                   double elevation,
                   TimeZone timeZone)
GeoLocation constructor with parameters for all required fields.

Parameters:
name - The location name for display use such as "Lakewood, NJ"
latitude - the latitude in a double format such as 40.095965 for Lakewood, NJ
Note: For latitudes south of the equator, a negative value should be used.
longitude - double the longitude in a double format such as -74.222130 for Lakewood, NJ.
Note: For longitudes east of the Prime Meridian (Greenwich), a negative value should be used.
elevation - the elevation above sea level in Meters. Elevation is not used in most algorithms used for calculating sunrise and set.
timeZone - the TimeZone for the location.

GeoLocation

public GeoLocation()
Default GeoLocation constructor will set location to the Prime Meridian at Greenwich, England and a TimeZone of GMT. The longitude will be set to 0 and the latitude will be 51.4772 to match the location of the Royal Observatory, Greenwich . No daylight savings time will be used.

Method Detail

getElevation

public double getElevation()
Method to get the elevation in Meters.

Returns:
Returns the elevation in Meters.

setElevation

public void setElevation(double elevation)
Method to set the elevation in Meters above sea level.

Parameters:
elevation - The elevation to set in Meters. An IllegalArgumentException will be thrown if the value is a negative.

setLatitude

public void setLatitude(double latitude)
Method to set the latitude.

Parameters:
latitude - The degrees of latitude to set. The values should be between -90° and 90°. An IllegalArgumentException will be thrown if the value exceeds the limit. For example 40.095965 would be used for Lakewood, NJ. Note: For latitudes south of the equator, a negative value should be used.

setLatitude

public void setLatitude(int degrees,
                        int minutes,
                        double seconds,
                        String direction)
Method to set the latitude in degrees, minutes and seconds.

Parameters:
degrees - The degrees of latitude to set between -90 and 90. An IllegalArgumentException will be thrown if the value exceeds the limit. For example 40 would be used for Lakewood, NJ.
minutes - minutes of arc
seconds - seconds of arc
direction - N for north and S for south. An IllegalArgumentException will be thrown if the value is not S or N.

getLatitude

public double getLatitude()
Returns:
Returns the latitude.

setLongitude

public void setLongitude(double longitude)
Method to set the longitude in a double format.

Parameters:
longitude - The degrees of longitude to set in a double format between -180° and 180°. An IllegalArgumentException will be thrown if the value exceeds the limit. For example -74.2094 would be used for Lakewood, NJ. Note: for longitudes east of the Prime Meridian (Greenwich) a negative value should be used.

setLongitude

public void setLongitude(int degrees,
                         int minutes,
                         double seconds,
                         String direction)
Method to set the longitude in degrees, minutes and seconds.

Parameters:
degrees - The degrees of longitude to set between -180 and 180. An IllegalArgumentException will be thrown if the value exceeds the limit. For example -74 would be used for Lakewood, NJ. Note: for longitudes east of the Prime Meridian (Greenwich) a negative value should be used.
minutes - minutes of arc
seconds - seconds of arc
direction - E for east of the Prime Meridian or W for west of it. An IllegalArgumentException will be thrown if the value is not E or W.

getLongitude

public double getLongitude()
Returns:
Returns the longitude.

getLocationName

public String getLocationName()
Returns:
Returns the location name.

setLocationName

public void setLocationName(String name)
Parameters:
name - The setter method for the display name.

getTimeZone

public TimeZone getTimeZone()
Returns:
Returns the timeZone.

setTimeZone

public void setTimeZone(TimeZone timeZone)
Method to set the TimeZone. If this is ever set after the GeoLocation is set in the AstronomicalCalendar, it is critical that AstronomicalCalendar.getCalendar().setTimeZone(TimeZone) be called in order for the AstronomicalCalendar to output times in the expected offset. This situation will arise if the AstronomicalCalendar is ever cloned.

Parameters:
timeZone - The timeZone to set.

getLocalMeanTimeOffset

public long getLocalMeanTimeOffset()
A method that will return the location's local mean time offset in milliseconds from local standard time. The globe is split into 360°, with 15° per hour of the day. For a local that is at a longitude that is evenly divisible by 15 (longitude % 15 == 0), at solar noon (with adjustment for the equation of time) the sun should be directly overhead, so a user who is 1° west of this will have noon at 4 minutes after standard time noon, and conversely, a user who is 1° east of the 15° longitude will have noon at 11:56 AM. The offset returned does not account for the Daylight saving time offset since this class is unaware of dates.

Returns:
the offset in milliseconds not accounting for Daylight saving time. A positive value will be returned East of the timezone line, and a negative value West of it.
Since:
1.1

getGeodesicInitialBearing

public double getGeodesicInitialBearing(GeoLocation location)
Calculate the initial geodesic bearing between this Object and a second Object passed to this method using Thaddeus Vincenty's inverse formula See T Vincenty, "Direct and Inverse Solutions of Geodesics on the Ellipsoid with application of nested equations", Survey Review, vol XXII no 176, 1975

Parameters:
location - the destination location

getGeodesicFinalBearing

public double getGeodesicFinalBearing(GeoLocation location)
Calculate the final geodesic bearing between this Object and a second Object passed to this method using Thaddeus Vincenty's inverse formula See T Vincenty, "Direct and Inverse Solutions of Geodesics on the Ellipsoid with application of nested equations", Survey Review, vol XXII no 176, 1975

Parameters:
location - the destination location

getGeodesicDistance

public double getGeodesicDistance(GeoLocation location)
Calculate geodesic distance in Meters between this Object and a second Object passed to this method using Thaddeus Vincenty's inverse formula See T Vincenty, "Direct and Inverse Solutions of Geodesics on the Ellipsoid with application of nested equations", Survey Review, vol XXII no 176, 1975

Parameters:
location - the destination location

getRhumbLineBearing

public double getRhumbLineBearing(GeoLocation location)
Returns the rhumb line bearing from the current location to the GeoLocation passed in.

Parameters:
location - destination location
Returns:
the bearing in degrees

getRhumbLineDistance

public double getRhumbLineDistance(GeoLocation location)
Returns the rhumb line distance from the current location to the GeoLocation passed in.

Parameters:
location - the destination location
Returns:
the distance in Meters

toXML

public String toXML()
A method that returns an XML formatted String representing the serialized Object. Very similar to the toString method but the return value is in an xml format. The format currently used (subject to change) is:
   <GeoLocation>
         <LocationName>Lakewood, NJ</LocationName>
         <Latitude>40.0828&deg</Latitude>
         <Longitude>-74.2094&deg</Longitude>
         <Elevation>0 Meters</Elevation>
         <TimezoneName>America/New_York</TimezoneName>
         <TimeZoneDisplayName>Eastern Standard Time</TimeZoneDisplayName>
         <TimezoneGMTOffset>-5</TimezoneGMTOffset>
         <TimezoneDSTOffset>1</TimezoneDSTOffset>
   </GeoLocation>
 

Returns:
The XML formatted String.

equals

public boolean equals(Object object)
Overrides:
equals in class Object
See Also:
Object.equals(Object)

hashCode

public int hashCode()
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()

clone

public Object clone()
An implementation of the Object.clone() method that creates a deep copy of the object.
Note: If the TimeZone in the clone will be changed from the original, it is critical that AstronomicalCalendar.getCalendar().setTimeZone(TimeZone) is called after cloning in order for the AstronomicalCalendar to output times in the expected offset.

Overrides:
clone in class Object
Since:
1.1
See Also:
Object.clone()

KosherJava Zmanim Homepage

Copyright © 2004 - 2011 Eliyahu Hershfeld. All Rights Reserved. Released under the GPL 2 license