Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FlowVelocityFilterFacet.java @ 4668:87c938d082d6
Added facet for filtered flow velocity and removed filter from default facet.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Thu, 13 Dec 2012 15:54:49 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4667:e6a282844a33 | 4668:87c938d082d6 |
---|---|
1 package de.intevation.flys.artifacts.model; | |
2 | |
3 import de.intevation.artifactdatabase.state.Facet; | |
4 | |
5 import de.intevation.artifacts.Artifact; | |
6 import de.intevation.artifacts.CallContext; | |
7 | |
8 import de.intevation.flys.artifacts.FLYSArtifact; | |
9 | |
10 import de.intevation.flys.artifacts.access.RiverAccess; | |
11 import de.intevation.flys.artifacts.context.FLYSContext; | |
12 | |
13 import de.intevation.flys.artifacts.math.MovingAverage; | |
14 import de.intevation.flys.artifacts.states.DefaultState.ComputeType; | |
15 | |
16 import org.apache.log4j.Logger; | |
17 | |
18 /** | |
19 * Facet of a FlowVelocity curve. | |
20 */ | |
21 public class FlowVelocityFilterFacet extends DataFacet { | |
22 | |
23 private static Logger logger = Logger.getLogger(FlowVelocityFilterFacet.class); | |
24 | |
25 public FlowVelocityFilterFacet() { | |
26 // required for clone operation deepCopy() | |
27 } | |
28 | |
29 | |
30 public FlowVelocityFilterFacet( | |
31 int idx, | |
32 String name, | |
33 String description, | |
34 ComputeType type, | |
35 String stateId, | |
36 String hash | |
37 ) { | |
38 super(idx, name, description, type, hash, stateId); | |
39 } | |
40 | |
41 | |
42 public Object getData(Artifact artifact, CallContext context) { | |
43 logger.debug("Get data for flow velocity at index: " + index); | |
44 | |
45 Double start = (Double)context.getContextValue("startkm"); | |
46 Double end = (Double)context.getContextValue("endkm"); | |
47 FLYSArtifact flys = (FLYSArtifact) artifact; | |
48 | |
49 CalculationResult res = (CalculationResult) | |
50 flys.compute(context, hash, stateId, type, false); | |
51 | |
52 FlowVelocityData[] data = (FlowVelocityData[]) res.getData(); | |
53 if(start != null && end != null) { | |
54 FLYSContext fc = (FLYSContext)context.globalContext(); | |
55 ZoomScale scales = (ZoomScale)fc.get("zoomscale"); | |
56 RiverAccess access = new RiverAccess((FLYSArtifact)artifact); | |
57 String river = access.getRiver(); | |
58 | |
59 double radius = scales.getRadius(river, start, end); | |
60 FlowVelocityData oldData = data[index]; | |
61 FlowVelocityData newData = new FlowVelocityData(); | |
62 double[][] q = oldData.getQPoints(); | |
63 double[][] totalV = MovingAverage.weighted(oldData.getTotalChannelPoints(), radius); | |
64 double[][] mainV = MovingAverage.weighted(oldData.getMainChannelPoints(), radius); | |
65 double[][] tau = MovingAverage.weighted(oldData.getTauPoints(), radius); | |
66 for(int j = 0; j < q[0].length; j++) { | |
67 newData.addKM(q[0][j]); | |
68 newData.addQ(q[1][j]); | |
69 newData.addTauMain(tau[1][j]); | |
70 newData.addVMain(mainV[1][j]); | |
71 newData.addVTotal(totalV[1][j]); | |
72 } | |
73 return newData; | |
74 } | |
75 return data[index]; | |
76 } | |
77 | |
78 | |
79 /** Copy deeply. */ | |
80 @Override | |
81 public Facet deepCopy() { | |
82 FlowVelocityFilterFacet copy = new FlowVelocityFilterFacet(); | |
83 copy.set(this); | |
84 copy.type = type; | |
85 copy.hash = hash; | |
86 copy.stateId = stateId; | |
87 return copy; | |
88 } | |
89 } | |
90 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |