com.mizar.geodesy
Class GeodesyUtils

java.lang.Object
  extended by com.mizar.geodesy.GeodesyUtils

public class GeodesyUtils
extends java.lang.Object

This class provides methods to compute distance and area from geographic coordinates. As such the precision is based on global averages and the results are not suitable for engineering purposes. Results will be particularly suspect when applied to small areas.


Field Summary
protected static org.apache.commons.logging.Log _Logger
           
static double AUTHALIC_RADIUS
           
static double EQUITORIAL_RADIUS
           
static double MEAN_RADIUS
           
static double POLAR_RADIUS
           
 
Constructor Summary
protected GeodesyUtils()
           
 
Method Summary
static double areaHaversine(double[] ordinates)
          This is a very rough computation of area based on the area of a spherical polygon using an interpolated radius of the earth from the median latitude.
static double[] decodeKey(long key)
           
static double[] decodeKey(java.lang.String key)
           
static double distanceHaversine(double[] ordinates)
           
static double distanceHaversine(double[] latLong1, double[] latLong2)
           
static double distanceHaversine(double lat1, double lon1, double lat2, double lon2)
          Taken from Javascript code written by Chris Veness (c) 2002-2009 Returns distance in kilometers between two geographic points.
static double distanceHaversine(long key1, long key2)
           
static double distanceHaversine(java.lang.String key1, java.lang.String key2)
           
static long encodeLongKey(double lat, double lon)
          The purpose is to create scalar keys for node locations that can be stored in a database and quickly found.
static java.lang.String encodeStringKey(double lat, double lon)
          The purpose is to create scalar keys for node locations that can be stored in a database and quickly found.
static void main(java.lang.String[] args)
           
static double veryQuickRadius(double latitude)
          The method returns a very crude approximation of the radius of the earth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_Logger

protected static org.apache.commons.logging.Log _Logger

EQUITORIAL_RADIUS

public static final double EQUITORIAL_RADIUS
See Also:
Constant Field Values

POLAR_RADIUS

public static final double POLAR_RADIUS
See Also:
Constant Field Values

MEAN_RADIUS

public static final double MEAN_RADIUS
See Also:
Constant Field Values

AUTHALIC_RADIUS

public static final double AUTHALIC_RADIUS
See Also:
Constant Field Values
Constructor Detail

GeodesyUtils

protected GeodesyUtils()
Method Detail

distanceHaversine

public static double distanceHaversine(double[] ordinates)
Parameters:
ordinates - a two dimensional array of geographic ordinates arranged as {long,lat,long,lat,...}
Returns:
the length of the polyline in kilometers
See Also:
distanceHaversine(double,double,double,double)

distanceHaversine

public static double distanceHaversine(double[] latLong1,
                                       double[] latLong2)
Parameters:
latLong1 -
latLong2 -
Returns:
the distance between point1 and point2 in kilometers.
See Also:
distanceHaversine(double,double,double,double)

distanceHaversine

public static double distanceHaversine(double lat1,
                                       double lon1,
                                       double lat2,
                                       double lon2)
Taken from Javascript code written by Chris Veness (c) 2002-2009 Returns distance in kilometers between two geographic points.

Parameters:
lat1 - utmNorthing (aka Y) ordinate of first point
lon1 - utmEasting (aka X) ordinate of first point
lat2 - utmNorthing (aka Y) ordinate of second point
lon2 - utmEasting (aka X) ordinate of second point
Returns:

distanceHaversine

public static double distanceHaversine(long key1,
                                       long key2)
Parameters:
key1 - a key generated with GeodesyUtils.encodeLongKey
key2 - a key generated with GeodesyUtils.encodeLongKey
Returns:
distance between locations in kilometers

distanceHaversine

public static double distanceHaversine(java.lang.String key1,
                                       java.lang.String key2)
Parameters:
key1 - a key generated with GeodesyUtils.encodeStringKey
key2 - a key generated with GeodesyUtils.encodeStringKey
Returns:
distance between locations in kilometers

veryQuickRadius

public static double veryQuickRadius(double latitude)
The method returns a very crude approximation of the radius of the earth

Parameters:
latitude - must fall within the range 0 to 90 (not checked)
Returns:
a rough approximation of the radius of the earth at latitude

areaHaversine

public static double areaHaversine(double[] ordinates)
This is a very rough computation of area based on the area of a spherical polygon using an interpolated radius of the earth from the median latitude. If ordinates has a length of 4 it will be assumed to be an MBR range

Parameters:
ordinates - a two dimensional array of geographic ordinates arranged as {long,lat,long,lat,...}
Returns:
the area in square kilometers

encodeLongKey

public static long encodeLongKey(double lat,
                                 double lon)
The purpose is to create scalar keys for node locations that can be stored in a database and quickly found.

Parameters:
lon - a value between -90 and 90
lat - a value between -180 and 180
Returns:
a large long
See Also:
Point.makeLongKey(double, double, double, double, int, long)

decodeKey

public static double[] decodeKey(long key)
Parameters:
key - a long created with GeoesyUtils.makLongKey
Returns:
a double array with the longitude and latitude (utmEasting, utmNorthing) in that order
See Also:
Point.decodeLongKey(long, double, double, int, long)

encodeStringKey

public static java.lang.String encodeStringKey(double lat,
                                               double lon)
The purpose is to create scalar keys for node locations that can be stored in a database and quickly found.

Parameters:
lon - a value between -90 and 90
lat - a value between -180 and 180
Returns:
a radix 36 encoded key
See Also:
Point.makeStringKey(double, double, int)

decodeKey

public static double[] decodeKey(java.lang.String key)
Parameters:
key - a long created with GeoesyUtils.makeStringKey
Returns:
a double array with the longitude and latitude (utmEasting, utmNorthing) in that order
See Also:
Point.decodeStringKey(java.lang.String, int)

main

public static void main(java.lang.String[] args)