Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Tue Nov 01 10:40:05 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Tue Nov 01 12:23:59 2011 +0000 @@ -670,7 +670,7 @@ /** * Get CrossSectionLine spatially closest to what is specified in the data - * "cross_section.km". + * "cross_section.km" (and from "cross_section.index"). * * @return CrossSectionLine closest to "cross_section.km". */ @@ -680,17 +680,26 @@ wishKM = Double.parseDouble(getDataAsString("cross_section.km")); } catch (Exception e) { - logger.warn(e); + logger.warn("Exception when parsing cross_section.km", e); + } + + int crossSectionIdx = 0; + + List<CrossSection> sections = getCrossSections(); + if (sections.size() < crossSectionIdx) { + logger.error("Cross-section not found: " + crossSectionIdx); + return null; + } + if (sections.size() == 0 + || sections.get(crossSectionIdx).getLines().size() == 0) + { + return null; } // Get the cross section closest to requested km. // Naive, linear approach. - List<CrossSection> sections = getCrossSections(); - if (sections.size() == 0 || sections.get(0).getLines().size() == 0) { - return null; - } List<CrossSectionLine> crossSectionLines = - sections.get(0).getLines(); + sections.get(crossSectionIdx).getLines(); CrossSectionLine oldLine = crossSectionLines.get(0); double oldDiff = Math.abs(wishKM - oldLine.getKm().doubleValue()); for (CrossSectionLine line: crossSectionLines) { @@ -734,7 +743,10 @@ logger.info("getCrossSectionData() for cross_section.km " + getDataAsString("cross_section.km")); CrossSectionLine line = searchCrossSectionKmLine(); - return line != null ? line.fetchCrossSectionProfile() : null; + + return line != null + ? line.fetchCrossSectionProfile() + : null; } @@ -771,7 +783,7 @@ wishKM = Double.parseDouble(getDataAsString("cross_section.km")); } catch (Exception e) { - logger.warn(e); + logger.warn("Exception when trying to get cross_section.km", e); } if (triple.size() == 0) { @@ -796,17 +808,17 @@ /** - * Get name of cross section. + * Get name of cross sections. + * @return list of names of cross-sections. */ - public String getCrossSectionName() { - List<CrossSection> sections = getCrossSections(); + public List<String> getCrossSectionNames() { + List<String> names = new ArrayList<String>(); - if (sections.size() > 0) { - return sections.get(0).getDescription(); + for (CrossSection section: getCrossSections()) { + names.add(section.getDescription()); } - else { - return ""; - } + + return names; }