changeset 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 5d050f6de41d
children 8ae596be276b
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChartFactory.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java gnv-artifacts/src/main/java/de/intevation/gnv/utils/DistanceCalculator.java gnv-artifacts/src/test/java/de/intevation/gnv/artifacts/util/DistanceCalculatorTestCase.java
diffstat 5 files changed, 109 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Fri Oct 16 09:31:25 2009 +0000
+++ b/gnv-artifacts/ChangeLog	Fri Oct 16 12:37:00 2009 +0000
@@ -1,5 +1,15 @@
 2009-10-16  Tim Englich  <tim.englich@intevation.de>
 
+	* src/test/java/de/intevation/gnv/artifacts/util/DistanceCalculatorTestCase.java (testDistanceCalculator): 
+	  Added Testcase for the DistanceCalculation
+	* src/main/java/de/intevation/gnv/chart/HorizontalProfileChartFactory.java (createXYSeries): 
+	* src/main/java/de/intevation/gnv/utils/DistanceCalculator.java (calculateDistance): 
+	  Added Calculation of the Distance in the unit km for Geodetic-Coordinates according to the Specification GT_0030.004
+	* src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java (HorizontalProfileOutputTransition): 
+	  Changed Domainlable for Horizintalprfiles according to the Specification GT_0030.004
+	  
+2009-10-16  Tim Englich  <tim.englich@intevation.de>
+	
 	* src/test/ressources/queries.properties:
 	  The Levelnumber of Meshes will also be visualized in the choose of depth GT_0020.0020
 
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChartFactory.java	Fri Oct 16 09:31:25 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChartFactory.java	Fri Oct 16 12:37:00 2009 +0000
@@ -28,6 +28,7 @@
 import de.intevation.gnv.chart.exception.TechnicalChartException;
 import de.intevation.gnv.geobackend.base.Result;
 import de.intevation.gnv.transition.describedata.KeyValueDescibeData;
+import de.intevation.gnv.utils.DistanceCalculator;
 
 /**
  * 
@@ -69,6 +70,7 @@
         if (sDebug)
             sLogger.debug("createXYSeries()");
         XYSeries series = new XYSeries(seriesName);
+        DistanceCalculator dc = new DistanceCalculator();
         try {
             Point lastPoint = null;
             double distance = 0;
@@ -79,7 +81,7 @@
                 if (i >= pStart && i <= pEnd) {
                     Point p = (Point)wktReader.read(lRow.getString("SHAPE"));
                     if (lastPoint != null) {
-                        distance = distance +p.distance(lastPoint); // TODO in Meter umrechnen
+                        distance = distance + dc.calculateDistance(lastPoint, p);
                     }
                     lastPoint = p;
                     double yValue = lRow.getDouble("YORDINATE");
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java	Fri Oct 16 09:31:25 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java	Fri Oct 16 12:37:00 2009 +0000
@@ -47,7 +47,7 @@
      */
     public HorizontalProfileOutputTransition() {
         super();
-        super.domainLable = "Messungen [m]";
+        super.domainLable = "Distance [km]";
     }
 
     /**
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/DistanceCalculator.java	Fri Oct 16 12:37:00 2009 +0000
@@ -0,0 +1,65 @@
+/**
+ *
+ */
+package de.intevation.gnv.utils;
+
+import com.vividsolutions.jts.geom.Point;
+
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public class DistanceCalculator {
+
+    private final static double flattening = 1.0 / 298.257233563;
+    
+    private final static double earthRadius = 6378137.0 / 1000.0 ;
+    
+    /**
+     * Constructor
+     */
+    public DistanceCalculator() {
+    }
+    
+    public double calculateDistance(Point p1, Point p2){
+        double resultValue = 0.0;
+        
+        double b1 = p1.getY();
+        double b2 = p2.getY();
+        
+        double l1 = p1.getX();
+        double l2 = p2.getX();
+        
+        
+        double F = (b1 + b2) / 2.0;
+        double G = (b1 - b2) / 2.0;
+        double l = (l1 - l2) / 2.0;
+        
+        F = (Math.PI / 180.0) * F;
+        G = (Math.PI / 180.0) * G;
+        l = (Math.PI / 180.0) * l;
+        
+        double S = ((Math.sin(G) * Math.sin(G)) * ((Math.cos(l) * Math.cos(l))))+
+                   ((Math.cos(F) * Math.cos(F)) * ((Math.sin(l) * Math.sin(l))));
+        
+        double C = ((Math.cos(G) * Math.cos(G)) * ((Math.cos(l) * Math.cos(l))))+
+                   ((Math.sin(F) * Math.sin(F)) * ((Math.sin(l) * Math.sin(l))));
+        
+        double w = Math.atan(Math.sqrt((S/C)));
+        
+        double D = 2.0 * w * earthRadius;
+        
+        double R = Math.sqrt((S*C)) / w;
+        
+        double H1 = (3.0 * R - 1.0 ) / (2.0 * C);
+        double H2 = (3.0 * R + 1.0 ) / (2.0 * S);
+        
+        resultValue = D * (1 + (flattening * H1 * (Math.sin(F) * Math.sin(F)) * 
+                                                  (Math.cos(G) * Math.cos(G))) - 
+                           (flattening * H2 * (Math.cos(F) * Math.cos(F)) * 
+                                              (Math.sin(G) * Math.sin(G))));
+        
+        return resultValue;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/test/java/de/intevation/gnv/artifacts/util/DistanceCalculatorTestCase.java	Fri Oct 16 12:37:00 2009 +0000
@@ -0,0 +1,30 @@
+package de.intevation.gnv.artifacts.util;
+
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.GeometryFactory;
+import com.vividsolutions.jts.geom.Point;
+
+import de.intevation.gnv.utils.DistanceCalculator;
+
+import junit.framework.TestCase;
+
+public class DistanceCalculatorTestCase extends TestCase {
+
+    public DistanceCalculatorTestCase(String name) {
+        super(name);
+    }
+    
+    public void testDistanceCalculator(){
+        
+        GeometryFactory gf = new GeometryFactory();
+        
+        // Distance between Berlin and Tokio
+        Point p1 = gf.createPoint(new Coordinate(13.4000, 52.5167));
+        Point p2 = gf.createPoint(new Coordinate(139.7667, 35.7000));
+        
+        double s = new DistanceCalculator().calculateDistance(p1, p2);
+        
+        assertEquals(8941.201227763724, s);
+    }
+
+}

http://dive4elements.wald.intevation.org