annotate artifacts/src/main/java/org/dive4elements/river/exports/process/FlowVelocityProcessor.java @ 7985:10debf4b82be facet-metadata

Split bed differences facet into data specific facets.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 01 Jul 2014 15:09:56 +0200
parents 45cced06490c
children b5cba2690347
rev   line source
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
1 /* Copyright (C) 2013 by Bundesanstalt für Gewässerkunde
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
2 * Software engineering by Intevation GmbH
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
3 *
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
6 * documentation coming with Dive4Elements River for details.
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
7 */
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
8
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
9 package org.dive4elements.river.exports.process;
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
10
7892
e844be34a606 Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
11 import java.util.Map;
e844be34a606 Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
12
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
13 import org.apache.log4j.Logger;
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
14 import org.jfree.data.xy.XYSeries;
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
15
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
16 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
17 import org.dive4elements.artifacts.CallContext;
7877
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
18 import org.dive4elements.river.artifacts.D4EArtifact;
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
19 import org.dive4elements.river.artifacts.access.RiverAccess;
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
20 import org.dive4elements.river.artifacts.context.RiverContext;
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
21 import org.dive4elements.river.artifacts.model.FacetTypes;
7877
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
22 import org.dive4elements.river.artifacts.model.ZoomScale;
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
23 import org.dive4elements.river.exports.DiagramGenerator;
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
24 import org.dive4elements.river.exports.StyledSeriesBuilder;
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
25 import org.dive4elements.river.jfree.StyledXYSeries;
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
26 import org.dive4elements.river.themes.ThemeDocument;
7164
440c55b9634e Cosmetics
Andre Heinecke <aheinecke@intevation.de>
parents: 7162
diff changeset
27
7162
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
28 import org.dive4elements.river.model.FlowVelocityMeasurementValue.FastFlowVelocityMeasurementValue;
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
29 import org.dive4elements.river.artifacts.model.FlowVelocityData;
7877
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
30 import org.dive4elements.river.artifacts.resources.Resources;
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
31
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
32 public class FlowVelocityProcessor extends DefaultProcessor {
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
33
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
34 private final static Logger logger =
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
35 Logger.getLogger(FlowVelocityProcessor.class);
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
36
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
37 public static final String I18N_AXIS_LABEL =
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
38 "chart.flow_velocity.section.yaxis.label";
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
39 public static final String I18N_AXIS_LABEL_DEFAULT =
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
40 "Geschwindigkeit v [m/s]";
7877
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
41 public static final String I18N_SUBTITLE_RADIUS =
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
42 "chart.subtitle.radius";
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
43
7892
e844be34a606 Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
44
e844be34a606 Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
45 protected String yAxisLabel;
e844be34a606 Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
46
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
47 @Override
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
48 public void doOut(
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
49 DiagramGenerator generator,
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
50 ArtifactAndFacet bundle,
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
51 ThemeDocument theme,
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
52 boolean visible) {
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
53 CallContext context = generator.getCallContext();
7892
e844be34a606 Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
54 Map<String, String> metaData = bundle.getFacet().getMetaData();
e844be34a606 Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
55 StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(),
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
56 theme);
7892
e844be34a606 Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
57 series.putMetaData(metaData, bundle.getArtifact(), context);
e844be34a606 Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
58 yAxisLabel = metaData.get("Y");
7162
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
59 String facetName = bundle.getFacetName();
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
60 Object data = bundle.getData(context);
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
61 if (data == null) {
7162
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
62 // Check has been here before so we keep it for security reasons
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
63 // this should never happen though.
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
64 logger.error("Data is null for facet: " + facetName);
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
65 return;
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
66 }
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
67 double [][] points;
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
68
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
69 if (facetName.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL) ||
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
70 facetName.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL_FILTERED)) {
7162
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
71 FlowVelocityData fData = (FlowVelocityData) data;
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
72 points = fData.getTotalChannelPoints();
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
73 } else if (facetName.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL) ||
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
74 facetName.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL_FILTERED)) {
7162
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
75 FlowVelocityData fData = (FlowVelocityData) data;
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
76 points = fData.getMainChannelPoints(); // I hate facets!
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
77 } else if (facetName.equals(FacetTypes.FLOW_VELOCITY_MEASUREMENT)) {
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
78 FastFlowVelocityMeasurementValue fData =
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
79 (FastFlowVelocityMeasurementValue) data;
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
80 points = new double[][] {{fData.getStation()},{fData.getV()}};
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
81 } else {
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
82 logger.error("Unknown facet name: " + facetName);
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
83 return;
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
84 }
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
85 StyledSeriesBuilder.addPoints(series, points, true);
7877
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
86 Double start = (Double)context.getContextValue("startkm");
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
87 Double end = (Double)context.getContextValue("endkm");
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
88 if (start != null && end != null) {
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
89 logger.debug("start: " + start + " end: " + end);
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
90 D4EArtifact artifact = (D4EArtifact)bundle.getArtifact();
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
91 RiverContext fc = (RiverContext)context.globalContext();
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
92 // Adaptive smoothing, based on zoom factor/diagram extents.
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
93 ZoomScale scales = (ZoomScale)fc.get("zoomscale");
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
94 RiverAccess access = new RiverAccess((D4EArtifact)artifact);
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
95 String river = access.getRiverName();
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
96
7877
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
97 double radius = scales.getRadius(river, start, end);
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
98 logger.debug("add a subtitle");
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
99 generator.addSubtitle(Resources.getMsg(
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
100 context.getMeta(),
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
101 I18N_SUBTITLE_RADIUS,
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
102 new Object[] { radius }));
43f18dc56c5a Fixed subtitle handling and added flowvelocity subtitle.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
103 }
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
104 generator.addAxisSeries(series, axisName, visible);
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
105 }
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
106
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
107 @Override
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
108 public boolean canHandle(String facettype) {
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
109 return facettype.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL_FILTERED) ||
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
110 facettype.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL) ||
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
111 facettype.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL_FILTERED) ||
7162
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
112 facettype.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL) ||
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
113 facettype.equals(FacetTypes.FLOW_VELOCITY_MEASUREMENT);
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
114 }
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
115
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
116 @Override
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
117 public String getAxisLabel(DiagramGenerator generator) {
7892
e844be34a606 Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
118 if (yAxisLabel != null && !yAxisLabel.isEmpty()) {
e844be34a606 Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
119 return generator.msg(yAxisLabel, I18N_AXIS_LABEL_DEFAULT);
e844be34a606 Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
120 }
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
121 return generator.msg(
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
122 I18N_AXIS_LABEL,
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
123 I18N_AXIS_LABEL_DEFAULT);
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
124 }
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
125 }

http://dive4elements.wald.intevation.org