comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 1139:6d9b08b958e2

Fix waterline in crosssection diagram. flys-artifacts/trunk@2660 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 07 Sep 2011 09:24:32 +0000
parents d90f5bfa3ddf
children 01d42a2454f6
comparison
equal deleted inserted replaced
1138:d90f5bfa3ddf 1139:6d9b08b958e2
647 return points; 647 return points;
648 } 648 }
649 649
650 650
651 /** 651 /**
652 * Get points of Profile of cross section. 652 * Get CrossSectionLine spatially closest to what is specified in the data
653 * 653 * "cross_section.km".
654 * @return an array holding coordinates of points of profile ( 654 *
655 * in the form {{x1, x2} {y1, y2}} ). 655 * @return CrossSectionLine closest to "cross_section.km".
656 */ 656 */
657 public double [][] getCrossSectionData() { 657 protected CrossSectionLine searchCrossSectionKmLine() {
658 logger.info("getCrossSectionData(), also cross_section.km " + getDataAsString("cross_section.km"));
659 double wishKM = 0.0f; 658 double wishKM = 0.0f;
660 try { 659 try {
661 wishKM = Double.parseDouble(getDataAsString("cross_section.km")); 660 wishKM = Double.parseDouble(getDataAsString("cross_section.km"));
662 } 661 }
663 catch (Exception e) { 662 catch (Exception e) {
664 ; 663 ;
665 } 664 }
666 665
667 // Get the cross section closest to requested km. 666 // Get the cross section closest to requested km.
668 //
669 // Naive, linear approach. 667 // Naive, linear approach.
670 List<CrossSectionLine> crossSectionLines = 668 List<CrossSectionLine> crossSectionLines =
671 getCrossSections().get(0).getLines(); 669 getCrossSections().get(0).getLines();
672 CrossSectionLine oldLine = crossSectionLines.get(0); 670 CrossSectionLine oldLine = crossSectionLines.get(0);
673 double oldDiff = Math.abs(wishKM - oldLine.getKm().doubleValue()); 671 double oldDiff = Math.abs(wishKM - oldLine.getKm().doubleValue());
677 break; 675 break;
678 } 676 }
679 oldDiff = diff; 677 oldDiff = diff;
680 oldLine = line; 678 oldLine = line;
681 } 679 }
682 return getCrossSectionProfile(oldLine); 680 return oldLine;
681 }
682
683
684 /**
685 * Get points of Profile of cross section.
686 *
687 * @return an array holding coordinates of points of profile (
688 * in the form {{x1, x2} {y1, y2}} ).
689 */
690 public double [][] getCrossSectionData() {
691 logger.info("getCrossSectionData() for cross_section.km "
692 + getDataAsString("cross_section.km"));
693 CrossSectionLine line = searchCrossSectionKmLine();
694 return getCrossSectionProfile(line);
683 } 695 }
684 696
685 697
686 /** 698 /**
687 * Get points of line describing the surface of water at cross section. 699 * Get points of line describing the surface of water at cross section.
688 * 700 *
689 * @return an array holding coordinates of points of surface of water ( 701 * @return an array holding coordinates of points of surface of water (
690 * in the form {{x1, x2} {y1, y2}} ). 702 * in the form {{x1, x2} {y1, y2}} ).
691 */ 703 */
692
693 public double [][] getWaterLines() { 704 public double [][] getWaterLines() {
694 CrossSectionLine csl = getCrossSections().get(0).getLines().get(0); 705 logger.debug("getWaterLines()");
706 CrossSectionLine csl = searchCrossSectionKmLine();
695 List<Point2D> points = getCrossSectionLinesPoints(csl); 707 List<Point2D> points = getCrossSectionLinesPoints(csl);
696 return CrossSectionApp.createWaterLines(points, 130); 708 // Need W at km
709 WQKms [] wqkms = (WQKms[]) getWaterlevelData().getData();
710 if (wqkms.length == 0) {
711 logger.error("No WQKms found.");
712 return CrossSectionApp.createWaterLines(points, 0.0f);
713 }
714 else
715 {
716 if (wqkms.length > 1) {
717 logger.warn("More than one wqkms found, taking first one.");
718 }
719 // Find W at km, linear naive approach.
720 WQKms triple = wqkms[0];
721 // Find index of km.
722 double wishKM = 0.0f;
723 int old_idx = 0;
724 try {
725 wishKM = Double.parseDouble(getDataAsString("cross_section.km"));
726 }
727 catch (Exception e) {
728 ;
729 }
730
731 // Linear seach in WQKms for closest km.
732 double old_dist_wish = Math.abs(wishKM - triple.getKm(0));
733
734 for (int i = 0; i < triple.size(); i++) {
735 double diff = Math.abs(wishKM - triple.getKm(i));
736 if (diff > old_dist_wish) {
737 return CrossSectionApp.createWaterLines(points,
738 triple.getW(i));
739 }
740 old_dist_wish = diff;
741 }
742 return CrossSectionApp.createWaterLines(points,
743 triple.getW(triple.size()-1));
744 }
697 } 745 }
698 746
699 747
700 /** 748 /**
701 * Get name of cross section. 749 * Get name of cross section.
1064 */ 1112 */
1065 public double[] getWs() { 1113 public double[] getWs() {
1066 StateData dMode = getData("wq_mode"); 1114 StateData dMode = getData("wq_mode");
1067 StateData dSingle = getData("wq_single"); 1115 StateData dSingle = getData("wq_single");
1068 1116
1069 String mode = dMode != null ? (String) dMode.getValue() : ""; 1117 String mode = (dMode != null) ? (String) dMode.getValue() : "";
1070 1118
1071 if (mode.equals("W")) { 1119 if (mode.equals("W")) {
1072 if (dSingle != null) { 1120 if (dSingle != null) {
1073 return getSingleWQValues(); 1121 return getSingleWQValues();
1074 } 1122 }

http://dive4elements.wald.intevation.org