Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesCrossSectionProcessor.java @ 9499:853f2dafc16e
VegetationZones in CrossSectionsDiagram
author | gernotbelger |
---|---|
date | Thu, 27 Sep 2018 18:06:26 +0200 |
parents | |
children | cb3dabb77857 |
comparison
equal
deleted
inserted
replaced
9496:d8e753d0fdb9 | 9499:853f2dafc16e |
---|---|
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()); | |
83 dataset.addStripe(new Stripe(zone.getZoneName(), color, lower, upper)); | |
84 } | |
85 | |
86 generator.addAxisDataset(dataset, 0, visible); | |
87 return; | |
88 } | |
89 | |
90 throw new UnsupportedOperationException(); | |
91 } | |
92 | |
93 private static double uefdToHeight(final CallContext context, final River river, final double station, final int uefd) { | |
94 | |
95 final MainWstValuesCalculator mainWstValues = MainWstValuesCalculator.forRiver(context, river, null, MAIN_VALUE_MQ); | |
96 | |
97 final double mw = mainWstValues.interpolateW(station, MAIN_VALUE_MQ); | |
98 | |
99 // Üfd = -70,559 ∗ ln((DGM - MW) + 0,5) + 80,711 | |
100 final double f1 = -70.559; | |
101 final double f2 = -88.711; | |
102 | |
103 final double dgm = Math.exp((uefd - f2) / f1) + mw - 0.5; | |
104 return dgm; | |
105 } | |
106 | |
107 public VegetationZonesCrossSectionProcessor() { | |
108 super(CrossSectionGenerator.I18N_YAXIS_LABEL, HANDLED_FACET_TYPES); | |
109 | |
110 throw new UnsupportedOperationException(); | |
111 } | |
112 | |
113 @Override | |
114 protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) { | |
115 throw new UnsupportedOperationException(); | |
116 } | |
117 | |
118 } |