Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java @ 429:bed9735adf84
Finished preprocessing data for interpolation in verticalcrosssection charts.ß
gnv-artifacts/trunk@477 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 22 Dec 2009 17:19:10 +0000 |
parents | 22229249e9fc |
children | 422275fc9927 |
comparison
equal
deleted
inserted
replaced
428:88cd37c3b5e4 | 429:bed9735adf84 |
---|---|
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 import java.util.Collection; | 10 import java.util.Collection; |
11 import java.util.HashMap; | |
11 import java.util.Iterator; | 12 import java.util.Iterator; |
12 import java.util.Locale; | 13 import java.util.Locale; |
14 import java.util.Map; | |
13 | 15 |
14 import org.apache.log4j.Logger; | 16 import org.apache.log4j.Logger; |
15 | 17 |
16 import org.jfree.chart.ChartTheme; | 18 import org.jfree.chart.ChartTheme; |
17 | 19 |
20 import org.w3c.dom.Node; | |
21 | |
22 import net.sf.ehcache.Element; | |
23 | |
18 import au.com.bytecode.opencsv.CSVWriter; | 24 import au.com.bytecode.opencsv.CSVWriter; |
19 | 25 |
20 import com.vividsolutions.jts.geom.Point; | 26 import com.vividsolutions.jts.geom.Point; |
27 import com.vividsolutions.jts.geom.Coordinate; | |
28 import com.vividsolutions.jts.geom.LineString; | |
21 import com.vividsolutions.jts.io.ParseException; | 29 import com.vividsolutions.jts.io.ParseException; |
22 import com.vividsolutions.jts.io.WKTReader; | 30 import com.vividsolutions.jts.io.WKTReader; |
23 | 31 |
32 import de.intevation.artifactdatabase.Config; | |
33 import de.intevation.gnv.artifacts.cache.CacheFactory; | |
24 import de.intevation.gnv.chart.Chart; | 34 import de.intevation.gnv.chart.Chart; |
25 import de.intevation.gnv.chart.ChartLabels; | 35 import de.intevation.gnv.chart.ChartLabels; |
26 import de.intevation.gnv.chart.ChartStyle; | 36 import de.intevation.gnv.chart.ChartStyle; |
27 import de.intevation.gnv.chart.exception.TechnicalChartException; | 37 import de.intevation.gnv.chart.exception.TechnicalChartException; |
28 import de.intevation.gnv.geobackend.base.Result; | 38 import de.intevation.gnv.geobackend.base.Result; |
39 import de.intevation.gnv.geobackend.base.ResultDescriptor; | |
40 import de.intevation.gnv.geobackend.base.query.QueryExecutor; | |
41 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; | |
42 import de.intevation.gnv.geobackend.base.query.exception.QueryException; | |
43 import de.intevation.gnv.math.AttributedXYColumns; | |
44 import de.intevation.gnv.math.HeightValue; | |
45 import de.intevation.gnv.math.XYColumn; | |
29 import de.intevation.gnv.state.describedata.KeyValueDescibeData; | 46 import de.intevation.gnv.state.describedata.KeyValueDescibeData; |
30 import de.intevation.gnv.state.exception.StateException; | 47 import de.intevation.gnv.state.exception.StateException; |
31 import de.intevation.gnv.state.timeseries.TimeSeriesOutputState; | 48 import de.intevation.gnv.state.timeseries.TimeSeriesOutputState; |
32 import de.intevation.gnv.statistics.Statistics; | 49 import de.intevation.gnv.statistics.Statistics; |
33 import de.intevation.gnv.statistics.VerticalProfileStatistics; | 50 import de.intevation.gnv.statistics.VerticalProfileStatistics; |
51 import de.intevation.gnv.utils.WKTUtils; | |
34 | 52 |
35 /** | 53 /** |
36 * @author Tim Englich <tim.englich@intevation.de> | 54 * @author Tim Englich <tim.englich@intevation.de> |
37 * | 55 * |
38 */ | 56 */ |
39 public class VerticalCrossSectionOutputState extends TimeSeriesOutputState { | 57 public class VerticalCrossSectionOutputState extends TimeSeriesOutputState { |
40 | 58 |
41 private static Logger log = Logger | 59 public static final String[] ATTRIBUTE_LIST = { |
42 .getLogger(VerticalCrossSectionOutputState.class); | 60 "SHAPE", |
43 | 61 "Z", |
62 "YORDINATE", | |
63 "IPOSITION", | |
64 "JPOSITION", | |
65 "KPOSITION" | |
66 }; | |
67 | |
68 private static Logger log = Logger.getLogger( | |
69 VerticalCrossSectionOutputState.class); | |
70 | |
71 private String ijkQueryID = "horizontalprofile_meshpoint_cross_ij"; | |
72 | |
44 /** | 73 /** |
45 * The UID of this Class | 74 * The UID of this Class |
46 */ | 75 */ |
47 private static final long serialVersionUID = 3233620652465061860L; | 76 private static final long serialVersionUID = 3233620652465061860L; |
48 | 77 |
51 */ | 80 */ |
52 public VerticalCrossSectionOutputState() { | 81 public VerticalCrossSectionOutputState() { |
53 super(); | 82 super(); |
54 super.domainLable = "chart.verticalcrosssection.title.xaxis"; | 83 super.domainLable = "chart.verticalcrosssection.title.xaxis"; |
55 } | 84 } |
85 | |
86 | |
87 @Override | |
88 protected Object getChartResult(String uuid) { | |
89 log.debug("VerticalCrossSectionOutputState.getChartResult"); | |
90 Collection<Result> result = null; | |
91 String key = uuid + super.getID(); | |
92 | |
93 Element element = CacheFactory.getInstance().getCache().get(key); | |
94 if (element != null) | |
95 return element.getObjectValue(); | |
96 | |
97 log.debug("No results in cache yet."); | |
98 if (inputData.containsKey("mesh_linestring")) { | |
99 | |
100 try { | |
101 LineString ls = (LineString) new WKTReader().read( | |
102 inputData.get("mesh_linestring").getValue()); | |
103 | |
104 Coordinate[] coords = ls.getCoordinates(); | |
105 | |
106 String additionWhere = WKTUtils.worldCoordinatesToIndex( | |
107 result, | |
108 inputData, | |
109 ijkQueryID | |
110 ); | |
111 | |
112 | |
113 String[] filterValues = | |
114 generateFilterValuesFromInputData(); | |
115 String[] addedFilterValues = | |
116 new String[filterValues.length + 1]; | |
117 | |
118 System.arraycopy( | |
119 filterValues, 0, | |
120 addedFilterValues, 0, | |
121 filterValues.length | |
122 ); | |
123 addedFilterValues[filterValues.length] = additionWhere; | |
124 | |
125 QueryExecutor exec = QueryExecutorFactory | |
126 .getInstance() | |
127 .getQueryExecutor(); | |
128 | |
129 result = exec.executeQuery(queryID, addedFilterValues); | |
130 } | |
131 catch (ParseException pe) { | |
132 log.error(pe, pe); | |
133 } | |
134 catch (QueryException qe) { | |
135 log.error(qe, qe); | |
136 } | |
137 } | |
138 else { | |
139 // TODO What should happen if there is no linestring? | |
140 log.warn("No linestring in inputData."); | |
141 } | |
142 | |
143 Object obj = process(preProcess(result)); | |
144 CacheFactory.getInstance().getCache().put(new Element(key, obj)); | |
145 | |
146 return obj; | |
147 } | |
148 | |
149 | |
150 protected Object process(AttributedXYColumns columns) { | |
151 | |
152 // TODO Implement me | |
153 return null; | |
154 } | |
155 | |
156 | |
157 protected AttributedXYColumns preProcess(Collection results) { | |
158 AttributedXYColumns attColumns = new AttributedXYColumns(); | |
159 Map map = new HashMap(); | |
160 Iterator iter = results.iterator(); | |
161 | |
162 int sIdx = -1; | |
163 int iIdx = -1; | |
164 int jIdx = -1; | |
165 int kIdx = -1; | |
166 int vIdx = -1; | |
167 int zIdx = -1; | |
168 | |
169 while (iter.hasNext()) { | |
170 Result result = (Result) iter.next(); | |
171 | |
172 if (sIdx == -1) { | |
173 ResultDescriptor rd = result.getResultDescriptor(); | |
174 int columnCount = rd.getColumnCount(); | |
175 | |
176 sIdx = rd.getColumnIndex("SHAPE"); | |
177 iIdx = rd.getColumnIndex("IPOSITION"); | |
178 jIdx = rd.getColumnIndex("JPOSITION"); | |
179 kIdx = rd.getColumnIndex("KPOSITION"); | |
180 vIdx = rd.getColumnIndex("YORDINATE"); | |
181 zIdx = rd.getColumnIndex("Z"); | |
182 | |
183 for (int i = 0; i < columnCount; i++) { | |
184 String colName = rd.getColumnName(i); | |
185 | |
186 if (!attributeInList(colName)) { | |
187 attColumns.setAttribute( | |
188 colName, | |
189 result.getObject(colName)); | |
190 } | |
191 } | |
192 } | |
193 | |
194 try { | |
195 Point point = (Point) new WKTReader().read( | |
196 result.getString(sIdx)); | |
197 double v = result.getDouble(vIdx); | |
198 int i = result.getInteger(iIdx); | |
199 int j = result.getInteger(jIdx); | |
200 int k = result.getInteger(kIdx); | |
201 int z = result.getInteger(zIdx); | |
202 | |
203 XYColumn col = new XYColumn(point.getX(), point.getY(), i, j); | |
204 XYColumn old = (XYColumn)map.get(col); | |
205 | |
206 if (old == null) { | |
207 map.put(old = col, col); | |
208 } | |
209 | |
210 old.add(new HeightValue(z, v, k)); | |
211 } | |
212 catch (ParseException pe) { | |
213 log.warn("Error while parsing geometry.", pe); | |
214 } | |
215 } | |
216 | |
217 XYColumn[] cols = (XYColumn[])map.values().toArray( | |
218 new XYColumn[map.size()]); | |
219 attColumns.setXYColumns(cols); | |
220 | |
221 return attColumns; | |
222 } | |
223 | |
224 | |
225 protected boolean attributeInList(String name) { | |
226 for (int i = 0; i < ATTRIBUTE_LIST.length; i++) { | |
227 if (name.equals(ATTRIBUTE_LIST[i])) | |
228 return true; | |
229 } | |
230 | |
231 return false; | |
232 } | |
233 | |
56 | 234 |
57 @Override | 235 @Override |
58 protected Chart getChart( | 236 protected Chart getChart( |
59 ChartLabels chartLables, | 237 ChartLabels chartLables, |
60 ChartTheme theme, | 238 ChartTheme theme, |
61 Collection parameters, | 239 Collection parameters, |
62 Collection measurements, | 240 Collection measurements, |
63 Collection dates, | 241 Collection dates, |
64 Collection result, | 242 Object result, |
65 Locale locale, | 243 Locale locale, |
66 String uuid, | 244 String uuid, |
67 boolean linesVisible, | 245 boolean linesVisible, |
68 boolean shapesVisible | 246 boolean shapesVisible |
69 ) { | 247 ) { |
76 | 254 |
77 if (chart != null) | 255 if (chart != null) |
78 return chart; | 256 return chart; |
79 | 257 |
80 log.info("Chart not in cache yet."); | 258 log.info("Chart not in cache yet."); |
81 | 259 |
82 log.warn("This sort of chart is not implemented yet."); | 260 log.warn("This sort of chart is not implemented yet."); |
83 /* TODO Implement a special chart for this sort of charts. | 261 /* TODO Implement a special chart for this sort of charts. |
84 chart = new VerticalProfileChart( | 262 chart = new VerticalProfileChart( |
85 chartLables, | 263 chartLables, |
86 chartTheme, | 264 chartTheme, |
127 */ | 305 */ |
128 @Override | 306 @Override |
129 protected Statistics getStatisticsGenerator() { | 307 protected Statistics getStatisticsGenerator() { |
130 return new VerticalProfileStatistics(); | 308 return new VerticalProfileStatistics(); |
131 } | 309 } |
132 | 310 |
133 /** | 311 /** |
134 * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#createCSV(java.io.OutputStream, java.util.Collection) | 312 * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#createCSV(java.io.OutputStream, java.util.Collection) |
135 */ | 313 */ |
136 @Override | 314 @Override |
137 protected void createCSV(OutputStream outputStream, | 315 protected void createCSV(OutputStream outputStream, |