Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java @ 340:07a64cfafdf1
Added gap detection in horizontal and vertical profile charts. Distinguish between meshes and other data sources.
gnv-artifacts/trunk@406 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 09 Dec 2009 10:22:20 +0000 |
parents | e37930705daa |
children | 061355435075 |
comparison
equal
deleted
inserted
replaced
339:02c71ea5c9c8 | 340:07a64cfafdf1 |
---|---|
58 this.PLOT_ORIENTATION = PlotOrientation.VERTICAL; | 58 this.PLOT_ORIENTATION = PlotOrientation.VERTICAL; |
59 this.distance = 0; | 59 this.distance = 0; |
60 } | 60 } |
61 | 61 |
62 | 62 |
63 protected void gapDetection( | |
64 Result[] results, | |
65 Series series, | |
66 int startPos, | |
67 int endPos | |
68 ) { | |
69 log.debug("Start gap detection."); | |
70 try { | |
71 Point startValue = getPoint(results[startPos]); | |
72 Point endValue = getPoint(results[endPos-1]); | |
73 if (results[0].getInteger("DATAID") == 2) | |
74 addGapsOnGrid(results, series, startPos, endPos); | |
75 else | |
76 addGaps( | |
77 results, | |
78 series, | |
79 startValue, | |
80 endValue, | |
81 startPos, | |
82 endPos | |
83 ); | |
84 } | |
85 catch (ParseException pe) { | |
86 log.warn( | |
87 "Error while parsing points for gap detection. " + | |
88 "No gaps for current series will be detected." | |
89 ); | |
90 } | |
91 | |
92 log.debug("Gap detection finished."); | |
93 } | |
94 | |
95 | |
63 protected void addValue(Result row, Series series) { | 96 protected void addValue(Result row, Series series) { |
64 // TODO look for gaps between two values | |
65 try { | 97 try { |
66 Point point = (Point) wktReader.read(row.getString("SHAPE")); | 98 Point point = (Point) wktReader.read(row.getString("SHAPE")); |
67 if (lastPoint != null) | 99 if (lastPoint != null) |
68 distance = distance + DistanceCalculator.calculateDistance( | 100 distance = distance + DistanceCalculator.calculateDistance( |
69 lastPoint, point | 101 lastPoint, point |
101 breakPoint2, | 133 breakPoint2, |
102 breakPoint3) + | 134 breakPoint3) + |
103 " " + | 135 " " + |
104 findValueTitle(dates, breakPoint3); | 136 findValueTitle(dates, breakPoint3); |
105 } | 137 } |
138 | |
139 | |
140 protected void addGapsOnGrid( | |
141 Result[] results, | |
142 Series series, | |
143 int startPos, | |
144 int endPos | |
145 ) { | |
146 String axis = getDependendAxisName( | |
147 results[startPos], | |
148 results[startPos+1] | |
149 ); | |
150 | |
151 double range = 0; | |
152 double distance = 0; | |
153 int last = 0; | |
154 int current = 0; | |
155 Point lastPoint = null; | |
156 Point currentPoint = null; | |
157 | |
158 for (int i = startPos+1; i < endPos; i++) { | |
159 try { | |
160 last = results[i-1].getInteger(axis); | |
161 lastPoint = getPoint(results[i-1]); | |
162 current = results[i].getInteger(axis); | |
163 currentPoint = getPoint(results[i]); | |
164 distance = DistanceCalculator.calculateDistance( | |
165 lastPoint, | |
166 currentPoint | |
167 ); | |
168 | |
169 boolean detected = gridDetection(last, current); | |
170 | |
171 if (detected) { | |
172 log.debug( | |
173 "Gap detected on grid between " + range + | |
174 " and " + (range+distance) | |
175 ); | |
176 | |
177 ((XYSeries) series).add(range+0.0001, null); | |
178 } | |
179 | |
180 range += distance; | |
181 } | |
182 catch (ParseException pe) { | |
183 log.warn("Error while parsing point for gap detection.", pe); | |
184 } | |
185 } | |
186 } | |
187 | |
188 | |
189 protected void addGaps( | |
190 Result[] results, | |
191 Series series, | |
192 Point startValue, | |
193 Point endValue, | |
194 int startPos, | |
195 int endPos | |
196 ) { | |
197 double range = 0; | |
198 Point last = null; | |
199 Point now = null; | |
200 | |
201 for (int i = startPos+1; i < endPos; i++) { | |
202 boolean detected = false; | |
203 | |
204 try { | |
205 last = (Point) getPoint(results[i-1]); | |
206 now = (Point) getPoint(results[i]); | |
207 | |
208 // gap detection for more than GAP_MAX_VALUES values | |
209 if (results.length > GAP_MAX_VALUES) | |
210 detected = simpleDetection(startValue, endValue, last, now); | |
211 // gap detection for less than GAP_MAX_VALUES values | |
212 else | |
213 detected = specialDetection( | |
214 startValue, | |
215 endValue, | |
216 last, | |
217 now, | |
218 results.length | |
219 ); | |
220 | |
221 // gap detected, insert null value to break line | |
222 if (detected) { | |
223 log.info("Gap after " + range); | |
224 double x = range + 0.0001; | |
225 | |
226 ((XYSeries)series).add(x, null); | |
227 } | |
228 | |
229 range += DistanceCalculator.calculateDistance(last,now); | |
230 } | |
231 catch (ParseException pe) { | |
232 log.warn("Error while parsing point."); | |
233 } | |
234 | |
235 } | |
236 } | |
237 | |
238 | |
239 protected boolean simpleDetection( | |
240 Point start, | |
241 Point end, | |
242 Point last, | |
243 Point current | |
244 ) { | |
245 double delta = DistanceCalculator.calculateDistance(start, end); | |
246 double deltaSmall = DistanceCalculator.calculateDistance(last,current); | |
247 | |
248 return (deltaSmall > (delta / 100 * PERCENTAGE)); | |
249 } | |
250 | |
251 | |
252 protected boolean specialDetection( | |
253 Point start, | |
254 Point end, | |
255 Point last, | |
256 Point current, | |
257 int count | |
258 ) { | |
259 double delta = Math.abs( | |
260 DistanceCalculator.calculateDistance(end, start) | |
261 ); | |
262 double smallDelta = Math.abs( | |
263 DistanceCalculator.calculateDistance(current, last) | |
264 ); | |
265 | |
266 return (smallDelta > (3.0 / (count - 1) * delta)); | |
267 } | |
268 | |
269 | |
270 private Point getPoint(Result result) | |
271 throws ParseException | |
272 { | |
273 return (Point) wktReader.read(result.getString("SHAPE")); | |
274 } | |
106 } | 275 } |
107 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 276 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |