comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 1155:854c2f7da3f1

Fix flys/issue279 . flys-artifacts/trunk@2686 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 09 Sep 2011 13:02:23 +0000
parents 24b87650136f
children a470b7c3b165
comparison
equal deleted inserted replaced
1154:24b87650136f 1155:854c2f7da3f1
72 public class WINFOArtifact extends FLYSArtifact { 72 public class WINFOArtifact extends FLYSArtifact {
73 73
74 /** The logger for this class. */ 74 /** The logger for this class. */
75 private static Logger logger = Logger.getLogger(WINFOArtifact.class); 75 private static Logger logger = Logger.getLogger(WINFOArtifact.class);
76 76
77
78 /** The name of the artifact. */ 77 /** The name of the artifact. */
79 public static final String ARTIFACT_NAME = "winfo"; 78 public static final String ARTIFACT_NAME = "winfo";
80
81 79
82 /** XPath */ 80 /** XPath */
83 public static final String XPATH_STATIC_UI ="/art:result/art:ui/art:static"; 81 public static final String XPATH_STATIC_UI ="/art:result/art:ui/art:static";
84 82
85 /** The default number of steps between the start end end of a selected Q 83 /** The default number of steps between the start end end of a selected Q
649 * @param line line of interest. 647 * @param line line of interest.
650 * 648 *
651 * @return list of points of CrossSectionLine, sorted. 649 * @return list of points of CrossSectionLine, sorted.
652 */ 650 */
653 protected List<Point2D> getCrossSectionLinesPoints(CrossSectionLine line) { 651 protected List<Point2D> getCrossSectionLinesPoints(CrossSectionLine line) {
654 List<Point2D> points = new ArrayList<Point2D>(); 652 List<Point2D> points = new ArrayList<Point2D>();
653
654 if (line == null) {
655 return points;
656 }
657
655 List<CrossSectionPoint> linePoints = line.getPoints(); 658 List<CrossSectionPoint> linePoints = line.getPoints();
656 if (linePoints.isEmpty()) { 659 if (linePoints.isEmpty()) {
657 logger.info("No points in selected CrossSectionLine."); 660 logger.info("No points in selected CrossSectionLine.");
658 return points; 661 return points;
659 } 662 }
684 ; 687 ;
685 } 688 }
686 689
687 // Get the cross section closest to requested km. 690 // Get the cross section closest to requested km.
688 // Naive, linear approach. 691 // Naive, linear approach.
692 List<CrossSection> sections = getCrossSections();
693 if (sections.size() == 0 || sections.get(0).getLines().size() == 0) {
694 return null;
695 }
689 List<CrossSectionLine> crossSectionLines = 696 List<CrossSectionLine> crossSectionLines =
690 getCrossSections().get(0).getLines(); 697 sections.get(0).getLines();
691 CrossSectionLine oldLine = crossSectionLines.get(0); 698 CrossSectionLine oldLine = crossSectionLines.get(0);
692 double oldDiff = Math.abs(wishKM - oldLine.getKm().doubleValue()); 699 double oldDiff = Math.abs(wishKM - oldLine.getKm().doubleValue());
693 for (CrossSectionLine line: crossSectionLines) { 700 for (CrossSectionLine line: crossSectionLines) {
694 double diff = Math.abs(wishKM - line.getKm().doubleValue()); 701 double diff = Math.abs(wishKM - line.getKm().doubleValue());
695 if (diff > oldDiff) { 702 if (diff > oldDiff) {
708 * 715 *
709 * @return km for which cross section is calculated. 716 * @return km for which cross section is calculated.
710 */ 717 */
711 public double getCrossSectionSnapKm() { 718 public double getCrossSectionSnapKm() {
712 // Note that this is this triggers a linear search. 719 // Note that this is this triggers a linear search.
713 return searchCrossSectionKmLine().getKm().doubleValue(); 720 CrossSectionLine line = searchCrossSectionKmLine();
721 if (line == null) {
722 logger.warn("No Cross Section for given km found.");
723 return 0.0f;
724 }
725 else {
726 return line.getKm().doubleValue();
727 }
714 } 728 }
715 729
716 730
717 /** 731 /**
718 * Get points of Profile of cross section. 732 * Get points of Profile of cross section.
759 } 773 }
760 catch (Exception e) { 774 catch (Exception e) {
761 ; 775 ;
762 } 776 }
763 777
778 if (triple.size() == 0) {
779 logger.warn("Calculation of waterline is empty.");
780 return CrossSectionApp.createWaterLines(points, 0.0f);
781 }
782
764 // Linear seach in WQKms for closest km. 783 // Linear seach in WQKms for closest km.
765 double old_dist_wish = Math.abs(wishKM - triple.getKm(0)); 784 double old_dist_wish = Math.abs(wishKM - triple.getKm(0));
785 double last_w = triple.getW(0);
766 786
767 for (int i = 0; i < triple.size(); i++) { 787 for (int i = 0; i < triple.size(); i++) {
768 double diff = Math.abs(wishKM - triple.getKm(i)); 788 double diff = Math.abs(wishKM - triple.getKm(i));
769 if (diff > old_dist_wish) { 789 if (diff > old_dist_wish) {
770 return CrossSectionApp.createWaterLines(points, 790 break;
771 triple.getW(i));
772 } 791 }
792 last_w = triple.getW(i);
773 old_dist_wish = diff; 793 old_dist_wish = diff;
774 } 794 }
775 return CrossSectionApp.createWaterLines(points, 795 return CrossSectionApp.createWaterLines(points, last_w);
776 triple.getW(triple.size()-1));
777 } 796 }
778 } 797 }
779 798
780 799
781 /** 800 /**
793 } 812 }
794 813
795 814
796 /** 815 /**
797 * Get points of CrossSection Line. 816 * Get points of CrossSection Line.
817 * @param csl The crossSectionline of interest.
818 * @return x and y positions of cross section profile.
798 */ 819 */
799 protected double [][] getCrossSectionProfile(CrossSectionLine csl) { 820 protected double [][] getCrossSectionProfile(CrossSectionLine csl) {
800 List<Point2D> points = getCrossSectionLinesPoints(csl); 821 List<Point2D> points = getCrossSectionLinesPoints(csl);
801 double [] xs = new double[points.size()]; 822 double [] xs = new double[points.size()];
802 double [] ys = new double[points.size()]; 823 double [] ys = new double[points.size()];

http://dive4elements.wald.intevation.org