comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/DistanceCalculator.java @ 185:5fc8f41669a6

Added Calculation of the Distance in the unit km for Geodetic-Coordinates according to the Specification GT_0030.004 gnv-artifacts/trunk@229 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Fri, 16 Oct 2009 12:37:00 +0000
parents
children da1499a464b9
comparison
equal deleted inserted replaced
184:5d050f6de41d 185:5fc8f41669a6
1 /**
2 *
3 */
4 package de.intevation.gnv.utils;
5
6 import com.vividsolutions.jts.geom.Point;
7
8 /**
9 * @author Tim Englich <tim.englich@intevation.de>
10 *
11 */
12 public class DistanceCalculator {
13
14 private final static double flattening = 1.0 / 298.257233563;
15
16 private final static double earthRadius = 6378137.0 / 1000.0 ;
17
18 /**
19 * Constructor
20 */
21 public DistanceCalculator() {
22 }
23
24 public double calculateDistance(Point p1, Point p2){
25 double resultValue = 0.0;
26
27 double b1 = p1.getY();
28 double b2 = p2.getY();
29
30 double l1 = p1.getX();
31 double l2 = p2.getX();
32
33
34 double F = (b1 + b2) / 2.0;
35 double G = (b1 - b2) / 2.0;
36 double l = (l1 - l2) / 2.0;
37
38 F = (Math.PI / 180.0) * F;
39 G = (Math.PI / 180.0) * G;
40 l = (Math.PI / 180.0) * l;
41
42 double S = ((Math.sin(G) * Math.sin(G)) * ((Math.cos(l) * Math.cos(l))))+
43 ((Math.cos(F) * Math.cos(F)) * ((Math.sin(l) * Math.sin(l))));
44
45 double C = ((Math.cos(G) * Math.cos(G)) * ((Math.cos(l) * Math.cos(l))))+
46 ((Math.sin(F) * Math.sin(F)) * ((Math.sin(l) * Math.sin(l))));
47
48 double w = Math.atan(Math.sqrt((S/C)));
49
50 double D = 2.0 * w * earthRadius;
51
52 double R = Math.sqrt((S*C)) / w;
53
54 double H1 = (3.0 * R - 1.0 ) / (2.0 * C);
55 double H2 = (3.0 * R + 1.0 ) / (2.0 * S);
56
57 resultValue = D * (1 + (flattening * H1 * (Math.sin(F) * Math.sin(F)) *
58 (Math.cos(G) * Math.cos(G))) -
59 (flattening * H2 * (Math.cos(F) * Math.cos(F)) *
60 (Math.sin(G) * Math.sin(G))));
61
62 return resultValue;
63 }
64
65 }

http://dive4elements.wald.intevation.org