Mercurial > dive4elements > gnv-client
changeset 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 | 0cf162fa4334 |
files | gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java |
diffstat | 2 files changed, 44 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Thu Mar 04 08:03:56 2010 +0000 +++ b/gnv-artifacts/ChangeLog Thu Mar 04 09:18:53 2010 +0000 @@ -1,3 +1,16 @@ +2010-03-04 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + Issue171 + + * src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java: Changed + the way to calculate the current distance from startpoint. We do not + calculate the distance between the current point and the last point and + add this value to a variable storing the total distance anymore, but + we take the distance between the current point and the start point. On + this way, we do not need a variable to store the total distance, because + current point - first point == total distance. And there is no + impreciseness in gaps of different layers (see issue171 for this). + 2010-03-04 Ingo Weinzierl <ingo.weinzierl@intevation.de> * src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java: Added
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java Thu Mar 04 08:03:56 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java Thu Mar 04 09:18:53 2010 +0000 @@ -27,9 +27,7 @@ private static Logger log = Logger.getLogger(HorizontalProfileChart.class); private static WKTReader wktReader = new WKTReader(); - private Point lastPoint; - private double distance; - + private Point firstPoint; public HorizontalProfileChart( ChartLabels labels, @@ -56,7 +54,6 @@ shapesVisible ); this.PLOT_ORIENTATION = PlotOrientation.VERTICAL; - this.distance = 0; } @@ -94,13 +91,18 @@ protected void addValue(Result row, Series series) { + double distance = 0; + try { Point point = (Point) wktReader.read(row.getString("SHAPE")); - if (lastPoint != null) - distance = distance + DistanceCalculator.calculateDistance( - lastPoint, point + if (firstPoint != null) { + distance = DistanceCalculator.calculateDistance( + firstPoint, point ); - lastPoint = point; + } + else { + firstPoint = point; + } ((XYSeries) series).add( distance, @@ -116,9 +118,8 @@ protected void addSeries(Series series, String label, int idx) { super.addSeries(series, label, idx); - // reset values used by current series for next series - lastPoint = null; - distance = 0; + // reset firstPoint for next series + firstPoint = null; } @@ -148,43 +149,48 @@ results[startPos+1] ); - double range = 0; - double distance = 0; int last = 0; int current = 0; Point lastPoint = null; Point currentPoint = null; + try { + firstPoint = getPoint(results[0]); + } + catch (ParseException pe) { + log.error("Unable to parse start point for gap detection."); + return; + } + for (int i = startPos+1; i < endPos; i++) { try { last = results[i-1].getInteger(axis); lastPoint = getPoint(results[i-1]); current = results[i].getInteger(axis); currentPoint = getPoint(results[i]); - distance = DistanceCalculator.calculateDistance( - lastPoint, - currentPoint - ); + double distance = DistanceCalculator.calculateDistance( + firstPoint, + currentPoint); + double distanceOld = DistanceCalculator.calculateDistance( + firstPoint, + lastPoint); boolean detected = gridDetection(last, current); if (log.isDebugEnabled()) { - log.debug("Current distance from start: " + range); log.debug("Last point: " + lastPoint.toString()); log.debug("Current point: " + currentPoint.toString()); - log.debug("Distance (current point - last point): " + distance); + log.debug("Current distance from start: " + distance); } if (detected) { log.info( - "Gap detected on grid between " + range + - " and " + (range+distance) - ); + "Gap detected on grid between " + distanceOld + + " and " + distance); - ((XYSeries) series).add(range+0.0001, null); + ((XYSeries) series).add(distance-1d, null); + ((XYSeries) series).add(distanceOld+1d, null); } - - range += distance; } catch (ParseException pe) { log.warn("Error while parsing point for gap detection.", pe);