Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java @ 1049:778d86255d76
Corrected the distance calculation of a 'Horizontalprofil' and adjusted the gap detection according to these changes (issue287).
gnv-artifacts/trunk@1122 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 25 May 2010 13:57:48 +0000 |
parents | 38c8cc586a85 |
children | f953c9a559d8 |
comparison
equal
deleted
inserted
replaced
1048:b5d852991cbf | 1049:778d86255d76 |
---|---|
51 | 51 |
52 /** | 52 /** |
53 * The first point in a HorizontalProfileChart. It is used to calculate the | 53 * The first point in a HorizontalProfileChart. It is used to calculate the |
54 * distance between the currently processed point an the start. | 54 * distance between the currently processed point an the start. |
55 */ | 55 */ |
56 private Point firstPoint; | 56 protected Point lastPoint; |
57 | |
58 protected double distance = 0d; | |
57 | 59 |
58 /** | 60 /** |
59 * Constructor used to create horizontal profile charts. | 61 * Constructor used to create horizontal profile charts. |
60 * | 62 * |
61 * @param labels Labels used to be displayed in title, subtitle and so on. | 63 * @param labels Labels used to be displayed in title, subtitle and so on. |
145 } | 147 } |
146 | 148 |
147 | 149 |
148 @Override | 150 @Override |
149 protected void addValue(Result row, Series series) { | 151 protected void addValue(Result row, Series series) { |
150 double distance = 0; | |
151 | |
152 try { | 152 try { |
153 Point point = (Point) wktReader.read(row.getString("SHAPE")); | 153 Point point = (Point) wktReader.read(row.getString("SHAPE")); |
154 if (firstPoint != null) { | 154 if (lastPoint != null) { |
155 distance = DistanceCalculator.calculateDistance( | 155 distance += DistanceCalculator.calculateDistance( |
156 firstPoint, point | 156 lastPoint, point |
157 ); | 157 ); |
158 } | |
159 else { | |
160 firstPoint = point; | |
161 } | 158 } |
162 | 159 |
163 ((XYSeries) series).add( | 160 ((XYSeries) series).add( |
164 distance, | 161 distance, |
165 row.getDouble("YORDINATE") | 162 row.getDouble("YORDINATE") |
166 ); | 163 ); |
164 | |
165 lastPoint = point; | |
167 } | 166 } |
168 catch(ParseException pe) { | 167 catch(ParseException pe) { |
169 log.warn("No data found while parsing."); | 168 log.warn("No data found while parsing."); |
170 } | 169 } |
171 } | 170 } |
173 | 172 |
174 @Override | 173 @Override |
175 protected void addSeries(Series series, String label, int idx) { | 174 protected void addSeries(Series series, String label, int idx) { |
176 super.addSeries(series, label, idx); | 175 super.addSeries(series, label, idx); |
177 | 176 |
178 // reset firstPoint for next series | 177 // reset lastPoint and distance of the last series |
179 firstPoint = null; | 178 lastPoint = null; |
179 distance = 0; | |
180 } | 180 } |
181 | 181 |
182 | 182 |
183 @Override | 183 @Override |
184 protected void prepareAxis(String seriesKey,int idx) { | 184 protected void prepareAxis(String seriesKey,int idx) { |
278 int last = 0; | 278 int last = 0; |
279 int current = 0; | 279 int current = 0; |
280 Point lastPoint = null; | 280 Point lastPoint = null; |
281 Point currentPoint = null; | 281 Point currentPoint = null; |
282 | 282 |
283 try { | 283 double distance = 0; |
284 firstPoint = getPoint(results[0]); | 284 double distanceOld = 0; |
285 } | |
286 catch (ParseException pe) { | |
287 log.error("Unable to parse start point for gap detection."); | |
288 return; | |
289 } | |
290 | |
291 for (int i = startPos+1; i < endPos; i++) { | 285 for (int i = startPos+1; i < endPos; i++) { |
292 try { | 286 try { |
293 last = results[i-1].getInteger(axis); | 287 last = results[i-1].getInteger(axis); |
294 lastPoint = getPoint(results[i-1]); | 288 lastPoint = getPoint(results[i-1]); |
295 current = results[i].getInteger(axis); | 289 current = results[i].getInteger(axis); |
296 currentPoint = getPoint(results[i]); | 290 currentPoint = getPoint(results[i]); |
297 double distance = DistanceCalculator.calculateDistance( | 291 |
298 firstPoint, | 292 distanceOld = distance; |
293 distance += DistanceCalculator.calculateDistance( | |
294 lastPoint, | |
299 currentPoint); | 295 currentPoint); |
300 double distanceOld = DistanceCalculator.calculateDistance( | |
301 firstPoint, | |
302 lastPoint); | |
303 | 296 |
304 boolean detected = gridDetection(last, current); | 297 boolean detected = gridDetection(last, current); |
305 | 298 |
306 if (log.isDebugEnabled()) { | 299 if (log.isDebugEnabled()) { |
307 log.debug("Last point: " + lastPoint.toString()); | 300 log.debug("Last point: " + lastPoint.toString()); |