comparison 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
comparison
equal deleted inserted replaced
1650:aaf8d32f85bd 1651:a7def20539fb
38 import de.intevation.flys.artifacts.model.WstValueTableFactory; 38 import de.intevation.flys.artifacts.model.WstValueTableFactory;
39 39
40 import de.intevation.flys.artifacts.states.DefaultState; 40 import de.intevation.flys.artifacts.states.DefaultState;
41 import de.intevation.flys.artifacts.states.LocationDistanceSelect; 41 import de.intevation.flys.artifacts.states.LocationDistanceSelect;
42 42
43 import de.intevation.flys.geom.Lines;
44
43 import de.intevation.flys.model.Gauge; 45 import de.intevation.flys.model.Gauge;
44 import de.intevation.flys.model.River; 46 import de.intevation.flys.model.River;
45 import de.intevation.flys.model.CrossSection; 47 import de.intevation.flys.model.CrossSection;
46 import de.intevation.flys.model.CrossSectionLine; 48 import de.intevation.flys.model.CrossSectionLine;
47 import de.intevation.flys.model.CrossSectionPoint;
48 49
49 import de.intevation.flys.utils.DoubleUtil; 50 import de.intevation.flys.utils.DoubleUtil;
50 import de.intevation.flys.utils.FLYSUtils; 51 import de.intevation.flys.utils.FLYSUtils;
51 52
52 import gnu.trove.TDoubleArrayList; 53 import gnu.trove.TDoubleArrayList;
62 63
63 import org.w3c.dom.Document; 64 import org.w3c.dom.Document;
64 import org.w3c.dom.Element; 65 import org.w3c.dom.Element;
65 import org.w3c.dom.Node; 66 import org.w3c.dom.Node;
66 67
67 import de.intevation.flys.artifacts.charts.CrossSectionApp;
68 import de.intevation.flys.artifacts.model.CalculationMessage; 68 import de.intevation.flys.artifacts.model.CalculationMessage;
69 69
70 /** 70 /**
71 * The default WINFO artifact. 71 * The default WINFO artifact.
72 * 72 *
663 return CrossSectionFactory.getCrossSections(river); 663 return CrossSectionFactory.getCrossSections(river);
664 } 664 }
665 665
666 666
667 /** 667 /**
668 * Get sorted, valid Points of a CrossSectionLine.
669 *
670 * @param line line of interest.
671 *
672 * @return list of points of CrossSectionLine, sorted.
673 */
674 protected List<Point2D> getCrossSectionLinesPoints(CrossSectionLine line) {
675 List<Point2D> points = new ArrayList<Point2D>();
676
677 if (line == null) {
678 return points;
679 }
680
681 List<CrossSectionPoint> linePoints = line.getPoints();
682 if (linePoints.isEmpty()) {
683 logger.info("No points in selected CrossSectionLine.");
684 return points;
685 }
686 Collections.sort(linePoints, CrossSectionApp.COL_POS_CMP);
687 for (CrossSectionPoint p: linePoints) {
688 double x = p.getX().doubleValue();
689 double y = p.getY().doubleValue();
690 if (CrossSectionApp.isValid(x) && CrossSectionApp.isValid(y)) {
691 points.add(new Point2D.Double(x,y));
692 }
693 }
694 return points;
695 }
696
697
698 /**
699 * Get CrossSectionLine spatially closest to what is specified in the data 668 * Get CrossSectionLine spatially closest to what is specified in the data
700 * "cross_section.km". 669 * "cross_section.km".
701 * 670 *
702 * @return CrossSectionLine closest to "cross_section.km". 671 * @return CrossSectionLine closest to "cross_section.km".
703 */ 672 */
705 double wishKM = 0.0f; 674 double wishKM = 0.0f;
706 try { 675 try {
707 wishKM = Double.parseDouble(getDataAsString("cross_section.km")); 676 wishKM = Double.parseDouble(getDataAsString("cross_section.km"));
708 } 677 }
709 catch (Exception e) { 678 catch (Exception e) {
710 ; 679 logger.warn(e);
711 } 680 }
712 681
713 // Get the cross section closest to requested km. 682 // Get the cross section closest to requested km.
714 // Naive, linear approach. 683 // Naive, linear approach.
715 List<CrossSection> sections = getCrossSections(); 684 List<CrossSection> sections = getCrossSections();
759 */ 728 */
760 public double [][] getCrossSectionData() { 729 public double [][] getCrossSectionData() {
761 logger.info("getCrossSectionData() for cross_section.km " 730 logger.info("getCrossSectionData() for cross_section.km "
762 + getDataAsString("cross_section.km")); 731 + getDataAsString("cross_section.km"));
763 CrossSectionLine line = searchCrossSectionKmLine(); 732 CrossSectionLine line = searchCrossSectionKmLine();
764 return getCrossSectionProfile(line); 733 return line != null ? line.fetchCrossSectionProfile() : null;
765 } 734 }
766 735
767 736
768 /** 737 /**
769 * Get points of line describing the surface of water at cross section. 738 * Get points of line describing the surface of water at cross section.
772 * in the form {{x1, x2} {y1, y2}} ). 741 * in the form {{x1, x2} {y1, y2}} ).
773 */ 742 */
774 public double [][] getWaterLines() { 743 public double [][] getWaterLines() {
775 logger.debug("getWaterLines()"); 744 logger.debug("getWaterLines()");
776 CrossSectionLine csl = searchCrossSectionKmLine(); 745 CrossSectionLine csl = searchCrossSectionKmLine();
777 List<Point2D> points = getCrossSectionLinesPoints(csl); 746 List<Point2D> points = csl.fetchCrossSectionLinesPoints();
778 // Need W at km 747 // Need W at km
779 WQKms [] wqkms = (WQKms[]) getWaterlevelData().getData(); 748 WQKms [] wqkms = (WQKms[]) getWaterlevelData().getData();
780 if (wqkms.length == 0) { 749 if (wqkms.length == 0) {
781 logger.error("No WQKms found."); 750 logger.error("No WQKms found.");
782 return CrossSectionApp.createWaterLines(points, 0.0f); 751 return Lines.createWaterLines(points, 0.0f);
783 } 752 }
784 else 753
785 { 754 if (wqkms.length > 1) {
786 if (wqkms.length > 1) { 755 logger.warn("More than one wqkms found, taking first one.");
787 logger.warn("More than one wqkms found, taking first one."); 756 }
788 } 757 // Find W at km, linear naive approach.
789 // Find W at km, linear naive approach. 758 WQKms triple = wqkms[0];
790 WQKms triple = wqkms[0]; 759 // Find index of km.
791 // Find index of km. 760 double wishKM = 0.0f;
792 double wishKM = 0.0f; 761 int old_idx = 0;
793 int old_idx = 0; 762 try {
794 try { 763 wishKM = Double.parseDouble(getDataAsString("cross_section.km"));
795 wishKM = Double.parseDouble(getDataAsString("cross_section.km")); 764 }
796 } 765 catch (Exception e) {
797 catch (Exception e) { 766 logger.warn(e);
798 ; 767 }
799 } 768
800 769 if (triple.size() == 0) {
801 if (triple.size() == 0) { 770 logger.warn("Calculation of waterline is empty.");
802 logger.warn("Calculation of waterline is empty."); 771 return Lines.createWaterLines(points, 0.0f);
803 return CrossSectionApp.createWaterLines(points, 0.0f); 772 }
804 } 773
805 774 // Linear seach in WQKms for closest km.
806 // Linear seach in WQKms for closest km. 775 double old_dist_wish = Math.abs(wishKM - triple.getKm(0));
807 double old_dist_wish = Math.abs(wishKM - triple.getKm(0)); 776 double last_w = triple.getW(0);
808 double last_w = triple.getW(0); 777
809 778 for (int i = 0, T = triple.size(); i < T; i++) {
810 for (int i = 0; i < triple.size(); i++) { 779 double diff = Math.abs(wishKM - triple.getKm(i));
811 double diff = Math.abs(wishKM - triple.getKm(i)); 780 if (diff > old_dist_wish) {
812 if (diff > old_dist_wish) { 781 break;
813 break; 782 }
814 } 783 last_w = triple.getW(i);
815 last_w = triple.getW(i); 784 old_dist_wish = diff;
816 old_dist_wish = diff; 785 }
817 } 786 return Lines.createWaterLines(points, last_w);
818 return CrossSectionApp.createWaterLines(points, last_w);
819 }
820 } 787 }
821 788
822 789
823 /** 790 /**
824 * Get name of cross section. 791 * Get name of cross section.
830 return sections.get(0).getDescription(); 797 return sections.get(0).getDescription();
831 } 798 }
832 else { 799 else {
833 return ""; 800 return "";
834 } 801 }
835 }
836
837
838 /**
839 * Get points of CrossSection Line.
840 * @param csl The crossSectionline of interest.
841 * @return x and y positions of cross section profile.
842 */
843 protected double [][] getCrossSectionProfile(CrossSectionLine csl) {
844 List<Point2D> points = getCrossSectionLinesPoints(csl);
845 double [] xs = new double[points.size()];
846 double [] ys = new double[points.size()];
847
848 if (points.isEmpty()) {
849 return new double [][] {xs, ys};
850 }
851
852 xs[0] = points.get(0).getX();
853 ys[0] = points.get(0).getY();
854
855 for (int i = 1; i < points.size(); i++) {
856 Point2D p = points.get(i);
857 xs[i] = p.getX();
858 if (xs[i] < xs[i-1]) {
859 xs[i] = xs[i-1] + CrossSectionApp.EPSILON;
860 }
861 ys[i] = p.getY();
862 }
863 return new double [][] { xs, ys };
864 } 802 }
865 803
866 804
867 /** 805 /**
868 * Returns the Qs for a number of Ws. This method makes use of 806 * Returns the Qs for a number of Ws. This method makes use of

http://dive4elements.wald.intevation.org