diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 1975:b30e1710df1d

Server-side of interactive cross-section diagrams. flys-artifacts/trunk@3394 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 13 Dec 2011 09:10:48 +0000
parents cdeb31ef20a1
children bf62cc7052d4
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Tue Dec 13 08:56:52 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Tue Dec 13 09:10:48 2011 +0000
@@ -672,96 +672,14 @@
 
 
     /**
-     * Get CrossSectionLine spatially closest to what is specified in the data
-     * "cross_section.km" (and from "cross_section.index").
-     *
-     * @return CrossSectionLine closest to "cross_section.km".
-     */
-    protected CrossSectionLine searchCrossSectionKmLine() {
-        double wishKM = 0.0f;
-        try {
-            wishKM = Double.parseDouble(getDataAsString("cross_section.km"));
-        }
-        catch (Exception e) {
-            logger.warn("Exception when parsing cross_section.km", e);
-        }
-
-        int crossSectionIdx = 0;
-
-        List<CrossSection> sections = getCrossSections();
-        if (sections.size() < crossSectionIdx) {
-            logger.error("Cross-section not found: " + crossSectionIdx);
-            return null;
-        }
-        if (sections.size() == 0
-            || sections.get(crossSectionIdx).getLines().size() == 0)
-        {
-            return null;
-        }
-
-        // Get the cross section closest to requested km.
-        // Naive, linear approach.
-        List<CrossSectionLine> crossSectionLines =
-            sections.get(crossSectionIdx).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 oldLine;
-    }
-
-
-    /**
-     * Get km for which a CrossSection is actually available (this may vary
-     * from the user picked "cross_section.km" data).
-     *
-     * @return km for which cross section is calculated.
-     */
-    public double getCrossSectionSnapKm() {
-        // Note that this is this triggers a linear search.
-        CrossSectionLine line = searchCrossSectionKmLine();
-        if (line == null) {
-            logger.warn("No Cross Section for given km found.");
-            return 0.0f;
-        }
-        else {
-            return line.getKm().doubleValue();
-        }
-    }
-
-
-    /**
-     * Get points of Profile of cross section.
-     *
-     * @return an array holding coordinates of points of profile (
-     *         in the form {{x1, x2} {y1, y2}} ).
-     */
-    public double [][] getCrossSectionData() {
-        logger.info("getCrossSectionData() for cross_section.km "
-            + getDataAsString("cross_section.km"));
-        CrossSectionLine line = searchCrossSectionKmLine();
-
-        return line != null
-               ? line.fetchCrossSectionProfile()
-               : null;
-    }
-
-
-    /**
      * Get points of line describing the surface of water at cross section.
      *
      * @return an array holding coordinates of points of surface of water (
      *         in the form {{x1, x2} {y1, y2}} ).
      */
-    public double [][] getWaterLines(int idx) {
-        logger.debug("getWaterLines()");
-        CrossSectionLine csl = searchCrossSectionKmLine();
+    public double [][] getWaterLines(int idx, CrossSectionLine csl) {
+        logger.debug("getWaterLines(" + idx + ")");
+
         List<Point2D> points = csl.fetchCrossSectionLinesPoints();
 
         // Need W at km
@@ -780,14 +698,8 @@
         WQKms triple = wqkms[idx];
 
         // Find index of km.
-        double wishKM = 0.0f;
+        double wishKM = csl.getKm().doubleValue();
         int old_idx = 0;
-        try {
-            wishKM = Double.parseDouble(getDataAsString("cross_section.km"));
-        }
-        catch (Exception e) {
-            logger.warn("Exception when trying to get cross_section.km", e);
-        }
 
         if (triple.size() == 0) {
             logger.warn("Calculation of waterline is empty.");
@@ -815,6 +727,7 @@
      * @return list of names of cross-sections.
      */
     public List<String> getCrossSectionNames() {
+        logger.debug("getCrossSectionNames");
         List<String> names = new ArrayList<String>();
 
         for (CrossSection section: getCrossSections()) {

http://dive4elements.wald.intevation.org