Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFacet.java @ 6382:43ef4943e0c2
SedimentLoadFacet: Now that we have total load values with correct ranges in
place, use them accordingly instead of guessing ranges based on point data.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 21 Jun 2013 11:42:11 +0200 |
parents | 588e99129883 |
children | c74261e05a62 |
comparison
equal
deleted
inserted
replaced
6381:df1a3826c691 | 6382:43ef4943e0c2 |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.artifacts.model.minfo; | 9 package org.dive4elements.river.artifacts.model.minfo; |
10 | 10 |
11 import gnu.trove.TDoubleArrayList; | |
12 | |
11 import org.dive4elements.artifactdatabase.state.Facet; | 13 import org.dive4elements.artifactdatabase.state.Facet; |
12 | 14 |
13 import org.dive4elements.artifacts.Artifact; | 15 import org.dive4elements.artifacts.Artifact; |
14 import org.dive4elements.artifacts.CallContext; | 16 import org.dive4elements.artifacts.CallContext; |
15 | 17 |
68 SedimentLoadResult result = data != null && data.length > index ? (SedimentLoadResult)data[index] : null; | 70 SedimentLoadResult result = data != null && data.length > index ? (SedimentLoadResult)data[index] : null; |
69 if (result == null) { | 71 if (result == null) { |
70 return null; | 72 return null; |
71 } | 73 } |
72 | 74 |
75 // These complicated calculations were necessary because | |
76 // SedimentLoad/Fraction did not contain the ranges of the given | |
77 // values. Since this changed, the code is somewhat obsolete, but stable. | |
78 // For an example of easier calculation, see the "total" part below. | |
79 | |
73 List<Double> sortedStarts = new ArrayList<Double>(); | 80 List<Double> sortedStarts = new ArrayList<Double>(); |
74 // Filter stations according to type. | 81 // Filter stations according to type. |
75 List<MeasurementStation> stations = new ArrayList<MeasurementStation>(); | 82 List<MeasurementStation> stations = new ArrayList<MeasurementStation>(); |
76 for (MeasurementStation station: allStations) { | 83 for (MeasurementStation station: allStations) { |
77 if (station.getRange() == null || station.getMeasurementType() == null) { | 84 if (station.getRange() == null || station.getMeasurementType() == null) { |
88 sortedStarts.add(station.getStation()); | 95 sortedStarts.add(station.getStation()); |
89 } | 96 } |
90 } | 97 } |
91 Collections.sort(sortedStarts); | 98 Collections.sort(sortedStarts); |
92 | 99 |
93 // Access data according to type. | 100 // Handle sediment load differently, as it respects already |
101 // the ranges that were added to SedimentLoad/Fraction. | |
102 if (getName().equals(FacetTypes.SEDIMENT_LOAD_TOTAL)) { | |
103 SedimentLoad load = result.getLoad(); | |
104 TDoubleArrayList xPos = new TDoubleArrayList(); | |
105 TDoubleArrayList yPos = new TDoubleArrayList(); | |
106 double lastX = -1d; | |
107 for (double km: load.getKms()) { | |
108 SedimentLoadFraction fraction = load.getFraction(km); | |
109 if (fraction.getTotal() != 0) { | |
110 if (Math.abs(lastX-km) >= EPSILON) { | |
111 xPos.add(Double.NaN); | |
112 yPos.add(Double.NaN); | |
113 } | |
114 xPos.add(km); | |
115 yPos.add(fraction.getTotal()); | |
116 xPos.add(fraction.getTotalRange().getEnd()); | |
117 yPos.add(fraction.getTotal()); | |
118 lastX = fraction.getTotalRange().getEnd(); | |
119 } | |
120 } | |
121 return new double[][] {xPos.toNativeArray(), yPos.toNativeArray()}; | |
122 } | |
123 | |
124 // Access data according to type (except total - see above). | |
94 double[][] sd = getLoadData(result); | 125 double[][] sd = getLoadData(result); |
95 | 126 |
96 // Sort by km. | 127 // Sort by km. |
97 TreeMap<Double, Double> sortedKmLoad = new TreeMap<Double,Double>(); | 128 TreeMap<Double, Double> sortedKmLoad = new TreeMap<Double,Double>(); |
98 | 129 |