diff gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java @ 432:6a70e8883307

Added some type safety. Fixed z value bug in reading database preprocessing. Only dissemble WKT points if really needed. gnv-artifacts/trunk@480 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 23 Dec 2009 09:45:40 +0000
parents 422275fc9927
children 8975de9d7483
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java	Wed Dec 23 06:53:46 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java	Wed Dec 23 09:45:40 2009 +0000
@@ -7,18 +7,18 @@
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.UnsupportedEncodingException;
+
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Locale;
 import java.util.Map;
+import java.util.ArrayList;
 
 import org.apache.log4j.Logger;
 
 import org.jfree.chart.ChartTheme;
 
-import org.w3c.dom.Node;
-
 import net.sf.ehcache.Element;
 
 import au.com.bytecode.opencsv.CSVWriter;
@@ -29,14 +29,17 @@
 import com.vividsolutions.jts.io.ParseException;
 import com.vividsolutions.jts.io.WKTReader;
 
-import de.intevation.artifactdatabase.Config;
 import de.intevation.gnv.artifacts.cache.CacheFactory;
+
 import de.intevation.gnv.chart.Chart;
 import de.intevation.gnv.chart.ChartLabels;
 import de.intevation.gnv.chart.ChartStyle;
+
 import de.intevation.gnv.chart.exception.TechnicalChartException;
+
 import de.intevation.gnv.geobackend.base.Result;
 import de.intevation.gnv.geobackend.base.ResultDescriptor;
+
 import de.intevation.gnv.geobackend.base.query.QueryExecutor;
 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory;
 import de.intevation.gnv.geobackend.base.query.exception.QueryException;
@@ -49,8 +52,10 @@
 import de.intevation.gnv.state.describedata.KeyValueDescibeData;
 import de.intevation.gnv.state.exception.StateException;
 import de.intevation.gnv.state.timeseries.TimeSeriesOutputState;
+
 import de.intevation.gnv.statistics.Statistics;
 import de.intevation.gnv.statistics.VerticalProfileStatistics;
+
 import de.intevation.gnv.utils.WKTUtils;
 
 /**
@@ -158,8 +163,9 @@
 
 
     protected AttributedXYColumns preProcess(Collection results) {
+
         AttributedXYColumns attColumns = new AttributedXYColumns();
-        Map        map                 = new HashMap(1013);
+        Map<IJKey, XYColumn> map       = new HashMap<IJKey, XYColumn>(1013);
         Iterator   iter                = results.iterator();
 
         int sIdx = -1;
@@ -194,33 +200,27 @@
                 }
             }
 
-            try {
-                Point point  = (Point) new WKTReader().read(
-                    result.getString(sIdx));
-                double v     = result.getDouble(vIdx);
-                int i        = result.getInteger(iIdx);
-                int j        = result.getInteger(jIdx);
-                int k        = result.getInteger(kIdx);
-                int z        = result.getInteger(zIdx);
-
-                IJKey key = new IJKey(i, j);
+            double v = result.getDouble(vIdx);
+            double z = result.getDouble(zIdx);
+            int    i = result.getInteger(iIdx);
+            int    j = result.getInteger(jIdx);
+            int    k = result.getInteger(kIdx);
 
-                XYColumn col = (XYColumn)map.get(key);
+            IJKey key = new IJKey(i, j);
 
-                if (col == null) {
-                    col = new XYColumn(point.getX(), point.getY(), i, j);
-                    map.put(key, col);
-                }
+            XYColumn col = (XYColumn)map.get(key);
 
-                col.add(new HeightValue(z, v, k));
+            if (col == null) {
+                Coordinate coord = WKTUtils.toCoordinate(result.getString(sIdx));
+                if (coord == null) coord = new Coordinate();
+                col = new XYColumn(coord.x, coord.z, i, j);
+                map.put(key, col);
             }
-            catch (ParseException pe) {
-                log.warn("Error while parsing geometry.", pe);
-            }
+
+            col.add(new HeightValue(z, v, k));
         }
 
-        XYColumn[] cols = (XYColumn[])map.values().toArray(
-            new XYColumn[map.size()]);
+        ArrayList<XYColumn> cols = new ArrayList<XYColumn>(map.values());
         attColumns.setXYColumns(cols);
 
         return attColumns;
@@ -317,11 +317,13 @@
      * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#createCSV(java.io.OutputStream, java.util.Collection)
      */
     @Override
-    protected void createCSV(OutputStream outputStream,
-                             Collection<Result> chartResult)
-                                                            throws UnsupportedEncodingException,
-                                                            IOException,
-                                                            StateException {
+    protected void createCSV(
+        OutputStream       outputStream,
+        Collection<Result> chartResult
+    )
+    throws UnsupportedEncodingException, IOException, StateException 
+    {
+        /* // TODO: Implement a substitution which makes sense.
         if (chartResult != null) {
             try {
                 CSVWriter writer = new CSVWriter(new OutputStreamWriter(
@@ -357,6 +359,7 @@
             throw new StateException(
                     "No Data given for generating an CSV-File.");
         }
+        */
     }
-
 }
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org