Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/CrossSectionArtifact.java @ 3272:31168ac9c7e7
Partial fix for issue694 (heightmarks snap to nearest cross section).
flys-artifacts/trunk@4916 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 10 Jul 2012 15:31:56 +0000 |
parents | 2f7fed1eb4bf |
children | d9af29a4bb85 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/CrossSectionArtifact.java Tue Jul 10 13:26:13 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/CrossSectionArtifact.java Tue Jul 10 15:31:56 2012 +0000 @@ -54,6 +54,12 @@ /** Name of data item flagging whether we are the newest. */ public static final String DATA_IS_NEWEST = "cross_section.newest?"; + /** Name of data item storing the previous possible km. */ + public static final String DATA_PREV_KM = "cross_section.km.previous"; + + /** Name of data item storing the next possible km. */ + public static final String DATA_NEXT_KM = "cross_section.km.next"; + /** Own logger. */ private static final Logger logger = Logger.getLogger(CrossSectionArtifact.class); @@ -98,14 +104,14 @@ CrossSectionLine csl = csls.get(0); // Find min-km of cross sections, // then set DATA_KM to min(DATA_KM, minCross). - double masterKm = Double.valueOf(getDataAsString(DATA_KM)); - if (masterKm < csl.getKm().doubleValue()) { + double dataKm = Double.valueOf(getDataAsString(DATA_KM)); + if (dataKm < csl.getKm().doubleValue()) { addStringData(DATA_KM, csl.getKm().toString()); } } fs.add(new CrossSectionFacet(0, cs.getDescription())); - // Find out if we are newest. + // Find out if we are newest and become master if so. boolean isNewest = CrossSectionFactory.isNewest(cs); String newString = (isNewest) ? "1" : "0"; addStringData(DATA_IS_NEWEST, newString); @@ -136,6 +142,15 @@ } + public Double getNextKm() { + return getDataAsDouble(DATA_NEXT_KM); + } + + public Double getPrevKm() { + return getDataAsDouble(DATA_PREV_KM); + } + + /** * Create and return a new StaticState with charting output. */ @@ -238,6 +253,9 @@ * Get CrossSectionLine spatially closest to what is specified in the data * "cross_section.km", null if considered too far. * + * It also adds DataItems to store the next and previous (numerically) + * values at which cross-section data was recorded. + * * @return CrossSectionLine closest to "cross_section.km", might be null * if considered too far. */ @@ -258,6 +276,9 @@ Double floor = kms.floorKey(wishKM); Double ceil = kms.ceilingKey(wishKM); + Double nextKm; + Double prevKm; + double floorD = floor != null ? Math.abs(floor - wishKM) : Double.MAX_VALUE; @@ -266,13 +287,33 @@ ? Math.abs(ceil - wishKM) : Double.MAX_VALUE; - double km = floorD < ceilD ? floor : ceil; + double km; + if (floorD < ceilD) { + km = floor; + } + else { + km = ceil; + } // If we are too far from the wished km, return null. if (Math.abs(km - wishKM) > TOO_FAR) { return null; } + // Store next and previous km. + nextKm = kms.higherKey(km); + prevKm = kms.lowerKey(km); + + if (prevKm == null) { + prevKm = -1d; + } + if (nextKm == null) { + nextKm = -1d; + } + + addStringData(DATA_PREV_KM, prevKm.toString()); + addStringData(DATA_NEXT_KM, nextKm.toString()); + return FastCrossSectionLineFactory .getCrossSectionLine(crossSection, km); }