comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/SedimentLoadFacet.java @ 5645:696d710470f5

flys/issue1077: Show loads as step line, therefore transform data in SedimentLoadFacet to stretch as in the measurement stations bounds. Deal with this new kind of data in the Generator.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 10 Apr 2013 09:35:07 +0200
parents 19772b414d46
children ddb2a4e982b8
comparison
equal deleted inserted replaced
5644:bae2b1568f3d 5645:696d710470f5
1 package de.intevation.flys.artifacts.model.minfo; 1 package de.intevation.flys.artifacts.model.minfo;
2 2
3 import org.apache.log4j.Logger; 3 import org.apache.log4j.Logger;
4
5 import java.util.ArrayList;
6 import java.util.List;
4 7
5 import de.intevation.artifactdatabase.state.Facet; 8 import de.intevation.artifactdatabase.state.Facet;
6 import de.intevation.artifacts.Artifact; 9 import de.intevation.artifacts.Artifact;
7 import de.intevation.artifacts.CallContext; 10 import de.intevation.artifacts.CallContext;
8 import de.intevation.flys.artifacts.FLYSArtifact; 11 import de.intevation.flys.artifacts.FLYSArtifact;
9 import de.intevation.flys.artifacts.model.CalculationResult; 12 import de.intevation.flys.artifacts.model.CalculationResult;
10 import de.intevation.flys.artifacts.model.DataFacet; 13 import de.intevation.flys.artifacts.model.DataFacet;
14 import de.intevation.flys.model.MeasurementStation;
15 import de.intevation.flys.artifacts.model.FacetTypes;
11 import de.intevation.flys.artifacts.states.DefaultState.ComputeType; 16 import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
17
18 import de.intevation.flys.utils.FLYSUtils;
12 19
13 20
14 public class SedimentLoadFacet 21 public class SedimentLoadFacet
15 extends DataFacet 22 extends DataFacet
16 { 23 {
24 /** Very own logger. */
17 private static Logger logger = Logger.getLogger(SedimentLoadFacet.class); 25 private static Logger logger = Logger.getLogger(SedimentLoadFacet.class);
26
27 private static double EPSILON = 1e-5;
18 28
19 public SedimentLoadFacet() { 29 public SedimentLoadFacet() {
20 } 30 }
21 31
22 public SedimentLoadFacet(int idx, String name, String description, 32 public SedimentLoadFacet(int idx, String name, String description,
33 stateId, type, false); 43 stateId, type, false);
34 44
35 Object[] data = 45 Object[] data =
36 (SedimentLoadResult[]) res.getData(); // TODO CAST TO SPECIFIC CLASS 46 (SedimentLoadResult[]) res.getData(); // TODO CAST TO SPECIFIC CLASS
37 47
38 return data != null && data.length > index ? data[index] : null; 48 List<MeasurementStation> allStations = FLYSUtils.getRiver(flys).getMeasurementStations();
49 SedimentLoadResult result = data != null && data.length > index ? (SedimentLoadResult)data[index] : null;
50 if (result == null) {
51 return null;
52 }
53
54 // Filter stations according to type.
55 List<MeasurementStation> stations = new ArrayList<MeasurementStation>();
56 for (MeasurementStation station: allStations) {
57 if (station.getRange() == null || station.getMeasurementType() == null) {
58 continue;
59 }
60 if (FacetTypes.IS.SEDIMENT_LOAD_NO_FLOAT(this.getName()) && station.getMeasurementType().equals("Geschiebe"))
61 stations.add(station);
62 else if (!FacetTypes.IS.SEDIMENT_LOAD_NO_FLOAT(this.getName()) && station.getMeasurementType().equals("Schwebstoff"))
63 stations.add(station);
64 }
65
66 // Access data according to type.
67 double[][] sd = null;
68 if (getName().equals(FacetTypes.SEDIMENT_LOAD_SAND))
69 sd = result.getSandData();
70 else if (getName().equals(FacetTypes.SEDIMENT_LOAD_COARSE))
71 sd = result.getCoarseData();
72 else if (getName().equals(FacetTypes.SEDIMENT_LOAD_FINEMIDDLE))
73 sd = result.getFineMiddleData();
74 else if (getName().equals(FacetTypes.SEDIMENT_LOAD_SUSP_SAND))
75 sd = result.getSuspSandData();
76 else if (getName().equals(FacetTypes.SEDIMENT_LOAD_SUSP_SAND_BED))
77 sd = result.getSuspSandBedData();
78 else if (getName().equals(FacetTypes.SEDIMENT_LOAD_SUSP_SEDIMENT))
79 sd = result.getSuspSedimentData();
80 else if (getName().equals(FacetTypes.SEDIMENT_LOAD_TOTAL_LOAD))
81 sd = result.getTotalLoadData();
82 else if (getName().equals(FacetTypes.SEDIMENT_LOAD_TOTAL))
83 sd = result.getTotalData();
84
85 double[] km = sd[0];
86 double[] load = sd[1];
87
88 double[][] values = new double[2][];
89 values[0] = new double[km.length*2];
90 values[1] = new double[km.length*2];
91
92 // Find station via its station (km).
93 // TODO what to do with gaps in measurement stations.
94 for (int i = 0; i < km.length; i++) {
95 boolean matchFound = false;
96 for (MeasurementStation station: stations) {
97 if (Math.abs(station.getStation() - km[i]) < EPSILON) {
98 values[0][i*2] = station.getRange().getA().doubleValue();
99 values[1][i*2] = load[i];
100 values[0][i*2+1] = station.getRange().getB().doubleValue();
101 values[1][i*2+1] = load[i];
102 matchFound = true;
103 }
104 }
105 if (!matchFound) {
106 values[0][i*2] = km[i];
107 values[1][i*2] = load[i];
108 logger.debug("No measurement station for km " + km[i]);
109 }
110 }
111 return values;
39 } 112 }
113
40 114
41 /** Copy deeply. */ 115 /** Copy deeply. */
42 @Override 116 @Override
43 public Facet deepCopy() { 117 public Facet deepCopy() {
44 SedimentLoadFacet copy = new SedimentLoadFacet(); 118 SedimentLoadFacet copy = new SedimentLoadFacet();

http://dive4elements.wald.intevation.org