Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChartFactory.java @ 176:bff7bbb7c6f0
Add Spatial-Query-Syntax to HorizontalProfile-Queries and use Geometry to Calculate the X-Ordinate of the Chart.
gnv-artifacts/trunk@219 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Wed, 14 Oct 2009 10:49:35 +0000 |
parents | 7fb9441dd8af |
children | f2c76f35da5a |
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChartFactory.java Tue Oct 13 10:30:01 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChartFactory.java Wed Oct 14 10:49:35 2009 +0000 @@ -22,6 +22,9 @@ import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.xy.XYSeries; +import com.vividsolutions.jts.geom.Point; +import com.vividsolutions.jts.io.WKTReader; + import de.intevation.gnv.chart.exception.TechnicalChartException; import de.intevation.gnv.geobackend.base.Result; @@ -38,6 +41,8 @@ private static Logger sLogger = Logger .getLogger(HorizontalProfileChartFactory.class); private static boolean sDebug = sLogger.isDebugEnabled(); + + private WKTReader wktReader = new WKTReader(); public HorizontalProfileChartFactory() { super(); @@ -64,32 +69,22 @@ sLogger.debug("createXYSeries()"); XYSeries series = new XYSeries(seriesName); try { - double xValue = 0; - double yValue = 0; - double xStartCoord = 0; - double yStartCoord = 0; + Point lastPoint = null; + double distance = 0; int i = 0; Iterator<Result> resultIterator = resultSet.iterator(); while (resultIterator.hasNext()) { Result lRow = resultIterator.next(); if (i >= pStart && i <= pEnd) { - if (xStartCoord == 0 && yStartCoord == 0) { - xStartCoord = lRow.getDouble("XORDINATE_XCOORD"); - yStartCoord = lRow.getDouble("XORDINATE_YCOORD"); + Point p = (Point)wktReader.read(lRow.getString("SHAPE")); + if (lastPoint != null) { + distance = distance +p.distance(lastPoint); // TODO in Meter umrechnen } - - double currentXCoord = lRow.getDouble("XORDINATE_XCOORD"); - ; - double currentYCoord = lRow.getDouble("XORDINATE_YCOORD"); - - xValue = this.calculateDistance(xStartCoord, yStartCoord, - currentXCoord, currentYCoord); - - yValue = lRow.getDouble("YORDINATE"); - series.add(xValue, yValue); - sLogger.debug(seriesName + " Added Value " + xValue + " / " + lastPoint = p; + double yValue = lRow.getDouble("YORDINATE"); + series.add(distance, yValue); + sLogger.debug(seriesName + " Added Value " + distance + " / " + yValue); - } else if (i > pEnd) { return series; } @@ -103,14 +98,6 @@ sLogger.error(e.getMessage(), e); } finally { } - return series; } - - private double calculateDistance(double xStartCoord, double yStartCoord, - double currentXCoord, double currentYCoord) { - double dx = xStartCoord - currentXCoord; - double dy = yStartCoord - currentYCoord; - return Math.sqrt((dx * dx) + (dy * dy)); - } }