comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 1122:111794adf285

Get real (but yet not parameterized) data to display in CrossSection. flys-artifacts/trunk@2631 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 01 Sep 2011 12:15:46 +0000
parents 05e4ef0f9489
children 65d8b3340397
comparison
equal deleted inserted replaced
1121:66783d957201 1122:111794adf285
1 package de.intevation.flys.artifacts; 1 package de.intevation.flys.artifacts;
2
3 import java.awt.geom.Point2D;
2 4
3 import de.intevation.artifactdatabase.ProtocolUtils; 5 import de.intevation.artifactdatabase.ProtocolUtils;
4 6
5 import de.intevation.artifactdatabase.data.StateData; 7 import de.intevation.artifactdatabase.data.StateData;
6 8
37 import de.intevation.flys.artifacts.states.LocationDistanceSelect; 39 import de.intevation.flys.artifacts.states.LocationDistanceSelect;
38 40
39 import de.intevation.flys.model.Gauge; 41 import de.intevation.flys.model.Gauge;
40 import de.intevation.flys.model.River; 42 import de.intevation.flys.model.River;
41 import de.intevation.flys.model.CrossSection; 43 import de.intevation.flys.model.CrossSection;
44 import de.intevation.flys.model.CrossSectionLine;
45 import de.intevation.flys.model.CrossSectionPoint;
42 46
43 import de.intevation.flys.utils.DoubleUtil; 47 import de.intevation.flys.utils.DoubleUtil;
44 import de.intevation.flys.utils.FLYSUtils; 48 import de.intevation.flys.utils.FLYSUtils;
45 49
46 import gnu.trove.TDoubleArrayList; 50 import gnu.trove.TDoubleArrayList;
54 import org.apache.log4j.Logger; 58 import org.apache.log4j.Logger;
55 59
56 import org.w3c.dom.Document; 60 import org.w3c.dom.Document;
57 import org.w3c.dom.Element; 61 import org.w3c.dom.Element;
58 import org.w3c.dom.Node; 62 import org.w3c.dom.Node;
63
64 import de.intevation.flys.artifacts.charts.CrossSectionApp;
59 65
60 /** 66 /**
61 * The default WINFO artifact. 67 * The default WINFO artifact.
62 * 68 *
63 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 69 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
597 return Collections.emptyList(); 603 return Collections.emptyList();
598 } 604 }
599 return Segment.parseSegments(input); 605 return Segment.parseSegments(input);
600 } 606 }
601 607
602 public List<CrossSection> getCrossSections() { 608
609 /**
610 * Get List of all cross-sections for current river.
611 *
612 * @return List of CrossSections for current river, null in case of error.
613 */
614 protected List<CrossSection> getCrossSections() {
603 River river = FLYSUtils.getRiver(this); 615 River river = FLYSUtils.getRiver(this);
604 if (river == null) { 616 if (river == null) {
605 logger.warn("No river in WINFO found"); 617 logger.warn("No river in WINFO found");
606 return null; 618 return null;
607 } 619 }
608 return CrossSectionFactory.getCrossSections(river); 620 return CrossSectionFactory.getCrossSections(river);
621 }
622
623
624 /**
625 * Get sorted, valid Points of a CrossSectionLine.
626 *
627 * @param line line of interest.
628 *
629 * @return list of points of CrossSectionLine, sorted.
630 */
631 protected List<Point2D> getCrossSectionLinesPoints(CrossSectionLine line) {
632 List<Point2D> points = new ArrayList<Point2D>();
633 List<CrossSectionPoint> linePoints = line.getPoints();
634 if (linePoints.isEmpty()) {
635 logger.info("No points in selected CrossSectionLine.");
636 return points;
637 }
638 Collections.sort(linePoints, CrossSectionApp.COL_POS_CMP);
639 for (CrossSectionPoint p: linePoints) {
640 double x = p.getX().doubleValue();
641 double y = p.getY().doubleValue();
642 if (CrossSectionApp.isValid(x) && CrossSectionApp.isValid(y)) {
643 points.add(new Point2D.Double(x,y));
644 }
645 }
646 return points;
647 }
648
649
650 /**
651 * Get points of Profile of cross section.
652 *
653 * @return an array holding coordinates of points of profile (
654 * in the form {{x1, x2} {y1, y2}} ).
655 */
656 public double [][] getCrossSectionData() {
657 return getCrossSectionProfile(getCrossSections().get(0).getLines().get(0));
658 }
659
660
661 /**
662 * Get points of line describing the surface of water at cross section.
663 *
664 * @return an array holding coordinates of points of surface of water (
665 * in the form {{x1, x2} {y1, y2}} ).
666 */
667
668 public double [][] getWaterLines() {
669 CrossSectionLine csl = getCrossSections().get(0).getLines().get(0);
670 List<Point2D> points = getCrossSectionLinesPoints(csl);
671 return CrossSectionApp.createWaterLines(points, 130);
672 }
673
674
675 /**
676 * Get points of CrossSection Line.
677 */
678 protected double [][] getCrossSectionProfile(CrossSectionLine csl) {
679 List<Point2D> points = getCrossSectionLinesPoints(csl);
680 double [] xs = new double[points.size()];
681 double [] ys = new double[points.size()];
682
683 if (points.isEmpty()) {
684 return new double [][] {xs, ys};
685 }
686
687 xs[0] = points.get(0).getX();
688 ys[0] = points.get(0).getY();
689
690 for (int i = 1; i < points.size(); i++) {
691 Point2D p = points.get(i);
692 xs[i] = p.getX();
693 if (xs[i] < xs[i-1]) {
694 xs[i] = xs[i-1] + CrossSectionApp.EPSILON;
695 }
696 ys[i] = p.getY();
697 }
698 return new double [][] { xs, ys };
609 } 699 }
610 700
611 701
612 /** 702 /**
613 * Returns the Qs for a number of Ws. This method makes use of 703 * Returns the Qs for a number of Ws. This method makes use of

http://dive4elements.wald.intevation.org