Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedHeightMinMaxFacet.java @ 8964:45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
author | gernotbelger |
---|---|
date | Thu, 29 Mar 2018 15:48:17 +0200 |
parents | 8a1c6e2ad48b |
children |
rev | line source |
---|---|
8961 | 1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.artifacts.model.minfo; | |
10 | |
11 import java.util.List; | |
12 | |
13 import org.dive4elements.artifacts.Artifact; | |
14 import org.dive4elements.artifacts.CallContext; | |
15 import org.dive4elements.river.artifacts.D4EArtifact; | |
16 import org.dive4elements.river.artifacts.access.BedHeightAccess; | |
17 import org.dive4elements.river.artifacts.model.BlackboardDataFacet; | |
18 import org.dive4elements.river.artifacts.model.FacetTypes; | |
19 import org.dive4elements.river.artifacts.resources.Resources; | |
20 import org.dive4elements.river.model.BedHeight; | |
21 import org.dive4elements.river.model.BedHeightValue; | |
8964
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8961
diff
changeset
|
22 import org.dive4elements.river.model.BedHeightValueType; |
8961 | 23 |
24 import gnu.trove.TDoubleArrayList; | |
25 | |
26 /** | |
27 * More or less the same as {@link BedHeightFacet}, but was necessary to copy because else we break the old | |
28 * serialization. | |
29 * | |
30 * @author Gernot Belger | |
31 */ | |
32 public class BedHeightMinMaxFacet extends BlackboardDataFacet implements FacetTypes { | |
33 | |
34 private static final long serialVersionUID = 1L; | |
35 | |
36 private final BedHeightValueType valueType; | |
37 | |
38 public BedHeightMinMaxFacet(final String name, final String description, final BedHeightValueType valueType) { | |
39 super(0, name, description); | |
40 | |
41 this.valueType = valueType; | |
42 | |
43 this.metaData.put("X", "chart.longitudinal.section.xaxis.label"); | |
44 this.metaData.put("Y", "chart.bedheight_middle.section.yaxis.label"); | |
45 } | |
46 | |
47 /** | |
48 * Returns the data this facet requires. | |
49 * | |
50 * @param artifact | |
51 * the owner artifact. | |
52 * @param context | |
53 * the CallContext (ignored). | |
54 * | |
55 * @return the data. | |
56 */ | |
57 @Override | |
58 public Object getData(final Artifact artifact, final CallContext context) { | |
59 | |
60 final BedHeightAccess access = new BedHeightAccess((D4EArtifact) artifact); | |
61 | |
62 final BedHeight single = BedHeight.getBedHeightById(access.getHeightId()); | |
63 | |
64 final List<BedHeightValue> bedheightValues = BedHeightValue.getBedHeightValues(single, access.getFrom(true), access.getTo(true)); | |
65 | |
66 final TDoubleArrayList stations = new TDoubleArrayList(bedheightValues.size()); | |
67 final TDoubleArrayList values = new TDoubleArrayList(bedheightValues.size()); | |
68 | |
69 for (final BedHeightValue bedheightValue : bedheightValues) { | |
70 | |
71 final Double station = bedheightValue.getStation(); | |
72 final Double value = this.valueType.getValue(bedheightValue); | |
73 | |
74 if (station != null && value != null) { | |
75 stations.add(station); | |
76 values.add(value); | |
77 } | |
78 } | |
79 | |
80 this.addMetaData(Resources.getMsg(context.getMeta(), "meta.bedheight.cur.elevation"), single.getCurElevationModel().getName()); | |
81 | |
82 if (single.getOldElevationModel() != null) | |
83 this.addMetaData(Resources.getMsg(context.getMeta(), "meta.bedheight.old.elevation"), single.getOldElevationModel().getName()); | |
84 | |
85 this.addMetaData(Resources.getMsg(context.getMeta(), "meta.bedheight.river.elevation"), access.getRiver().getWstUnit().getName()); | |
86 | |
87 return new double[][] { stations.toNativeArray(), values.toNativeArray() }; | |
88 } | |
89 | |
90 /** | |
91 * Create a deep copy of this Facet. | |
92 * | |
93 * @return a deep copy. | |
94 */ | |
95 @Override | |
96 public BedHeightMinMaxFacet deepCopy() { | |
97 final BedHeightMinMaxFacet copy = new BedHeightMinMaxFacet(this.name, this.description, this.valueType); | |
98 copy.set(this); | |
99 return copy; | |
100 } | |
101 } |