Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 1651:a7def20539fb
flys/issue317: Removed dependency from cross section demo app.
flys-artifacts/trunk@2840 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 27 Sep 2011 13:45:13 +0000 |
parents | a470b7c3b165 |
children | c85a84d60f68 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Tue Sep 27 12:40:42 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Tue Sep 27 13:45:13 2011 +0000 @@ -40,11 +40,12 @@ import de.intevation.flys.artifacts.states.DefaultState; import de.intevation.flys.artifacts.states.LocationDistanceSelect; +import de.intevation.flys.geom.Lines; + import de.intevation.flys.model.Gauge; import de.intevation.flys.model.River; import de.intevation.flys.model.CrossSection; import de.intevation.flys.model.CrossSectionLine; -import de.intevation.flys.model.CrossSectionPoint; import de.intevation.flys.utils.DoubleUtil; import de.intevation.flys.utils.FLYSUtils; @@ -64,7 +65,6 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; -import de.intevation.flys.artifacts.charts.CrossSectionApp; import de.intevation.flys.artifacts.model.CalculationMessage; /** @@ -665,37 +665,6 @@ /** - * Get sorted, valid Points of a CrossSectionLine. - * - * @param line line of interest. - * - * @return list of points of CrossSectionLine, sorted. - */ - protected List<Point2D> getCrossSectionLinesPoints(CrossSectionLine line) { - List<Point2D> points = new ArrayList<Point2D>(); - - if (line == null) { - return points; - } - - List<CrossSectionPoint> linePoints = line.getPoints(); - if (linePoints.isEmpty()) { - logger.info("No points in selected CrossSectionLine."); - return points; - } - Collections.sort(linePoints, CrossSectionApp.COL_POS_CMP); - for (CrossSectionPoint p: linePoints) { - double x = p.getX().doubleValue(); - double y = p.getY().doubleValue(); - if (CrossSectionApp.isValid(x) && CrossSectionApp.isValid(y)) { - points.add(new Point2D.Double(x,y)); - } - } - return points; - } - - - /** * Get CrossSectionLine spatially closest to what is specified in the data * "cross_section.km". * @@ -707,7 +676,7 @@ wishKM = Double.parseDouble(getDataAsString("cross_section.km")); } catch (Exception e) { - ; + logger.warn(e); } // Get the cross section closest to requested km. @@ -761,7 +730,7 @@ logger.info("getCrossSectionData() for cross_section.km " + getDataAsString("cross_section.km")); CrossSectionLine line = searchCrossSectionKmLine(); - return getCrossSectionProfile(line); + return line != null ? line.fetchCrossSectionProfile() : null; } @@ -774,49 +743,47 @@ public double [][] getWaterLines() { logger.debug("getWaterLines()"); CrossSectionLine csl = searchCrossSectionKmLine(); - List<Point2D> points = getCrossSectionLinesPoints(csl); + List<Point2D> points = csl.fetchCrossSectionLinesPoints(); // Need W at km WQKms [] wqkms = (WQKms[]) getWaterlevelData().getData(); if (wqkms.length == 0) { logger.error("No WQKms found."); - return CrossSectionApp.createWaterLines(points, 0.0f); + return Lines.createWaterLines(points, 0.0f); } - else - { - if (wqkms.length > 1) { - logger.warn("More than one wqkms found, taking first one."); - } - // Find W at km, linear naive approach. - WQKms triple = wqkms[0]; - // Find index of km. - double wishKM = 0.0f; - int old_idx = 0; - try { - wishKM = Double.parseDouble(getDataAsString("cross_section.km")); - } - catch (Exception e) { - ; - } - if (triple.size() == 0) { - logger.warn("Calculation of waterline is empty."); - return CrossSectionApp.createWaterLines(points, 0.0f); - } - - // Linear seach in WQKms for closest km. - double old_dist_wish = Math.abs(wishKM - triple.getKm(0)); - double last_w = triple.getW(0); + if (wqkms.length > 1) { + logger.warn("More than one wqkms found, taking first one."); + } + // Find W at km, linear naive approach. + WQKms triple = wqkms[0]; + // Find index of km. + double wishKM = 0.0f; + int old_idx = 0; + try { + wishKM = Double.parseDouble(getDataAsString("cross_section.km")); + } + catch (Exception e) { + logger.warn(e); + } - for (int i = 0; i < triple.size(); i++) { - double diff = Math.abs(wishKM - triple.getKm(i)); - if (diff > old_dist_wish) { - break; - } - last_w = triple.getW(i); - old_dist_wish = diff; + if (triple.size() == 0) { + logger.warn("Calculation of waterline is empty."); + return Lines.createWaterLines(points, 0.0f); + } + + // Linear seach in WQKms for closest km. + double old_dist_wish = Math.abs(wishKM - triple.getKm(0)); + double last_w = triple.getW(0); + + for (int i = 0, T = triple.size(); i < T; i++) { + double diff = Math.abs(wishKM - triple.getKm(i)); + if (diff > old_dist_wish) { + break; } - return CrossSectionApp.createWaterLines(points, last_w); + last_w = triple.getW(i); + old_dist_wish = diff; } + return Lines.createWaterLines(points, last_w); } @@ -836,35 +803,6 @@ /** - * Get points of CrossSection Line. - * @param csl The crossSectionline of interest. - * @return x and y positions of cross section profile. - */ - protected double [][] getCrossSectionProfile(CrossSectionLine csl) { - List<Point2D> points = getCrossSectionLinesPoints(csl); - double [] xs = new double[points.size()]; - double [] ys = new double[points.size()]; - - if (points.isEmpty()) { - return new double [][] {xs, ys}; - } - - xs[0] = points.get(0).getX(); - ys[0] = points.get(0).getY(); - - for (int i = 1; i < points.size(); i++) { - Point2D p = points.get(i); - xs[i] = p.getX(); - if (xs[i] < xs[i-1]) { - xs[i] = xs[i-1] + CrossSectionApp.EPSILON; - } - ys[i] = p.getY(); - } - return new double [][] { xs, ys }; - } - - - /** * Returns the Qs for a number of Ws. This method makes use of * DischargeTables.getQForW(). *