comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 1975:b30e1710df1d

Server-side of interactive cross-section diagrams. flys-artifacts/trunk@3394 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 13 Dec 2011 09:10:48 +0000
parents cdeb31ef20a1
children bf62cc7052d4
comparison
equal deleted inserted replaced
1974:cdeb31ef20a1 1975:b30e1710df1d
670 return CrossSectionFactory.getCrossSections(river); 670 return CrossSectionFactory.getCrossSections(river);
671 } 671 }
672 672
673 673
674 /** 674 /**
675 * Get CrossSectionLine spatially closest to what is specified in the data
676 * "cross_section.km" (and from "cross_section.index").
677 *
678 * @return CrossSectionLine closest to "cross_section.km".
679 */
680 protected CrossSectionLine searchCrossSectionKmLine() {
681 double wishKM = 0.0f;
682 try {
683 wishKM = Double.parseDouble(getDataAsString("cross_section.km"));
684 }
685 catch (Exception e) {
686 logger.warn("Exception when parsing cross_section.km", e);
687 }
688
689 int crossSectionIdx = 0;
690
691 List<CrossSection> sections = getCrossSections();
692 if (sections.size() < crossSectionIdx) {
693 logger.error("Cross-section not found: " + crossSectionIdx);
694 return null;
695 }
696 if (sections.size() == 0
697 || sections.get(crossSectionIdx).getLines().size() == 0)
698 {
699 return null;
700 }
701
702 // Get the cross section closest to requested km.
703 // Naive, linear approach.
704 List<CrossSectionLine> crossSectionLines =
705 sections.get(crossSectionIdx).getLines();
706 CrossSectionLine oldLine = crossSectionLines.get(0);
707 double oldDiff = Math.abs(wishKM - oldLine.getKm().doubleValue());
708 for (CrossSectionLine line: crossSectionLines) {
709 double diff = Math.abs(wishKM - line.getKm().doubleValue());
710 if (diff > oldDiff) {
711 break;
712 }
713 oldDiff = diff;
714 oldLine = line;
715 }
716 return oldLine;
717 }
718
719
720 /**
721 * Get km for which a CrossSection is actually available (this may vary
722 * from the user picked "cross_section.km" data).
723 *
724 * @return km for which cross section is calculated.
725 */
726 public double getCrossSectionSnapKm() {
727 // Note that this is this triggers a linear search.
728 CrossSectionLine line = searchCrossSectionKmLine();
729 if (line == null) {
730 logger.warn("No Cross Section for given km found.");
731 return 0.0f;
732 }
733 else {
734 return line.getKm().doubleValue();
735 }
736 }
737
738
739 /**
740 * Get points of Profile of cross section.
741 *
742 * @return an array holding coordinates of points of profile (
743 * in the form {{x1, x2} {y1, y2}} ).
744 */
745 public double [][] getCrossSectionData() {
746 logger.info("getCrossSectionData() for cross_section.km "
747 + getDataAsString("cross_section.km"));
748 CrossSectionLine line = searchCrossSectionKmLine();
749
750 return line != null
751 ? line.fetchCrossSectionProfile()
752 : null;
753 }
754
755
756 /**
757 * Get points of line describing the surface of water at cross section. 675 * Get points of line describing the surface of water at cross section.
758 * 676 *
759 * @return an array holding coordinates of points of surface of water ( 677 * @return an array holding coordinates of points of surface of water (
760 * in the form {{x1, x2} {y1, y2}} ). 678 * in the form {{x1, x2} {y1, y2}} ).
761 */ 679 */
762 public double [][] getWaterLines(int idx) { 680 public double [][] getWaterLines(int idx, CrossSectionLine csl) {
763 logger.debug("getWaterLines()"); 681 logger.debug("getWaterLines(" + idx + ")");
764 CrossSectionLine csl = searchCrossSectionKmLine(); 682
765 List<Point2D> points = csl.fetchCrossSectionLinesPoints(); 683 List<Point2D> points = csl.fetchCrossSectionLinesPoints();
766 684
767 // Need W at km 685 // Need W at km
768 WQKms [] wqkms = (WQKms[]) getWaterlevelData().getData(); 686 WQKms [] wqkms = (WQKms[]) getWaterlevelData().getData();
769 if (wqkms.length == 0) { 687 if (wqkms.length == 0) {
778 696
779 // Find W at km, linear naive approach. 697 // Find W at km, linear naive approach.
780 WQKms triple = wqkms[idx]; 698 WQKms triple = wqkms[idx];
781 699
782 // Find index of km. 700 // Find index of km.
783 double wishKM = 0.0f; 701 double wishKM = csl.getKm().doubleValue();
784 int old_idx = 0; 702 int old_idx = 0;
785 try {
786 wishKM = Double.parseDouble(getDataAsString("cross_section.km"));
787 }
788 catch (Exception e) {
789 logger.warn("Exception when trying to get cross_section.km", e);
790 }
791 703
792 if (triple.size() == 0) { 704 if (triple.size() == 0) {
793 logger.warn("Calculation of waterline is empty."); 705 logger.warn("Calculation of waterline is empty.");
794 return Lines.createWaterLines(points, 0.0f); 706 return Lines.createWaterLines(points, 0.0f);
795 } 707 }
813 /** 725 /**
814 * Get name of cross sections. 726 * Get name of cross sections.
815 * @return list of names of cross-sections. 727 * @return list of names of cross-sections.
816 */ 728 */
817 public List<String> getCrossSectionNames() { 729 public List<String> getCrossSectionNames() {
730 logger.debug("getCrossSectionNames");
818 List<String> names = new ArrayList<String>(); 731 List<String> names = new ArrayList<String>();
819 732
820 for (CrossSection section: getCrossSections()) { 733 for (CrossSection section: getCrossSections()) {
821 names.add(section.getDescription()); 734 names.add(section.getDescription());
822 } 735 }

http://dive4elements.wald.intevation.org