Revision 20098 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/tools/geo/Geo.java

View differences:

Geo.java
1 1
package com.iver.cit.gvsig.fmap.tools.geo;
2 2

  
3 3
/**
4
 * GeoC is a convenience class used for a couple of things. It can
5
 * be used to specifiy constants, and can be used for calculate the geographical area.
4
 * <p>Mathematical utilities to work with geographical data:
5
 *  <ul>
6
 *  <li>Geographical constants:
7
 *   <ul>
8
 *    <li>PI / 2.</li>
9
 *    <li>Degrees per radian.</li>
10
 *    <li>Square miles per spherical degree.</li>
11
 *    <li>Square kilometres per spherical degree.</li>
12
 *    <li>Square metres per spherical degree.</li>
13
 *   </ul>
14
 *  </li>
15
 *  <li>Decimal degrees equivalent to <i>m</i> meters.</li>
16
 *  <li>The area of a spherical polygon in spherical degrees, given the latitudes and longitudes 
17
 *   of <i>n</i> points, according the <a href="http://en.wikipedia.org/wiki/Haversine_formula">Haversine function</a>.
18
 *  </ul>
19
 * </p> 
6 20
 *
7 21
 * @author Vicente Caballero Navarro
8 22
 */
9 23
public class Geo {
10
    public static double HalfPi = 1.5707963267948966192313;
11
    public static double Degree = 57.295779513082320876798; /* degrees per radian */
12
    public static double SqMi = 273218.4; /* Square mi per spherical degree. */
13
    public static double SqKm = 707632.4; /* Square km per spherical degree. */
14
    public static double SqM = 707632400000.0; /* Square M per spherical degree. */
24
	/**
25
	 * <i>PI / 2</i>, having PI = 3.14159265358979323846
26
	 */
27
	public static double HalfPi = 1.5707963267948966192313;
15 28

  
16
    public static double getDecimalDegrees(double m) {
29
    /**
30
     * Degrees per radian.
31
     */
32
	public static double Degree = 57.295779513082320876798; /* degrees per radian */
33

  
34
    /**
35
     *  Square miles per spherical degree.
36
     */
37
	public static double SqMi = 273218.4; /* Square mi per spherical degree. */
38

  
39
    /**
40
     * Square kilometres per spherical degree.
41
     */
42
	public static double SqKm = 707632.4; /* Square km per spherical degree. */
43

  
44
    /**
45
     * Square metres per spherical degree.
46
     */
47
	public static double SqM = 707632400000.0; /* Square M per spherical degree. */
48

  
49

  
50
	/**
51
	 * <p>Gets the decimal degrees equivalent to the <i>m</i> meters.</p>
52
	 * <p>Uses this formula:</br>
53
	 * <b><i>m * R * PI</i></b>, having R = Radius of the Earth at the equator
54
	 * </p>
55
	 * 
56
	 * @param m distance value in meters
57
	 * 
58
	 * @return <i>m</i> * Radius at the equator
59
	 */
60
	public static double getDecimalDegrees(double m) {
17 61
    	///(m*180)/ (6378137.0 * Math.PI)
18 62
    	return (m*8.983152841195214E-6);
19 63
    }
20 64

  
21
    /*  Haversine function: hav(x)= (1-cos(x))/2.  */
22
    private static double hav(double X){
65
    /**
66
     * <p>Operation for calculate the <a href="http://en.wikipedia.org/wiki/Haversine_formula">Haversine function</a>:
67
     *  <b><i>hav(x)= (1-cos(x))/2</i></b>.</p>
68
     * 
69
     * @param X length between the difference of a coordinate of two points
70
     */
71
	private static double hav(double X){
23 72
        return (1.0 - Math.cos(X)) / 2.0;
24 73
    }
25 74

  
26
    /*  Returns the area of a simple spherical polygon in spherical degrees,
27
    given the latitudes and longitudes in Lat and Lon, respectively.
28
    The N data points have indices which range from 0 to N-1.
29
    This don?t work with multipolygons.
30
    */
75
    /**
76
     * <p>Returns the area of a spherical polygon in spherical degrees,
77
     *  given the latitudes and longitudes in <i>lat</i> and <i>lon</i>, respectively.</p>
78
     *
79
     * <p>The <i>n</i> data points have indexes which range from 0 to N-1.</p>
80
     *
81
     * <p>Uses the <a href="http://en.wikipedia.org/wiki/Haversine_formula">Haversine function</a> for calculating the
82
     *  spherical area of the polygon.</p>
83
     *  
84
     * @param lat latitude of the vertexes <i>(must be in radians)</i>
85
     * @param lon longitude of the vertexes <i>(must be in radians)</i>
86
     * @param n number of vertexes in the polygon
87
     * 
88
     * @return the area of a spherical polygon in spherical degrees
89
     */
31 90
    public static double sphericalPolyArea(double[] lat, double[] lon, int n) {
32 91
        int j;
33 92
        int k;

Also available in: Unified diff