comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedHeightsFinder.java @ 9573:b9c87bbff6a4

mean bed height -> mean bed LEVEL
author gernotbelger
date Tue, 06 Nov 2018 10:56:22 +0100
parents 7228bd10a8cc
children 5395c6d4ca50
comparison
equal deleted inserted replaced
9572:0d0c8fd1b8c8 9573:b9c87bbff6a4
26 import org.dive4elements.river.model.BedHeightValue; 26 import org.dive4elements.river.model.BedHeightValue;
27 import org.dive4elements.river.model.BedHeightValueType; 27 import org.dive4elements.river.model.BedHeightValueType;
28 import org.dive4elements.river.utils.RiverUtils; 28 import org.dive4elements.river.utils.RiverUtils;
29 29
30 /** 30 /**
31 * Provides bed heights for various calculations. 31 * Provides bed levels for various calculations.
32 * 32 *
33 * @author Gernot Belger 33 * @author Gernot Belger
34 */ 34 */
35 public final class BedHeightsFinder { 35 public final class BedHeightsFinder {
36 36
43 private Calculation problems; 43 private Calculation problems;
44 44
45 private final boolean isNull; 45 private final boolean isNull;
46 46
47 /** 47 /**
48 * Create bed height finders from a collection of bed heights. 48 * Create bed level finders from a collection of bed levels.
49 */ 49 */
50 public static Collection<BedHeightsFinder> createTkhBedHeights(final Calculation problems, final DoubleRange range, 50 public static Collection<BedHeightsFinder> createTkhBedHeights(final Calculation problems, final DoubleRange range,
51 final Collection<BedHeight> bedHeights) { 51 final Collection<BedHeight> bedHeights) {
52 final List<BedHeightsFinder> result = new ArrayList<>(bedHeights.size()); 52 final List<BedHeightsFinder> result = new ArrayList<>(bedHeights.size());
53 53
100 } 100 }
101 101
102 /** 102 /**
103 * Creates a {@link BedHeightsFinder} for a dataset from the database, specified by its id. 103 * Creates a {@link BedHeightsFinder} for a dataset from the database, specified by its id.
104 * 104 *
105 * @return <code>null</code> if no bed height with the given id exists. 105 * @return <code>null</code> if no bed level with the given id exists.
106 */ 106 */
107 public static BedHeightsFinder forId(final Calculation problems, final int id, final DoubleRange range) { 107 public static BedHeightsFinder forId(final Calculation problems, final int id, final DoubleRange range) {
108 108
109 final BedHeight bedHeight = BedHeight.getBedHeightById(id); 109 final BedHeight bedHeight = BedHeight.getBedHeightById(id);
110 if (bedHeight == null) 110 if (bedHeight == null)
120 final NavigableMap<Double, BedHeightValue> values = new TreeMap<>(); 120 final NavigableMap<Double, BedHeightValue> values = new TreeMap<>();
121 return new BedHeightsFinder(null, null, values, true); 121 return new BedHeightsFinder(null, null, values, true);
122 } 122 }
123 123
124 /** 124 /**
125 * Create a finder for a given bed height. 125 * Create a finder for a given bed level.
126 * 126 *
127 */ 127 */
128 private static BedHeightsFinder createBedHeights(final Calculation problems, final BedHeight bedHeight, final DoubleRange range) { 128 private static BedHeightsFinder createBedHeights(final Calculation problems, final BedHeight bedHeight, final DoubleRange range) {
129 129
130 // FIXME: sort by station, but in what direction? 130 // FIXME: sort by station, but in what direction?
152 this.isNull = isNull; 152 this.isNull = isNull;
153 } 153 }
154 154
155 /** 155 /**
156 * Whether this is a null (always NaN) finder. 156 * Whether this is a null (always NaN) finder.
157 * 157 *
158 * @return 158 * @return
159 */ 159 */
160 public boolean isNull() { 160 public boolean isNull() {
161 return this.isNull; 161 return this.isNull;
162 } 162 }
194 public double getFieldHeight(final double km, final int index) { 194 public double getFieldHeight(final double km, final int index) {
195 return interpolateBedHeights(km, BedHeightValueType.field(index)); 195 return interpolateBedHeights(km, BedHeightValueType.field(index));
196 } 196 }
197 197
198 private double interpolateBedHeights(final double km, final BedHeightValueType type) { 198 private double interpolateBedHeights(final double km, final BedHeightValueType type) {
199 if (this.values.containsKey(km)) 199 if (this.values.containsKey(km)) {
200 {
201 final Double value = type.getValue(this.values.get(km)); 200 final Double value = type.getValue(this.values.get(km));
202 return value == null ? Double.NaN : value.doubleValue(); 201 return value == null ? Double.NaN : value.doubleValue();
203 } 202 }
204 203
205 final Entry<Double, BedHeightValue> floorEntry = this.values.floorEntry(km); 204 final Entry<Double, BedHeightValue> floorEntry = this.values.floorEntry(km);

http://dive4elements.wald.intevation.org