org.hermit.geo
Class GeoCalculator

java.lang.Object
  extended by org.hermit.geo.GeoCalculator
All Implemented Interfaces:
GeoConstants
Direct Known Subclasses:
AndoyerCalculator, HaversineCalculator, VincentyCalculator

public abstract class GeoCalculator
extends java.lang.Object
implements GeoConstants

Base class for geographic data calculators. Subclasses of this class provide functions like distance and azimuth calculation; since there are multiple algorithms with very different accuracy and complexity, the user can select which subclass they wish to use.

Author:
Ian Cameron Smith

Nested Class Summary
static class GeoCalculator.Algorithm
          Definition of the algorithm to be used.
 
Nested classes/interfaces inherited from interface org.hermit.geo.GeoConstants
GeoConstants.Ellipsoid
 
Field Summary
 
Fields inherited from interface org.hermit.geo.GeoConstants
EQUATORIAL_RADIUS, MEAN_RADIUS, POLAR_RADIUS
 
Constructor Summary
GeoCalculator()
          Create a calculator using the WGS84 ellipsoid.
GeoCalculator(GeoConstants.Ellipsoid ellip)
          Create a calculator using a given ellipsoid.
 
Method Summary
abstract  Azimuth azimuth(Position p1, Position p2)
          Calculate the azimuth (bearing) from a position to another.
abstract  Distance distance(Position p1, Position p2)
          Calculate the distance between two positions.
abstract  GeoCalculator.Algorithm getAlgorithm()
          Get the algorithm this calculator uses.
static GeoCalculator getCalculator()
          Get the default geodetic calcualtor.
static GeoCalculator.Algorithm getCurrentAlgorithm()
          Get the geodetic calculator in use.
abstract  Distance latDistance(Position p1, double lat)
          Calculate the distance between a position and a given latitude.
abstract  Position offset(Position p1, Distance distance, Azimuth azimuth)
          Calculate a second position given its offset from a given position.
static void setAlgorithm(GeoCalculator.Algorithm algorithm)
          Set the geodetic calculator to use for future calculations.
static void setAlgorithm(GeoCalculator.Algorithm algorithm, GeoConstants.Ellipsoid ellipsoid)
          Set the geodetic calcualtor to use for future calculations.
abstract  Vector vector(Position p1, Position p2)
          Calculate the azimuth and distance from a position to another.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GeoCalculator

public GeoCalculator()
Create a calculator using the WGS84 ellipsoid.


GeoCalculator

public GeoCalculator(GeoConstants.Ellipsoid ellip)
Create a calculator using a given ellipsoid.

Parameters:
ellip - The ellipsoid to use for geodetic calculations.
Method Detail

getCurrentAlgorithm

public static GeoCalculator.Algorithm getCurrentAlgorithm()
Get the geodetic calculator in use.

Returns:
The algorithm currently in use.

setAlgorithm

public static void setAlgorithm(GeoCalculator.Algorithm algorithm)
Set the geodetic calculator to use for future calculations. The default is HAVERSINE.

Parameters:
algorithm - The algorithm to use. If it has a selectable ellipsoid, then the WGS84 ellipsoid will be used.

setAlgorithm

public static void setAlgorithm(GeoCalculator.Algorithm algorithm,
                                GeoConstants.Ellipsoid ellipsoid)
Set the geodetic calcualtor to use for future calculations. The default is HAVERSINE.

Parameters:
algorithm - The algorithm to use.
ellipsoid - If the algorithm has a selectable ellipsoid, then this ellipsoid will be used.

getCalculator

public static GeoCalculator getCalculator()
Get the default geodetic calcualtor.

Returns:
The default geodetic calcualtor.

getAlgorithm

public abstract GeoCalculator.Algorithm getAlgorithm()
Get the algorithm this calculator uses.

Returns:
The algorithm this calculator uses.

distance

public abstract Distance distance(Position p1,
                                  Position p2)
Calculate the distance between two positions.

Parameters:
p1 - Position to calculate the distance from.
p2 - Position to calculate the distance to.
Returns:
The distance between p1 and p2.

latDistance

public abstract Distance latDistance(Position p1,
                                     double lat)
Calculate the distance between a position and a given latitude.

Parameters:
p1 - Position to calculate the distance from.
lat - Latitude in radians to calculate the distance to.
Returns:
The distance of this Position from lat.

azimuth

public abstract Azimuth azimuth(Position p1,
                                Position p2)
Calculate the azimuth (bearing) from a position to another.

Parameters:
p1 - Position to calculate the distance from.
p2 - Position to calculate the distance to.
Returns:
The azimuth of pos from this Position.

vector

public abstract Vector vector(Position p1,
                              Position p2)
Calculate the azimuth and distance from a position to another. This function may be faster than calling azimuth(p1, p2) and distance(p1, p2), if both parts are required.

Parameters:
p1 - Position to calculate the vector from.
p2 - Position to calculate the vector to.
Returns:
The Vector from p1 to p2.

offset

public abstract Position offset(Position p1,
                                Distance distance,
                                Azimuth azimuth)
Calculate a second position given its offset from a given position.

Parameters:
p1 - Position to calculate from.
distance - The Distance to the desired position.
azimuth - The Azimuth to the desired position.
Returns:
The position given by the azimuth and distance from p1. Returns null if the result could not be computed.