annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/river/MainWstValuesCalculator.java @ 9499:853f2dafc16e

VegetationZones in CrossSectionsDiagram
author gernotbelger
date Thu, 27 Sep 2018 18:06:26 +0200
parents
children 8b7bf26b8782
rev   line source
9499
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
2 * Software engineering by
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
3 * Björnsen Beratende Ingenieure GmbH
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
5 *
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
6 * This file is Free Software under the GNU AGPL (>=v3)
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
8 * documentation coming with Dive4Elements River for details.
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
9 */
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
10 package org.dive4elements.river.artifacts.model.river;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
11
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
12 import java.util.HashMap;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
13 import java.util.Map;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
14
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
15 import org.apache.commons.lang.math.DoubleRange;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
16 import org.dive4elements.artifacts.CallContext;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
17 import org.dive4elements.river.artifacts.model.WstValueTable;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
18 import org.dive4elements.river.artifacts.model.WstValueTable.QPosition;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
19 import org.dive4elements.river.artifacts.model.WstValueTableFactory;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
20 import org.dive4elements.river.model.Gauge;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
21 import org.dive4elements.river.model.MainValue;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
22 import org.dive4elements.river.model.MainValueType.MainValueTypeKey;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
23 import org.dive4elements.river.model.River;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
24
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
25 /**
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
26 * @author Domenico Nardi Tironi
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
27 */
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
28 public final class MainWstValuesCalculator {
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
29
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
30 private final WstValueTable wst;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
31
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
32 private final Map<String, MainValueQPosition> positions;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
33
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
34 private static class MainValueQPosition {
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
35
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
36 private final Map<Gauge, QPosition> gaugePositions = new HashMap<>();
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
37 private QPosition refGaugePositions = null;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
38 }
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
39
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
40 public static MainWstValuesCalculator forRiver(final CallContext context, final River river, final DoubleRange calcRange, final String... mainValueNames) {
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
41
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
42 final RiverInfoProvider info = RiverInfoProvider.forRange(context, river, calcRange);
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
43
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
44 return forRiverInfo(info, mainValueNames);
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
45 }
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
46
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
47 public static MainWstValuesCalculator forRiverInfo(final RiverInfoProvider info, final String... mainValueNames) {
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
48
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
49 final WstValueTable wst = WstValueTableFactory.getTable(info.getRiver());
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
50
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
51 final Map<String, MainValueQPosition> positions = calculatePositions(info, wst, mainValueNames);
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
52
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
53 return new MainWstValuesCalculator(wst, positions);
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
54 }
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
55
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
56 private static Map<String, MainValueQPosition> calculatePositions(final RiverInfoProvider info, final WstValueTable wst, final String[] mainValueNames) {
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
57
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
58 boolean isFirstGauge = true;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
59
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
60 final Map<String, MainValueQPosition> positions = new HashMap<>();
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
61
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
62 for (final String mainValue : mainValueNames)
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
63 positions.put(mainValue.toUpperCase(), new MainValueQPosition());
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
64
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
65 for (final Gauge gauge : info.getGauges()) {
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
66
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
67 for (final MainValueQPosition position : positions.values())
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
68 position.gaugePositions.put(gauge, null);
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
69
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
70 final double gaugeKm = gauge.getStation().doubleValue();
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
71 for (final MainValue mv : MainValue.getValuesOfGaugeAndType(gauge, MainValueTypeKey.Q)) {
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
72
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
73 final MainValueQPosition position = positions.get(mv.getMainValue().getName().toUpperCase());
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
74 if (position != null) {
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
75 final QPosition qPosition = wst.getQPosition(gaugeKm, mv.getValue().doubleValue());
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
76 position.gaugePositions.put(gauge, qPosition);
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
77
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
78 if (isFirstGauge)
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
79 position.refGaugePositions = qPosition;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
80 }
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
81 }
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
82
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
83 isFirstGauge = false;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
84 }
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
85
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
86 return positions;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
87 }
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
88
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
89 private MainWstValuesCalculator(final WstValueTable wst, final Map<String, MainValueQPosition> positions) {
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
90 this.wst = wst;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
91 this.positions = positions;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
92 }
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
93
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
94 public boolean hasPosition(final String mainValueName) {
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
95
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
96 final MainValueQPosition position = this.positions.get(mainValueName);
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
97 if (position == null)
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
98 throw new IllegalArgumentException();
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
99
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
100 return position.refGaugePositions != null;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
101 }
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
102
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
103 /**
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
104 * Interpolates the W for a station with a fixed (virtual) wst column position
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
105 */
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
106 public double interpolateW(final double station, final String mainValueName) {
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
107
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
108 final MainValueQPosition mainValuePosition = this.positions.get(mainValueName.toUpperCase());
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
109
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
110 if (mainValuePosition.refGaugePositions == null)
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
111 return Double.NaN;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
112
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
113 return this.wst.interpolateW(station, mainValuePosition.refGaugePositions);
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
114 }
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
115 }

http://dive4elements.wald.intevation.org