Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java @ 335:e964a3d8f7bc
Some Refactoring work done.
Moved Transition to State
gnv-artifacts/trunk@401 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Tue, 08 Dec 2009 08:39:03 +0000 |
parents | |
children | 2e43542e6a11 |
comparison
equal
deleted
inserted
replaced
334:e37930705daa | 335:e964a3d8f7bc |
---|---|
1 /** | |
2 * | |
3 */ | |
4 package de.intevation.gnv.state.profile.verticalcrosssection; | |
5 | |
6 import java.io.IOException; | |
7 import java.io.OutputStream; | |
8 import java.io.OutputStreamWriter; | |
9 import java.io.UnsupportedEncodingException; | |
10 import java.util.Collection; | |
11 import java.util.Iterator; | |
12 import java.util.Locale; | |
13 | |
14 import org.apache.log4j.Logger; | |
15 | |
16 import au.com.bytecode.opencsv.CSVWriter; | |
17 | |
18 import com.vividsolutions.jts.geom.Point; | |
19 import com.vividsolutions.jts.io.ParseException; | |
20 import com.vividsolutions.jts.io.WKTReader; | |
21 | |
22 import de.intevation.gnv.chart.Chart; | |
23 import de.intevation.gnv.chart.ChartLabels; | |
24 import de.intevation.gnv.chart.ChartStyle; | |
25 import de.intevation.gnv.chart.VerticalCrossSectionChartFactory; | |
26 import de.intevation.gnv.chart.exception.TechnicalChartException; | |
27 import de.intevation.gnv.geobackend.base.Result; | |
28 import de.intevation.gnv.state.describedata.KeyValueDescibeData; | |
29 import de.intevation.gnv.state.exception.StateException; | |
30 import de.intevation.gnv.state.timeseries.TimeSeriesOutputState; | |
31 import de.intevation.gnv.statistics.Statistics; | |
32 import de.intevation.gnv.statistics.VerticalProfileStatistics; | |
33 | |
34 /** | |
35 * @author Tim Englich <tim.englich@intevation.de> | |
36 * | |
37 */ | |
38 public class VerticalCrossSectionOutputState extends TimeSeriesOutputState { | |
39 | |
40 private static Logger log = Logger | |
41 .getLogger(VerticalCrossSectionOutputState.class); | |
42 | |
43 /** | |
44 * The UID of this Class | |
45 */ | |
46 private static final long serialVersionUID = 3233620652465061860L; | |
47 | |
48 /** | |
49 * Constructor | |
50 */ | |
51 public VerticalCrossSectionOutputState() { | |
52 super(); | |
53 super.domainLable = "Depth [m]"; | |
54 } | |
55 | |
56 @Override | |
57 protected Chart getChart( | |
58 ChartLabels chartLables, | |
59 Collection parameters, | |
60 Collection measurements, | |
61 Collection dates, | |
62 Collection result, | |
63 Locale locale, | |
64 String uuid, | |
65 boolean linesVisible, | |
66 boolean shapesVisible | |
67 ) { | |
68 Chart chart = null; | |
69 | |
70 if (CACHE_CHART) { | |
71 log.info("Try to get verticalcrosssection chart from cache."); | |
72 chart = (Chart) getChartFromCache(uuid); | |
73 } | |
74 | |
75 if (chart != null) | |
76 return chart; | |
77 | |
78 log.info("Chart not in cache yet."); | |
79 | |
80 log.warn("This sort of chart is not implemented yet."); | |
81 /* TODO Implement a special chart for this sort of charts. | |
82 chart = new VerticalProfileChart( | |
83 chartLables, | |
84 chartTheme, | |
85 parameters, | |
86 measurements, | |
87 result, | |
88 dates, | |
89 locale | |
90 ); | |
91 chart.generateChart(); | |
92 | |
93 if (CACHE_CHART) { | |
94 log.info("Put chart into cache."); | |
95 purifyChart(chart, uuid); | |
96 } | |
97 */ | |
98 | |
99 return chart; | |
100 } | |
101 | |
102 /** | |
103 * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#createChart(java.io.OutputStream, | |
104 * java.util.Collection, java.util.Collection, java.lang.String, | |
105 * de.intevation.gnv.chart.ChartStyle, | |
106 * de.intevation.gnv.chart.ChartLabels) | |
107 */ | |
108 /* | |
109 @Override | |
110 protected void createChart(OutputStream outputStream, | |
111 Collection<KeyValueDescibeData> parameters, | |
112 Collection<KeyValueDescibeData> measurements, | |
113 Collection<KeyValueDescibeData> dates, | |
114 ChartStyle chartStyle, ChartLabels chartLables, | |
115 String uuid) throws IOException, | |
116 TechnicalChartException { | |
117 new VerticalCrossSectionChartFactory().createProfileChart(chartLables, | |
118 chartStyle, parameters, measurements, dates, outputStream, this | |
119 .getChartResult(uuid)); | |
120 } | |
121 */ | |
122 | |
123 /** | |
124 * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#getStatisticsGenerator() | |
125 */ | |
126 @Override | |
127 protected Statistics getStatisticsGenerator() { | |
128 return new VerticalProfileStatistics(); | |
129 } | |
130 | |
131 /** | |
132 * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#createCSV(java.io.OutputStream, java.util.Collection) | |
133 */ | |
134 @Override | |
135 protected void createCSV(OutputStream outputStream, | |
136 Collection<Result> chartResult) | |
137 throws UnsupportedEncodingException, | |
138 IOException, | |
139 StateException { | |
140 if (chartResult != null) { | |
141 try { | |
142 CSVWriter writer = new CSVWriter(new OutputStreamWriter( | |
143 outputStream, "ISO-8859-1"), ','); | |
144 // USE THIS ENCODING BECAUSE OF | |
145 // PROBLEMS WITH EXCEL AND UTF-8 | |
146 Iterator<Result> it = chartResult.iterator(); | |
147 WKTReader wktReader = new WKTReader(); | |
148 while (it.hasNext()) { | |
149 Result result = it.next(); | |
150 int i = 0; | |
151 String[] entries = new String[9]; | |
152 Point p = (Point)wktReader.read(result.getString("SHAPE")); | |
153 entries[i++] = ""+p.getX(); | |
154 entries[i++] = ""+p.getY(); | |
155 entries[i++] = result.getString("Z"); | |
156 entries[i++] = result.getString("YORDINATE"); | |
157 entries[i++] = result.getString("GROUP1"); | |
158 entries[i++] = result.getString("GROUP2"); | |
159 entries[i++] = result.getString("IPOSITION"); | |
160 entries[i++] = result.getString("JPOSITION"); | |
161 entries[i++] = result.getString("KPOSITION"); | |
162 writer.writeNext(entries); | |
163 } | |
164 writer.close(); | |
165 } catch (ParseException e) { | |
166 log.error(e,e); | |
167 throw new StateException( | |
168 "Exception occured while parsing an Point from WKT."); | |
169 } | |
170 } else { | |
171 log.error("No Data given for generating an CSV-File."); | |
172 throw new StateException( | |
173 "No Data given for generating an CSV-File."); | |
174 } | |
175 } | |
176 | |
177 } |