[Dive4elements-commits] [PATCH 3 of 3] W80Parser: Implement linear cascading distance measurements

Wald Commits scm-commit at wald.intevation.org
Wed Jan 16 11:23:16 CET 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1358331779 -3600
# Node ID e9566109bd5b30894d7e6108b350468f1d0747aa
# Parent  94cb955234abc52ba33b12aa8e301bc96b5063ab
W80Parser: Implement linear cascading distance measurements.

diff -r 94cb955234ab -r e9566109bd5b flys-backend/src/main/java/de/intevation/flys/importer/parsers/W80Parser.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/W80Parser.java	Wed Jan 16 11:19:41 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/W80Parser.java	Wed Jan 16 11:22:59 2013 +0100
@@ -62,10 +62,27 @@
     private Anchor anchor;
 
 
+    /**
+     * Reference point for distance calculations, introduced to
+     * deal with bends in the lines.
+     * Array has two entrys: first is GK-Right, second GK-High.
+     */
+    private double[] lastPointGK;
+
+
     /** Measurement date of anchor as listed in w80 file. */
     private Date anchorDate;
 
 
+    private double distanceToLastPoint(double gkr, double gkh) {
+        double dx = gkr - lastPointGK[0];
+        double dy = gkh - lastPointGK[1];
+        double d  = dx*dx + dy*dy;
+
+        return Math.sqrt(d);
+    }
+
+
     /** Trivial constructor. */
     public W80Parser() {
         data = new TreeMap<Double, List<XY>>(EpsilonComparator.CMP);
@@ -134,6 +151,7 @@
         currentLine = new ArrayList<XY>();
         anchor = null;
         anchorDate = null;
+        lastPointGK = new double[] {0d,0d};
     }
 
 
@@ -150,6 +168,15 @@
     }
 
 
+    private double getLastPointX() {
+        if (currentLine == null || currentLine.isEmpty()) {
+            return 0d;
+        }
+        XY lastPoint = this.currentLine.get(currentLine.size()-1);
+        return lastPoint.getX();
+    }
+
+
     /**
      * Add a Point (YZ,Index) to the current cross section line.
      * @param y The y coordinate of new point.
@@ -159,11 +186,9 @@
      *         parsable y or z values.
      */
     private boolean addPoint(double gkr, double gkh, double height, String idx) {
-        // Calculate distance between this and anchor-point.
-        double d = anchor.distance(gkr, gkh);
-
-        // TODO: Scale to have "x==0" e.g. at axis of river.
-        // TODO: Handle "not straight lines."
+        // Calculate distance between this and lst point (add distances).
+        double d = distanceToLastPoint(gkr, gkh);
+        double totalX = getLastPointX() + d;
 
         // We ignore idx, and increment instead.
         int index;
@@ -174,7 +199,9 @@
             index = lastPointIdx + 1;
         }
 
-        currentLine.add(new XY(d, height/1000d, index));
+        this.lastPointGK[0] = gkr;
+        this.lastPointGK[1] = gkh;
+        currentLine.add(new XY(totalX, height/1000d, index));
         return true;
     }
 
@@ -190,10 +217,10 @@
         // negative.
         String pointId = line.substring(0,20);
         String station = line.substring(9,15);
-        String shore   = line.substring(15,17);
+        String shore   = line.substring(15,16);
         // TODO: There is 'station' and a 'shore'-code behind.
         // 1 = left, 2 = right. none = middle
-        String pointIndex = line.substring(17,21);
+        String pointIndex = line.substring(16,21);
         // For GK, first seven digits are of interest.
         String gkRight = line.substring(20,30);
         String gkHigh  = line.substring(30,40);
@@ -221,6 +248,8 @@
         // New (or first) line.
         if (anchor == null || !anchor.sameStation(stationKm)) {
             anchor = new Anchor(gkRightKm, gkHighKm, heightM, stationKm);
+            lastPointGK[0] = gkRightKm;
+            lastPointGK[1] = gkHighKm;
             currentLine = new ArrayList<XY>();
             data.put(stationKm, currentLine);
             currentLine.add(new XY(0d, heightM, 0));


More information about the Dive4elements-commits mailing list