9499
|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
|
2 * Software engineering by |
|
3 * Björnsen Beratende Ingenieure GmbH |
|
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt |
|
5 * |
|
6 * This file is Free Software under the GNU AGPL (>=v3) |
|
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
|
8 * documentation coming with Dive4Elements River for details. |
|
9 */ |
|
10 package org.dive4elements.river.artifacts.uinfo.vegetationzones; |
|
11 |
|
12 import java.awt.Color; |
|
13 import java.util.HashSet; |
|
14 import java.util.List; |
|
15 import java.util.Set; |
|
16 |
|
17 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; |
|
18 import org.dive4elements.artifactdatabase.state.Facet; |
|
19 import org.dive4elements.artifacts.Artifact; |
|
20 import org.dive4elements.artifacts.CallContext; |
|
21 import org.dive4elements.artifacts.DataProvider; |
|
22 import org.dive4elements.river.artifacts.common.AbstractCalculationResult; |
|
23 import org.dive4elements.river.artifacts.common.AbstractProcessor; |
|
24 import org.dive4elements.river.artifacts.model.CrossSectionFacetUtils; |
|
25 import org.dive4elements.river.artifacts.model.river.MainWstValuesCalculator; |
|
26 import org.dive4elements.river.artifacts.uinfo.UINFOArtifact; |
|
27 import org.dive4elements.river.exports.CrossSectionGenerator; |
|
28 import org.dive4elements.river.exports.DiagramGenerator; |
|
29 import org.dive4elements.river.jfree.StripedAreaDataset; |
|
30 import org.dive4elements.river.jfree.StripedAreaDataset.Stripe; |
|
31 import org.dive4elements.river.model.FastCrossSectionLine; |
|
32 import org.dive4elements.river.model.River; |
|
33 import org.dive4elements.river.themes.ThemeDocument; |
|
34 |
|
35 /** |
|
36 * @author Domenico Nardi Tironi |
|
37 * |
|
38 */ |
|
39 public class VegetationZonesCrossSectionProcessor extends AbstractProcessor { |
|
40 |
|
41 private static final String MAIN_VALUE_MQ = "mq"; |
|
42 |
|
43 public static final String FACET_VEGETATION_ZONES_CROSS_SECTION = "uinfo_facet_vegetation_zones_cross_section"; |
|
44 |
|
45 private static final String FACET_VEGETATION_ZONES_CROSS_SECTION_DESCRIPTION = "uinfo_facet_vegetation_zones_cross_section.description"; |
|
46 |
|
47 private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>(); |
|
48 |
|
49 static { |
|
50 HANDLED_FACET_TYPES.add(FACET_VEGETATION_ZONES_CROSS_SECTION); |
|
51 } |
|
52 |
|
53 public static Facet createVegetationZonesCrossSectionFacet(final CallContext context, final String hash, final String id, |
|
54 final AbstractCalculationResult result, final int index) { |
|
55 return AbstractProcessor.createFacet(context, hash, id, result, index, CrossSectionGenerator.I18N_XAXIS_LABEL, FACET_VEGETATION_ZONES_CROSS_SECTION, |
|
56 FACET_VEGETATION_ZONES_CROSS_SECTION_DESCRIPTION); |
|
57 } |
|
58 |
|
59 public static void generateSeries(final CrossSectionGenerator generator, final ArtifactAndFacet bundle, final CallContext context, |
|
60 final ThemeDocument theme, final boolean visible) { |
|
61 |
|
62 final DataProvider provider = CrossSectionFacetUtils.getDataProvider(context); |
|
63 final FastCrossSectionLine crossSection = CrossSectionFacetUtils.getCrossSection(provider, context); |
|
64 if (crossSection == null) |
|
65 return; |
|
66 final double currentStation = crossSection.getKm(); |
|
67 |
|
68 if (bundle.getFacetName().equals(FACET_VEGETATION_ZONES_CROSS_SECTION)) { |
|
69 |
|
70 final StripedAreaDataset dataset = new StripedAreaDataset(theme); |
|
71 |
|
72 final Artifact artifact = bundle.getArtifact(); |
|
73 final VegetationzonesAccess vAccess = new VegetationzonesAccess((UINFOArtifact) artifact); |
|
74 final River river = vAccess.getRiver(); |
|
75 final List<VegetationZoneServerClientXChange> zones = VegetationZoneServerClientXChange.parse(vAccess.getVegZones()); |
|
76 |
|
77 for (final VegetationZoneServerClientXChange zone : zones) { |
|
78 |
|
79 final double lower = uefdToHeight(context, river, currentStation, zone.getLowerFromTo()); |
|
80 final double upper = uefdToHeight(context, river, currentStation, zone.getUpperFromTo()); |
|
81 |
|
82 final Color color = Color.decode(zone.getHexColor()); |
9501
|
83 final String label = String.format("%s (%dd-%dd)", zone.getZoneName(), zone.getLowerFromTo(), zone.getUpperFromTo()); |
|
84 dataset.addStripe(new Stripe(label, color, lower, upper)); |
9499
|
85 } |
|
86 |
|
87 generator.addAxisDataset(dataset, 0, visible); |
|
88 return; |
|
89 } |
|
90 |
|
91 throw new UnsupportedOperationException(); |
|
92 } |
|
93 |
|
94 private static double uefdToHeight(final CallContext context, final River river, final double station, final int uefd) { |
|
95 |
|
96 final MainWstValuesCalculator mainWstValues = MainWstValuesCalculator.forRiver(context, river, null, MAIN_VALUE_MQ); |
|
97 |
|
98 final double mw = mainWstValues.interpolateW(station, MAIN_VALUE_MQ); |
|
99 |
|
100 // Üfd = -70,559 ∗ ln((DGM - MW) + 0,5) + 80,711 |
|
101 final double f1 = -70.559; |
|
102 final double f2 = -88.711; |
|
103 |
|
104 final double dgm = Math.exp((uefd - f2) / f1) + mw - 0.5; |
|
105 return dgm; |
|
106 } |
|
107 |
|
108 public VegetationZonesCrossSectionProcessor() { |
|
109 super(CrossSectionGenerator.I18N_YAXIS_LABEL, HANDLED_FACET_TYPES); |
|
110 |
|
111 throw new UnsupportedOperationException(); |
|
112 } |
|
113 |
|
114 @Override |
|
115 protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) { |
|
116 throw new UnsupportedOperationException(); |
|
117 } |
|
118 |
|
119 } |