comparison 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
comparison
equal deleted inserted replaced
3271:4c4ec9e9650a 3272:31168ac9c7e7
51 /** Name of data item flagging whether we think that we are master. */ 51 /** Name of data item flagging whether we think that we are master. */
52 public static final String DATA_IS_MASTER = "cross_section.master?"; 52 public static final String DATA_IS_MASTER = "cross_section.master?";
53 53
54 /** Name of data item flagging whether we are the newest. */ 54 /** Name of data item flagging whether we are the newest. */
55 public static final String DATA_IS_NEWEST = "cross_section.newest?"; 55 public static final String DATA_IS_NEWEST = "cross_section.newest?";
56
57 /** Name of data item storing the previous possible km. */
58 public static final String DATA_PREV_KM = "cross_section.km.previous";
59
60 /** Name of data item storing the next possible km. */
61 public static final String DATA_NEXT_KM = "cross_section.km.next";
56 62
57 /** Own logger. */ 63 /** Own logger. */
58 private static final Logger logger = 64 private static final Logger logger =
59 Logger.getLogger(CrossSectionArtifact.class); 65 Logger.getLogger(CrossSectionArtifact.class);
60 66
96 List<CrossSectionLine> csls = cs.getLines(); 102 List<CrossSectionLine> csls = cs.getLines();
97 if (!csls.isEmpty()) { 103 if (!csls.isEmpty()) {
98 CrossSectionLine csl = csls.get(0); 104 CrossSectionLine csl = csls.get(0);
99 // Find min-km of cross sections, 105 // Find min-km of cross sections,
100 // then set DATA_KM to min(DATA_KM, minCross). 106 // then set DATA_KM to min(DATA_KM, minCross).
101 double masterKm = Double.valueOf(getDataAsString(DATA_KM)); 107 double dataKm = Double.valueOf(getDataAsString(DATA_KM));
102 if (masterKm < csl.getKm().doubleValue()) { 108 if (dataKm < csl.getKm().doubleValue()) {
103 addStringData(DATA_KM, csl.getKm().toString()); 109 addStringData(DATA_KM, csl.getKm().toString());
104 } 110 }
105 } 111 }
106 fs.add(new CrossSectionFacet(0, cs.getDescription())); 112 fs.add(new CrossSectionFacet(0, cs.getDescription()));
107 113
108 // Find out if we are newest. 114 // Find out if we are newest and become master if so.
109 boolean isNewest = CrossSectionFactory.isNewest(cs); 115 boolean isNewest = CrossSectionFactory.isNewest(cs);
110 String newString = (isNewest) ? "1" : "0"; 116 String newString = (isNewest) ? "1" : "0";
111 addStringData(DATA_IS_NEWEST, newString); 117 addStringData(DATA_IS_NEWEST, newString);
112 addStringData(DATA_IS_MASTER, newString); 118 addStringData(DATA_IS_MASTER, newString);
113 119
134 } 140 }
135 this.addStringData(DATA_KM, Double.toString(min)); 141 this.addStringData(DATA_KM, Double.toString(min));
136 } 142 }
137 143
138 144
145 public Double getNextKm() {
146 return getDataAsDouble(DATA_NEXT_KM);
147 }
148
149 public Double getPrevKm() {
150 return getDataAsDouble(DATA_PREV_KM);
151 }
152
153
139 /** 154 /**
140 * Create and return a new StaticState with charting output. 155 * Create and return a new StaticState with charting output.
141 */ 156 */
142 @Override 157 @Override
143 public State getCurrentState(Object cc) { 158 public State getCurrentState(Object cc) {
236 251
237 /** 252 /**
238 * Get CrossSectionLine spatially closest to what is specified in the data 253 * Get CrossSectionLine spatially closest to what is specified in the data
239 * "cross_section.km", null if considered too far. 254 * "cross_section.km", null if considered too far.
240 * 255 *
256 * It also adds DataItems to store the next and previous (numerically)
257 * values at which cross-section data was recorded.
258 *
241 * @return CrossSectionLine closest to "cross_section.km", might be null 259 * @return CrossSectionLine closest to "cross_section.km", might be null
242 * if considered too far. 260 * if considered too far.
243 */ 261 */
244 public FastCrossSectionLine searchCrossSectionLine() { 262 public FastCrossSectionLine searchCrossSectionLine() {
245 double TOO_FAR = 1d; 263 double TOO_FAR = 1d;
256 Double wishKM = getKm(); 274 Double wishKM = getKm();
257 275
258 Double floor = kms.floorKey(wishKM); 276 Double floor = kms.floorKey(wishKM);
259 Double ceil = kms.ceilingKey(wishKM); 277 Double ceil = kms.ceilingKey(wishKM);
260 278
279 Double nextKm;
280 Double prevKm;
281
261 double floorD = floor != null 282 double floorD = floor != null
262 ? Math.abs(floor - wishKM) 283 ? Math.abs(floor - wishKM)
263 : Double.MAX_VALUE; 284 : Double.MAX_VALUE;
264 285
265 double ceilD = ceil != null 286 double ceilD = ceil != null
266 ? Math.abs(ceil - wishKM) 287 ? Math.abs(ceil - wishKM)
267 : Double.MAX_VALUE; 288 : Double.MAX_VALUE;
268 289
269 double km = floorD < ceilD ? floor : ceil; 290 double km;
291 if (floorD < ceilD) {
292 km = floor;
293 }
294 else {
295 km = ceil;
296 }
270 297
271 // If we are too far from the wished km, return null. 298 // If we are too far from the wished km, return null.
272 if (Math.abs(km - wishKM) > TOO_FAR) { 299 if (Math.abs(km - wishKM) > TOO_FAR) {
273 return null; 300 return null;
274 } 301 }
302
303 // Store next and previous km.
304 nextKm = kms.higherKey(km);
305 prevKm = kms.lowerKey(km);
306
307 if (prevKm == null) {
308 prevKm = -1d;
309 }
310 if (nextKm == null) {
311 nextKm = -1d;
312 }
313
314 addStringData(DATA_PREV_KM, prevKm.toString());
315 addStringData(DATA_NEXT_KM, nextKm.toString());
275 316
276 return FastCrossSectionLineFactory 317 return FastCrossSectionLineFactory
277 .getCrossSectionLine(crossSection, km); 318 .getCrossSectionLine(crossSection, km);
278 } 319 }
279 320

http://dive4elements.wald.intevation.org