# HG changeset patch # User Ingo Weinzierl # Date 1274795868 0 # Node ID 778d86255d76c6ab28aad54bb01ad325123bd422 # Parent b5d852991cbf03b3c6e6d8060f7146e8a92b367a 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 diff -r b5d852991cbf -r 778d86255d76 gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Mon May 24 17:07:26 2010 +0000 +++ b/gnv-artifacts/ChangeLog Tue May 25 13:57:48 2010 +0000 @@ -1,3 +1,11 @@ +2010-05-25 Ingo Weinzierl + + Issue287 + + * src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java: + Corrected the distance calculation of a 'Horizontal Profil' and adjusted + the gap detection according to these changes. + 2010-05-24 Ingo Weinzierl Issue290 diff -r b5d852991cbf -r 778d86255d76 gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java Mon May 24 17:07:26 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java Tue May 25 13:57:48 2010 +0000 @@ -53,7 +53,9 @@ * The first point in a HorizontalProfileChart. It is used to calculate the * distance between the currently processed point an the start. */ - private Point firstPoint; + protected Point lastPoint; + + protected double distance = 0d; /** * Constructor used to create horizontal profile charts. @@ -147,23 +149,20 @@ @Override protected void addValue(Result row, Series series) { - double distance = 0; - try { Point point = (Point) wktReader.read(row.getString("SHAPE")); - if (firstPoint != null) { - distance = DistanceCalculator.calculateDistance( - firstPoint, point + if (lastPoint != null) { + distance += DistanceCalculator.calculateDistance( + lastPoint, point ); } - else { - firstPoint = point; - } ((XYSeries) series).add( distance, row.getDouble("YORDINATE") ); + + lastPoint = point; } catch(ParseException pe) { log.warn("No data found while parsing."); @@ -175,8 +174,9 @@ protected void addSeries(Series series, String label, int idx) { super.addSeries(series, label, idx); - // reset firstPoint for next series - firstPoint = null; + // reset lastPoint and distance of the last series + lastPoint = null; + distance = 0; } @@ -280,26 +280,19 @@ 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; - } - + double distance = 0; + double distanceOld = 0; 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]); - double distance = DistanceCalculator.calculateDistance( - firstPoint, + + distanceOld = distance; + distance += DistanceCalculator.calculateDistance( + lastPoint, currentPoint); - double distanceOld = DistanceCalculator.calculateDistance( - firstPoint, - lastPoint); boolean detected = gridDetection(last, current);