Mercurial > dive4elements > gnv-client
comparison 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 |
comparison
equal
deleted
inserted
replaced
431:422275fc9927 | 432:6a70e8883307 |
---|---|
5 | 5 |
6 import java.io.IOException; | 6 import java.io.IOException; |
7 import java.io.OutputStream; | 7 import java.io.OutputStream; |
8 import java.io.OutputStreamWriter; | 8 import java.io.OutputStreamWriter; |
9 import java.io.UnsupportedEncodingException; | 9 import java.io.UnsupportedEncodingException; |
10 | |
10 import java.util.Collection; | 11 import java.util.Collection; |
11 import java.util.HashMap; | 12 import java.util.HashMap; |
12 import java.util.Iterator; | 13 import java.util.Iterator; |
13 import java.util.Locale; | 14 import java.util.Locale; |
14 import java.util.Map; | 15 import java.util.Map; |
16 import java.util.ArrayList; | |
15 | 17 |
16 import org.apache.log4j.Logger; | 18 import org.apache.log4j.Logger; |
17 | 19 |
18 import org.jfree.chart.ChartTheme; | 20 import org.jfree.chart.ChartTheme; |
19 | |
20 import org.w3c.dom.Node; | |
21 | 21 |
22 import net.sf.ehcache.Element; | 22 import net.sf.ehcache.Element; |
23 | 23 |
24 import au.com.bytecode.opencsv.CSVWriter; | 24 import au.com.bytecode.opencsv.CSVWriter; |
25 | 25 |
27 import com.vividsolutions.jts.geom.Coordinate; | 27 import com.vividsolutions.jts.geom.Coordinate; |
28 import com.vividsolutions.jts.geom.LineString; | 28 import com.vividsolutions.jts.geom.LineString; |
29 import com.vividsolutions.jts.io.ParseException; | 29 import com.vividsolutions.jts.io.ParseException; |
30 import com.vividsolutions.jts.io.WKTReader; | 30 import com.vividsolutions.jts.io.WKTReader; |
31 | 31 |
32 import de.intevation.artifactdatabase.Config; | |
33 import de.intevation.gnv.artifacts.cache.CacheFactory; | 32 import de.intevation.gnv.artifacts.cache.CacheFactory; |
33 | |
34 import de.intevation.gnv.chart.Chart; | 34 import de.intevation.gnv.chart.Chart; |
35 import de.intevation.gnv.chart.ChartLabels; | 35 import de.intevation.gnv.chart.ChartLabels; |
36 import de.intevation.gnv.chart.ChartStyle; | 36 import de.intevation.gnv.chart.ChartStyle; |
37 | |
37 import de.intevation.gnv.chart.exception.TechnicalChartException; | 38 import de.intevation.gnv.chart.exception.TechnicalChartException; |
39 | |
38 import de.intevation.gnv.geobackend.base.Result; | 40 import de.intevation.gnv.geobackend.base.Result; |
39 import de.intevation.gnv.geobackend.base.ResultDescriptor; | 41 import de.intevation.gnv.geobackend.base.ResultDescriptor; |
42 | |
40 import de.intevation.gnv.geobackend.base.query.QueryExecutor; | 43 import de.intevation.gnv.geobackend.base.query.QueryExecutor; |
41 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; | 44 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; |
42 import de.intevation.gnv.geobackend.base.query.exception.QueryException; | 45 import de.intevation.gnv.geobackend.base.query.exception.QueryException; |
43 | 46 |
44 import de.intevation.gnv.math.AttributedXYColumns; | 47 import de.intevation.gnv.math.AttributedXYColumns; |
47 import de.intevation.gnv.math.IJKey; | 50 import de.intevation.gnv.math.IJKey; |
48 | 51 |
49 import de.intevation.gnv.state.describedata.KeyValueDescibeData; | 52 import de.intevation.gnv.state.describedata.KeyValueDescibeData; |
50 import de.intevation.gnv.state.exception.StateException; | 53 import de.intevation.gnv.state.exception.StateException; |
51 import de.intevation.gnv.state.timeseries.TimeSeriesOutputState; | 54 import de.intevation.gnv.state.timeseries.TimeSeriesOutputState; |
55 | |
52 import de.intevation.gnv.statistics.Statistics; | 56 import de.intevation.gnv.statistics.Statistics; |
53 import de.intevation.gnv.statistics.VerticalProfileStatistics; | 57 import de.intevation.gnv.statistics.VerticalProfileStatistics; |
58 | |
54 import de.intevation.gnv.utils.WKTUtils; | 59 import de.intevation.gnv.utils.WKTUtils; |
55 | 60 |
56 /** | 61 /** |
57 * @author Tim Englich <tim.englich@intevation.de> | 62 * @author Tim Englich <tim.englich@intevation.de> |
58 * | 63 * |
156 return null; | 161 return null; |
157 } | 162 } |
158 | 163 |
159 | 164 |
160 protected AttributedXYColumns preProcess(Collection results) { | 165 protected AttributedXYColumns preProcess(Collection results) { |
166 | |
161 AttributedXYColumns attColumns = new AttributedXYColumns(); | 167 AttributedXYColumns attColumns = new AttributedXYColumns(); |
162 Map map = new HashMap(1013); | 168 Map<IJKey, XYColumn> map = new HashMap<IJKey, XYColumn>(1013); |
163 Iterator iter = results.iterator(); | 169 Iterator iter = results.iterator(); |
164 | 170 |
165 int sIdx = -1; | 171 int sIdx = -1; |
166 int iIdx = -1; | 172 int iIdx = -1; |
167 int jIdx = -1; | 173 int jIdx = -1; |
192 result.getObject(colName)); | 198 result.getObject(colName)); |
193 } | 199 } |
194 } | 200 } |
195 } | 201 } |
196 | 202 |
197 try { | 203 double v = result.getDouble(vIdx); |
198 Point point = (Point) new WKTReader().read( | 204 double z = result.getDouble(zIdx); |
199 result.getString(sIdx)); | 205 int i = result.getInteger(iIdx); |
200 double v = result.getDouble(vIdx); | 206 int j = result.getInteger(jIdx); |
201 int i = result.getInteger(iIdx); | 207 int k = result.getInteger(kIdx); |
202 int j = result.getInteger(jIdx); | 208 |
203 int k = result.getInteger(kIdx); | 209 IJKey key = new IJKey(i, j); |
204 int z = result.getInteger(zIdx); | 210 |
205 | 211 XYColumn col = (XYColumn)map.get(key); |
206 IJKey key = new IJKey(i, j); | 212 |
207 | 213 if (col == null) { |
208 XYColumn col = (XYColumn)map.get(key); | 214 Coordinate coord = WKTUtils.toCoordinate(result.getString(sIdx)); |
209 | 215 if (coord == null) coord = new Coordinate(); |
210 if (col == null) { | 216 col = new XYColumn(coord.x, coord.z, i, j); |
211 col = new XYColumn(point.getX(), point.getY(), i, j); | 217 map.put(key, col); |
212 map.put(key, col); | 218 } |
213 } | 219 |
214 | 220 col.add(new HeightValue(z, v, k)); |
215 col.add(new HeightValue(z, v, k)); | 221 } |
216 } | 222 |
217 catch (ParseException pe) { | 223 ArrayList<XYColumn> cols = new ArrayList<XYColumn>(map.values()); |
218 log.warn("Error while parsing geometry.", pe); | |
219 } | |
220 } | |
221 | |
222 XYColumn[] cols = (XYColumn[])map.values().toArray( | |
223 new XYColumn[map.size()]); | |
224 attColumns.setXYColumns(cols); | 224 attColumns.setXYColumns(cols); |
225 | 225 |
226 return attColumns; | 226 return attColumns; |
227 } | 227 } |
228 | 228 |
315 | 315 |
316 /** | 316 /** |
317 * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#createCSV(java.io.OutputStream, java.util.Collection) | 317 * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#createCSV(java.io.OutputStream, java.util.Collection) |
318 */ | 318 */ |
319 @Override | 319 @Override |
320 protected void createCSV(OutputStream outputStream, | 320 protected void createCSV( |
321 Collection<Result> chartResult) | 321 OutputStream outputStream, |
322 throws UnsupportedEncodingException, | 322 Collection<Result> chartResult |
323 IOException, | 323 ) |
324 StateException { | 324 throws UnsupportedEncodingException, IOException, StateException |
325 { | |
326 /* // TODO: Implement a substitution which makes sense. | |
325 if (chartResult != null) { | 327 if (chartResult != null) { |
326 try { | 328 try { |
327 CSVWriter writer = new CSVWriter(new OutputStreamWriter( | 329 CSVWriter writer = new CSVWriter(new OutputStreamWriter( |
328 outputStream, "ISO-8859-1"), ','); | 330 outputStream, "ISO-8859-1"), ','); |
329 // USE THIS ENCODING BECAUSE OF | 331 // USE THIS ENCODING BECAUSE OF |
355 } else { | 357 } else { |
356 log.error("No Data given for generating an CSV-File."); | 358 log.error("No Data given for generating an CSV-File."); |
357 throw new StateException( | 359 throw new StateException( |
358 "No Data given for generating an CSV-File."); | 360 "No Data given for generating an CSV-File."); |
359 } | 361 } |
360 } | 362 */ |
361 | 363 } |
362 } | 364 } |
365 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |