view artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesCrossSectionProcessor.java @ 9509:6146358c4842

Fixed: f2 sign corrected in vegetation zone height calculation, vegetation zone limit handling changed in the importer
author mschaefer
date Mon, 01 Oct 2018 09:53:36 +0200
parents 8b7bf26b8782
children ee6508687e3f
line wrap: on
line source
/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
 * Software engineering by
 *  Björnsen Beratende Ingenieure GmbH
 *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */
package org.dive4elements.river.artifacts.uinfo.vegetationzones;

import java.awt.Color;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
import org.dive4elements.artifactdatabase.state.Facet;
import org.dive4elements.artifacts.Artifact;
import org.dive4elements.artifacts.CallContext;
import org.dive4elements.artifacts.DataProvider;
import org.dive4elements.river.artifacts.D4EArtifact;
import org.dive4elements.river.artifacts.common.AbstractProcessor;
import org.dive4elements.river.artifacts.model.CrossSectionFacetUtils;
import org.dive4elements.river.artifacts.model.river.MainWstValuesCalculator;
import org.dive4elements.river.exports.CrossSectionGenerator;
import org.dive4elements.river.exports.DiagramGenerator;
import org.dive4elements.river.jfree.StripedAreaDataset;
import org.dive4elements.river.jfree.StripedAreaDataset.Stripe;
import org.dive4elements.river.model.FastCrossSectionLine;
import org.dive4elements.river.model.River;
import org.dive4elements.river.themes.ThemeDocument;

/**
 * @author Domenico Nardi Tironi
 *
 */
public class VegetationZonesCrossSectionProcessor extends AbstractProcessor {

    private static final String MAIN_VALUE_MQ = "mq";

    public static final String FACET_VEGETATION_ZONES_CROSS_SECTION = "uinfo_facet_vegetation_zones_cross_section";


    private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>();

    static {
        HANDLED_FACET_TYPES.add(FACET_VEGETATION_ZONES_CROSS_SECTION);
    }

    public static Facet createVegetationZonesCrossSectionFacet(final String description) {

        return new VegetationZonesCrossSectionFacet(FACET_VEGETATION_ZONES_CROSS_SECTION, description);
    }

    public static void generateSeries(final CrossSectionGenerator generator, final ArtifactAndFacet bundle, final CallContext context,
            final ThemeDocument theme, final boolean visible) {

        final DataProvider provider = CrossSectionFacetUtils.getDataProvider(context);
        final FastCrossSectionLine crossSection = CrossSectionFacetUtils.getCrossSection(provider, context);
        if (crossSection == null)
            return;
        final double currentStation = crossSection.getKm();

        if (bundle.getFacetName().equals(FACET_VEGETATION_ZONES_CROSS_SECTION)) {

            final StripedAreaDataset dataset = new StripedAreaDataset(theme);

            final Artifact artifact = bundle.getArtifact();
            final VegetationzonesAccess vAccess = new VegetationzonesAccess((D4EArtifact) artifact);
            final River river = vAccess.getRiver();
            final List<VegetationZoneServerClientXChange> zones = VegetationZoneServerClientXChange.parse(vAccess.getVegZones());

            for (final VegetationZoneServerClientXChange zone : zones) {

                final double lower = uefdToHeight(context, river, currentStation, zone.getLowerFromTo());
                final double upper = uefdToHeight(context, river, currentStation, zone.getUpperFromTo());

                final Color color = Color.decode(zone.getHexColor());
                final String label = String.format("%s (%dd-%dd)", zone.getZoneName(), zone.getLowerFromTo(), zone.getUpperFromTo());
                dataset.addStripe(new Stripe(label, color, lower, upper));
            }

            generator.addAxisDataset(dataset, 0, visible);
            return;
        }

        throw new UnsupportedOperationException();
    }

    private static double uefdToHeight(final CallContext context, final River river, final double station, final int uefd) {

        final MainWstValuesCalculator mainWstValues = MainWstValuesCalculator.forRiver(context, river, null, MAIN_VALUE_MQ);

        final double mw = mainWstValues.interpolateW(station, MAIN_VALUE_MQ);

        // Üfd = -70,559 ∗ ln((DGM - MW) + 0,5) + 80,711
        final double f1 = -70.559;
        final double f2 = 88.711;

        final double dgm = Math.exp((uefd - f2) / f1) + mw - 0.5;
        return dgm;
    }

    public VegetationZonesCrossSectionProcessor() {
        super(CrossSectionGenerator.I18N_YAXIS_LABEL, HANDLED_FACET_TYPES);

        throw new UnsupportedOperationException();
    }

    @Override
    protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) {
        throw new UnsupportedOperationException();
    }

}

http://dive4elements.wald.intevation.org