diff gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java @ 365:f66088a43ecc

Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation. gnv-artifacts/trunk@440 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 16 Dec 2009 19:29:05 +0000
parents 1ab23cd66870
children 04a242c67fe6
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java	Wed Dec 16 11:58:44 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java	Wed Dec 16 19:29:05 2009 +0000
@@ -7,6 +7,7 @@
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
+import java.util.Locale;
 
 import org.apache.log4j.Logger;
 import org.w3c.dom.Node;
@@ -22,6 +23,10 @@
 
 import de.intevation.gnv.artifacts.cache.CacheFactory;
 
+import de.intevation.gnv.chart.Chart;
+import de.intevation.gnv.chart.ChartLabels;
+import de.intevation.gnv.chart.HorizontalCrossProfileChart;
+
 import de.intevation.gnv.geobackend.base.DefaultResultDescriptor;
 import de.intevation.gnv.geobackend.base.ResultDescriptor;
 import de.intevation.gnv.geobackend.base.DefaultResult;
@@ -49,6 +54,8 @@
 
 import org.apache.commons.math.FunctionEvaluationException;
 
+import org.jfree.chart.ChartTheme;
+
 /**
  * @author Tim Englich <tim.englich@intevation.de>
  *
@@ -87,9 +94,55 @@
         
     }
 
+
+    @Override
+    protected Chart getChart(
+        ChartLabels  chartLables,
+        ChartTheme   theme,
+        Collection   parameters,
+        Collection   measurements,
+        Collection   dates,
+        Collection   result,
+        Locale       locale,
+        String       uuid,
+        boolean      linesVisible,
+        boolean      shapesVisible
+    ) {
+        Chart chart = null;
+        if (CACHE_CHART) {
+            log.info("Try to get horizontalprofilemeshcross chart from cache.");
+            chart = (Chart) getChartFromCache(uuid);
+        }
+
+        if (chart != null)
+            return chart;
+
+        log.info("Chart not in cache yet.");
+        chart = new HorizontalCrossProfileChart(
+            chartLables,
+            theme,
+            parameters,
+            measurements,
+            dates,
+            result,
+            null,
+            locale,
+            linesVisible,
+            shapesVisible
+        );
+        chart.generateChart();
+
+        if (CACHE_CHART) {
+            log.info("Put chart into cache.");
+            purifyChart(chart, uuid);
+        }
+
+        return chart;
+    }
+
     @Override
     protected Collection<Result> getChartResult(String uuid) {
-        log.debug("OutputStateBase.getChartResult");
+        log.debug("HorizontalProfileMeshCrossOutputState.getChartResult");
         Collection<Result> result = null;
         if (CacheFactory.getInstance().isInitialized()) {
             String key = uuid + super.getID();
@@ -117,11 +170,11 @@
 
                         ArrayList missingPoints = new ArrayList();
 
-                        String additionWhere = "TRUE";
+                        String additionWhere = "FEATUREID=FEATUREID";
 
                         for (int i = 0; i < coords.length; i++) {
 
-                            String wkt = "POINT( "+coords[i].x+" "+coords[i].y+" )";
+                            String wkt = toWKT(coords[i]);
 
                             result = queryExecutor.executeQuery(this.ijkQueryID,
                                                                new String[]{meshid,wkt});
@@ -229,6 +282,15 @@
         return result;
     }
 
+
+    @Override
+    protected String createChartSubtitle(Locale locale, String uuid) {
+        log.debug("create chart subtitle for horizontal crossprofile charts.");
+        String subtitle = createTimePeriod(locale, uuid);
+
+        return subtitle;
+    }
+
     private static final String [] COLUMN_BLACKLIST = {
         "MEDIAN.MESHPOINT.JPOSITION",
         "MEDIAN.MESHPOINT.IPOSITION"
@@ -245,11 +307,20 @@
 
     private static boolean different(Result a, Result b, int [] indices) {
         for (int i = 0; i < indices.length; ++i) {
-            Object oa = a.getObject(indices[i]);
-            Object ob = b.getObject(indices[i]);
-            if ((oa == null && ob != null)
-            ||  (oa != null && ob == null)
-            ||  (oa != null && !oa.equals(ob))) {
+            String oa = a.getString(indices[i]);
+            String ob = b.getString(indices[i]);
+
+            if (oa == null && ob == null)  {
+                continue;
+            }
+
+            if (oa == null || ob == null) {
+                return true;
+            }
+
+            if (!oa.equals(ob)) {
+                log.debug("+++++++++++++++ differs ++++++++++++++");
+                log.debug("   " + oa + " != " + ob);
                 return true;
             }
         }
@@ -282,21 +353,25 @@
             this.path       = path;
             this.output     = output;
             this.descriptor = descriptor;
+            points = new ArrayList<Point2d>();
         }
 
         public void finish() {
             if (!points.isEmpty()) {
                 double distance = toKM(
                     DistanceCalculator.calculateDistance(path));
+                
+                if (distance > EPSILON) {
 
-                Interpolation2D.interpolate(
-                    path,
-                    points,
-                    0d,
-                    distance,
-                    steps(distance),
-                    LinearMetrics.INSTANCE, // XXX: This wrong!!!
-                    this);
+                    Interpolation2D.interpolate(
+                        path,
+                        points,
+                        0d,
+                        distance,
+                        INTERPOLATION_STEPS,
+                        LinearMetrics.INSTANCE,
+                        this);
+                }
 
                 points.clear();
             }
@@ -336,6 +411,9 @@
                 else if (colname.equals("YORDINATE")) {
                     result.addColumnValue(j, Double.valueOf(coordinate.z));
                 }
+                else {
+                    result.addColumnValue(j, prototyp.getObject(i));
+                }
                 ++j;
             }
             output.add(result);
@@ -349,14 +427,9 @@
         return (distance * NAUTICAL_MILE) / KILOMETER;
     }
 
-    public static final double INTERPOLATION_STEP_WIDTH =
-        Double.parseDouble(System.getProperty(
-            "interpolation.step.width", "100"));
-
-    public static int steps(double km) {
-        return (int)Math.ceil(
-            Math.max(1d, (km * KILOMETER)/INTERPOLATION_STEP_WIDTH));
-    }
+    public static final double EPSILON = 1e-5d;
+    public static final int    INTERPOLATION_STEPS =
+        Integer.getInteger("interpolation.steps", 500).intValue();
 
     public static Coordinate toCoordinate(String shape) {
         try {
@@ -381,6 +454,7 @@
         List<Coordinate>   path,
         Collection<Result> input
     ) {
+        log.debug("------  number of points before processing: " + input.size());
         ArrayList<Result> output = new ArrayList<Result>();
 
 
@@ -432,6 +506,8 @@
             sectionHandler.finish();
         }
 
+        log.debug("------  number of points after processing: " + output.size());
+
         return output;
     }
 }

http://dive4elements.wald.intevation.org