changeset 4749:3028037c6293

W80Parser: addPoint and lastIdx functions to add a point and find last points index.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 03 Jan 2013 09:59:41 +0100
parents ea8c3e6c9614
children 60398ab6129a
files flys-backend/src/main/java/de/intevation/flys/importer/parsers/W80Parser.java
diffstat 1 files changed, 41 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/W80Parser.java	Thu Jan 03 09:58:49 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/W80Parser.java	Thu Jan 03 09:59:41 2013 +0100
@@ -138,6 +138,47 @@
     public void reset() {
         data.clear();
         currentLine = new ArrayList<XY>();
+        anchor = null;
+    }
+
+
+    /**
+     * Get the Index of the last cross-section lines point.
+     * @return last points index, -1 if not available.
+     */
+    private int lastPointIdx() {
+        if (currentLine == null || currentLine.isEmpty()) {
+            return -1;
+        }
+        XY lastPoint = this.currentLine.get(currentLine.size()-1);
+        return lastPoint.getIndex();
+    }
+
+    /**
+     * Add a Point (YZ,Index) to the current cross section line.
+     * @param y The y coordinate of new point.
+     * @param z The z coordinate of new point.
+     * @param idx Ignored, the parameter of new point.
+     * @return true if point could been added, false otherwise (e.g. not
+     *         parsable y or z values.
+     */
+    private boolean addPoint(double gkr, double gkh, double height, String idx) {
+        // Calculate distance between this and anchor-point.
+        double dx = gkr - anchor.getCoordinate().getX();
+        double dy = gkh - anchor.getCoordinate().getY();
+        double d  = Math.sqrt(dx * dx + dy * dy);
+
+        // We ignore idx, and increment instead.
+        int index;
+        int lastPointIdx = lastPointIdx();
+        if (lastPointIdx <= 0) {
+            index = 1;
+        } else {
+            index = lastPointIdx + 1;
+        }
+
+        currentLine.add(new XY(d, height/1000d, index));
+        return true;
     }
 
 

http://dive4elements.wald.intevation.org