comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 1803:51e59f221333

Minor preparations for WINFO/CrossSection to handle multiple cross-sections. flys-artifacts/trunk@3128 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 01 Nov 2011 12:23:59 +0000
parents 26d7077e42d2
children f6a190f6aaff
comparison
equal deleted inserted replaced
1802:26d7077e42d2 1803:51e59f221333
668 } 668 }
669 669
670 670
671 /** 671 /**
672 * Get CrossSectionLine spatially closest to what is specified in the data 672 * Get CrossSectionLine spatially closest to what is specified in the data
673 * "cross_section.km". 673 * "cross_section.km" (and from "cross_section.index").
674 * 674 *
675 * @return CrossSectionLine closest to "cross_section.km". 675 * @return CrossSectionLine closest to "cross_section.km".
676 */ 676 */
677 protected CrossSectionLine searchCrossSectionKmLine() { 677 protected CrossSectionLine searchCrossSectionKmLine() {
678 double wishKM = 0.0f; 678 double wishKM = 0.0f;
679 try { 679 try {
680 wishKM = Double.parseDouble(getDataAsString("cross_section.km")); 680 wishKM = Double.parseDouble(getDataAsString("cross_section.km"));
681 } 681 }
682 catch (Exception e) { 682 catch (Exception e) {
683 logger.warn(e); 683 logger.warn("Exception when parsing cross_section.km", e);
684 }
685
686 int crossSectionIdx = 0;
687
688 List<CrossSection> sections = getCrossSections();
689 if (sections.size() < crossSectionIdx) {
690 logger.error("Cross-section not found: " + crossSectionIdx);
691 return null;
692 }
693 if (sections.size() == 0
694 || sections.get(crossSectionIdx).getLines().size() == 0)
695 {
696 return null;
684 } 697 }
685 698
686 // Get the cross section closest to requested km. 699 // Get the cross section closest to requested km.
687 // Naive, linear approach. 700 // Naive, linear approach.
688 List<CrossSection> sections = getCrossSections();
689 if (sections.size() == 0 || sections.get(0).getLines().size() == 0) {
690 return null;
691 }
692 List<CrossSectionLine> crossSectionLines = 701 List<CrossSectionLine> crossSectionLines =
693 sections.get(0).getLines(); 702 sections.get(crossSectionIdx).getLines();
694 CrossSectionLine oldLine = crossSectionLines.get(0); 703 CrossSectionLine oldLine = crossSectionLines.get(0);
695 double oldDiff = Math.abs(wishKM - oldLine.getKm().doubleValue()); 704 double oldDiff = Math.abs(wishKM - oldLine.getKm().doubleValue());
696 for (CrossSectionLine line: crossSectionLines) { 705 for (CrossSectionLine line: crossSectionLines) {
697 double diff = Math.abs(wishKM - line.getKm().doubleValue()); 706 double diff = Math.abs(wishKM - line.getKm().doubleValue());
698 if (diff > oldDiff) { 707 if (diff > oldDiff) {
732 */ 741 */
733 public double [][] getCrossSectionData() { 742 public double [][] getCrossSectionData() {
734 logger.info("getCrossSectionData() for cross_section.km " 743 logger.info("getCrossSectionData() for cross_section.km "
735 + getDataAsString("cross_section.km")); 744 + getDataAsString("cross_section.km"));
736 CrossSectionLine line = searchCrossSectionKmLine(); 745 CrossSectionLine line = searchCrossSectionKmLine();
737 return line != null ? line.fetchCrossSectionProfile() : null; 746
747 return line != null
748 ? line.fetchCrossSectionProfile()
749 : null;
738 } 750 }
739 751
740 752
741 /** 753 /**
742 * Get points of line describing the surface of water at cross section. 754 * Get points of line describing the surface of water at cross section.
769 int old_idx = 0; 781 int old_idx = 0;
770 try { 782 try {
771 wishKM = Double.parseDouble(getDataAsString("cross_section.km")); 783 wishKM = Double.parseDouble(getDataAsString("cross_section.km"));
772 } 784 }
773 catch (Exception e) { 785 catch (Exception e) {
774 logger.warn(e); 786 logger.warn("Exception when trying to get cross_section.km", e);
775 } 787 }
776 788
777 if (triple.size() == 0) { 789 if (triple.size() == 0) {
778 logger.warn("Calculation of waterline is empty."); 790 logger.warn("Calculation of waterline is empty.");
779 return Lines.createWaterLines(points, 0.0f); 791 return Lines.createWaterLines(points, 0.0f);
794 return Lines.createWaterLines(points, last_w); 806 return Lines.createWaterLines(points, last_w);
795 } 807 }
796 808
797 809
798 /** 810 /**
799 * Get name of cross section. 811 * Get name of cross sections.
800 */ 812 * @return list of names of cross-sections.
801 public String getCrossSectionName() { 813 */
802 List<CrossSection> sections = getCrossSections(); 814 public List<String> getCrossSectionNames() {
803 815 List<String> names = new ArrayList<String>();
804 if (sections.size() > 0) { 816
805 return sections.get(0).getDescription(); 817 for (CrossSection section: getCrossSections()) {
806 } 818 names.add(section.getDescription());
807 else { 819 }
808 return ""; 820
809 } 821 return names;
810 } 822 }
811 823
812 824
813 /** 825 /**
814 * Returns the Qs for a number of Ws. This method makes use of 826 * Returns the Qs for a number of Ws. This method makes use of

http://dive4elements.wald.intevation.org