Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java @ 644:f3882e94c7e0
Changed the way of calculating the total distance in 'Horizontalprofil'-charts (issue171).
gnv-artifacts/trunk@730 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 04 Mar 2010 09:18:53 +0000 |
parents | 24a85678bd39 |
children | b98d1adee7a6 |
comparison
equal
deleted
inserted
replaced
643:24a85678bd39 | 644:f3882e94c7e0 |
---|---|
25 extends VerticalProfileChart | 25 extends VerticalProfileChart |
26 { | 26 { |
27 private static Logger log = Logger.getLogger(HorizontalProfileChart.class); | 27 private static Logger log = Logger.getLogger(HorizontalProfileChart.class); |
28 | 28 |
29 private static WKTReader wktReader = new WKTReader(); | 29 private static WKTReader wktReader = new WKTReader(); |
30 private Point lastPoint; | 30 private Point firstPoint; |
31 private double distance; | |
32 | |
33 | 31 |
34 public HorizontalProfileChart( | 32 public HorizontalProfileChart( |
35 ChartLabels labels, | 33 ChartLabels labels, |
36 ChartTheme theme, | 34 ChartTheme theme, |
37 Collection parameters, | 35 Collection parameters, |
54 locale, | 52 locale, |
55 linesVisible, | 53 linesVisible, |
56 shapesVisible | 54 shapesVisible |
57 ); | 55 ); |
58 this.PLOT_ORIENTATION = PlotOrientation.VERTICAL; | 56 this.PLOT_ORIENTATION = PlotOrientation.VERTICAL; |
59 this.distance = 0; | |
60 } | 57 } |
61 | 58 |
62 | 59 |
63 protected void gapDetection( | 60 protected void gapDetection( |
64 Result[] results, | 61 Result[] results, |
92 log.debug("Gap detection finished."); | 89 log.debug("Gap detection finished."); |
93 } | 90 } |
94 | 91 |
95 | 92 |
96 protected void addValue(Result row, Series series) { | 93 protected void addValue(Result row, Series series) { |
94 double distance = 0; | |
95 | |
97 try { | 96 try { |
98 Point point = (Point) wktReader.read(row.getString("SHAPE")); | 97 Point point = (Point) wktReader.read(row.getString("SHAPE")); |
99 if (lastPoint != null) | 98 if (firstPoint != null) { |
100 distance = distance + DistanceCalculator.calculateDistance( | 99 distance = DistanceCalculator.calculateDistance( |
101 lastPoint, point | 100 firstPoint, point |
102 ); | 101 ); |
103 lastPoint = point; | 102 } |
103 else { | |
104 firstPoint = point; | |
105 } | |
104 | 106 |
105 ((XYSeries) series).add( | 107 ((XYSeries) series).add( |
106 distance, | 108 distance, |
107 row.getDouble("YORDINATE") | 109 row.getDouble("YORDINATE") |
108 ); | 110 ); |
114 | 116 |
115 | 117 |
116 protected void addSeries(Series series, String label, int idx) { | 118 protected void addSeries(Series series, String label, int idx) { |
117 super.addSeries(series, label, idx); | 119 super.addSeries(series, label, idx); |
118 | 120 |
119 // reset values used by current series for next series | 121 // reset firstPoint for next series |
120 lastPoint = null; | 122 firstPoint = null; |
121 distance = 0; | |
122 } | 123 } |
123 | 124 |
124 | 125 |
125 protected String createSeriesName( | 126 protected String createSeriesName( |
126 String breakPoint1, | 127 String breakPoint1, |
146 String axis = getDependendAxisName( | 147 String axis = getDependendAxisName( |
147 results[startPos], | 148 results[startPos], |
148 results[startPos+1] | 149 results[startPos+1] |
149 ); | 150 ); |
150 | 151 |
151 double range = 0; | |
152 double distance = 0; | |
153 int last = 0; | 152 int last = 0; |
154 int current = 0; | 153 int current = 0; |
155 Point lastPoint = null; | 154 Point lastPoint = null; |
156 Point currentPoint = null; | 155 Point currentPoint = null; |
156 | |
157 try { | |
158 firstPoint = getPoint(results[0]); | |
159 } | |
160 catch (ParseException pe) { | |
161 log.error("Unable to parse start point for gap detection."); | |
162 return; | |
163 } | |
157 | 164 |
158 for (int i = startPos+1; i < endPos; i++) { | 165 for (int i = startPos+1; i < endPos; i++) { |
159 try { | 166 try { |
160 last = results[i-1].getInteger(axis); | 167 last = results[i-1].getInteger(axis); |
161 lastPoint = getPoint(results[i-1]); | 168 lastPoint = getPoint(results[i-1]); |
162 current = results[i].getInteger(axis); | 169 current = results[i].getInteger(axis); |
163 currentPoint = getPoint(results[i]); | 170 currentPoint = getPoint(results[i]); |
164 distance = DistanceCalculator.calculateDistance( | 171 double distance = DistanceCalculator.calculateDistance( |
165 lastPoint, | 172 firstPoint, |
166 currentPoint | 173 currentPoint); |
167 ); | 174 double distanceOld = DistanceCalculator.calculateDistance( |
175 firstPoint, | |
176 lastPoint); | |
168 | 177 |
169 boolean detected = gridDetection(last, current); | 178 boolean detected = gridDetection(last, current); |
170 | 179 |
171 if (log.isDebugEnabled()) { | 180 if (log.isDebugEnabled()) { |
172 log.debug("Current distance from start: " + range); | |
173 log.debug("Last point: " + lastPoint.toString()); | 181 log.debug("Last point: " + lastPoint.toString()); |
174 log.debug("Current point: " + currentPoint.toString()); | 182 log.debug("Current point: " + currentPoint.toString()); |
175 log.debug("Distance (current point - last point): " + distance); | 183 log.debug("Current distance from start: " + distance); |
176 } | 184 } |
177 | 185 |
178 if (detected) { | 186 if (detected) { |
179 log.info( | 187 log.info( |
180 "Gap detected on grid between " + range + | 188 "Gap detected on grid between " + distanceOld + |
181 " and " + (range+distance) | 189 " and " + distance); |
182 ); | 190 |
183 | 191 ((XYSeries) series).add(distance-1d, null); |
184 ((XYSeries) series).add(range+0.0001, null); | 192 ((XYSeries) series).add(distanceOld+1d, null); |
185 } | 193 } |
186 | |
187 range += distance; | |
188 } | 194 } |
189 catch (ParseException pe) { | 195 catch (ParseException pe) { |
190 log.warn("Error while parsing point for gap detection.", pe); | 196 log.warn("Error while parsing point for gap detection.", pe); |
191 } | 197 } |
192 } | 198 } |