# HG changeset patch # User Ingo Weinzierl # Date 1267694333 0 # Node ID f3882e94c7e0a3bc3fac01ed02ee112f5ea22775 # Parent 24a85678bd39cd5263d0a4807d7aa61208c90d85 Changed the way of calculating the total distance in 'Horizontalprofil'-charts (issue171). gnv-artifacts/trunk@730 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 24a85678bd39 -r f3882e94c7e0 gnv-artifacts/ChangeLog --- 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 + + 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 * src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java: Added diff -r 24a85678bd39 -r f3882e94c7e0 gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java --- 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);