changeset 1049:778d86255d76

Corrected the distance calculation of a 'Horizontalprofil' and adjusted the gap detection according to these changes (issue287). gnv-artifacts/trunk@1122 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 25 May 2010 13:57:48 +0000
parents b5d852991cbf
children 7f3154331bc1
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java
diffstat 2 files changed, 25 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Mon May 24 17:07:26 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Tue May 25 13:57:48 2010 +0000
@@ -1,3 +1,11 @@
+2010-05-25  Ingo Weinzierl <ingo.weinzierl@intevation.de>
+
+	  Issue287
+
+	* src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java:
+	  Corrected the distance calculation of a 'Horizontal Profil' and adjusted
+	  the gap detection according to these changes.
+
 2010-05-24  Ingo Weinzierl <ingo_weinzierl@web.de>
 
 	  Issue290
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java	Mon May 24 17:07:26 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java	Tue May 25 13:57:48 2010 +0000
@@ -53,7 +53,9 @@
      * The first point in a HorizontalProfileChart. It is used to calculate the
      * distance between the currently processed point an the start.
      */
-    private        Point     firstPoint;
+    protected Point lastPoint;
+
+    protected double distance = 0d;
 
     /**
      * Constructor used to create horizontal profile charts.
@@ -147,23 +149,20 @@
 
     @Override
     protected void addValue(Result row, Series series) {
-        double distance = 0;
-
         try {
             Point point = (Point) wktReader.read(row.getString("SHAPE"));
-            if (firstPoint != null) {
-                distance = DistanceCalculator.calculateDistance(
-                    firstPoint, point
+            if (lastPoint != null) {
+                distance += DistanceCalculator.calculateDistance(
+                    lastPoint, point
                 );
             }
-            else {
-                firstPoint = point;
-            }
 
             ((XYSeries) series).add(
                 distance,
                 row.getDouble("YORDINATE")
             );
+
+            lastPoint = point;
         }
         catch(ParseException pe) {
             log.warn("No data found while parsing.");
@@ -175,8 +174,9 @@
     protected void addSeries(Series series, String label, int idx) {
         super.addSeries(series, label, idx);
 
-        // reset firstPoint for next series
-        firstPoint = null;
+        // reset lastPoint and distance of the last series
+        lastPoint = null;
+        distance  = 0;
     }
 
 
@@ -280,26 +280,19 @@
         Point  lastPoint    = null;
         Point  currentPoint = null;
 
-        try {
-            firstPoint = getPoint(results[0]);
-        }
-        catch (ParseException pe) {
-            log.error("Unable to parse start point for gap detection.");
-            return;
-        }
-
+        double distance    = 0;
+        double distanceOld = 0;
         for (int i = startPos+1; i < endPos; i++) {
             try {
                 last         = results[i-1].getInteger(axis);
                 lastPoint    = getPoint(results[i-1]);
                 current      = results[i].getInteger(axis);
                 currentPoint = getPoint(results[i]);
-                double distance = DistanceCalculator.calculateDistance(
-                    firstPoint,
+
+                distanceOld  = distance;
+                distance    += DistanceCalculator.calculateDistance(
+                    lastPoint,
                     currentPoint);
-                double distanceOld = DistanceCalculator.calculateDistance(
-                    firstPoint,
-                    lastPoint);
 
                 boolean detected = gridDetection(last, current);
 

http://dive4elements.wald.intevation.org