Revision 20100 branches/v10/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. */
15
public static void main(String[] args) {
16
	getDecimalDegrees(1000);
17
}
24
	/**
25
	 * <i>PI / 2</i>, having PI = 3.14159265358979323846
26
	 */
27
	public static double HalfPi = 1.5707963267948966192313;
18 28

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

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

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

  
44
    /**
45
     * Square metres per spherical degree.
46
     */
47
	public static double SqM = 707632400000.0;
48
	
49
	public static void main(String[] args) {
50
		getDecimalDegrees(1000);
51
	}
52

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

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

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

Also available in: Unified diff