diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 1138:d90f5bfa3ddf

Fix profile loading of cross section diagram. flys-artifacts/trunk@2659 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 07 Sep 2011 07:48:03 +0000
parents 073c36bb94ed
children 6d9b08b958e2
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Sep 07 07:37:22 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Sep 07 07:48:03 2011 +0000
@@ -655,7 +655,31 @@
      *         in the form {{x1, x2} {y1, y2}} ).
      */
     public double [][] getCrossSectionData() {
-        return getCrossSectionProfile(getCrossSections().get(0).getLines().get(0));
+        logger.info("getCrossSectionData(), also cross_section.km " + getDataAsString("cross_section.km"));
+        double wishKM = 0.0f;
+        try {
+            wishKM = Double.parseDouble(getDataAsString("cross_section.km"));
+        }
+        catch (Exception e) {
+            ;
+        }
+
+        // Get the cross section closest to requested km.
+        //
+        // Naive, linear approach.
+        List<CrossSectionLine> crossSectionLines =
+            getCrossSections().get(0).getLines();
+        CrossSectionLine oldLine = crossSectionLines.get(0);
+        double oldDiff = Math.abs(wishKM - oldLine.getKm().doubleValue());
+        for (CrossSectionLine line: crossSectionLines) {
+            double diff = Math.abs(wishKM - line.getKm().doubleValue());
+            if (diff > oldDiff) {
+                break;
+            }
+            oldDiff = diff;
+            oldLine = line;
+        }
+        return getCrossSectionProfile(oldLine);
     }
 
 

http://dive4elements.wald.intevation.org