view gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java @ 308:677da0e143cc

Added dependencies for esri and ibm libraries required for unit tests. gnv-artifacts/trunk@366 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 24 Nov 2009 14:40:53 +0000
parents 80f7c5dc09c6
children 45625b5cd6d4
line wrap: on
line source
package de.intevation.gnv.chart;

import java.util.Collection;
import java.util.Locale;

import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.io.WKTReader;
import com.vividsolutions.jts.io.ParseException;

import org.apache.log4j.Logger;

import org.jfree.chart.ChartTheme;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.general.Series;
import org.jfree.data.xy.XYSeries;

import de.intevation.gnv.geobackend.base.Result;
import de.intevation.gnv.utils.DistanceCalculator;


/**
 * @author Ingo Weinzierl <ingo.weinzierl@intevation.de>
 */
public class HorizontalProfileChart
extends      VerticalProfileChart
{
    private static Logger log = Logger.getLogger(HorizontalProfileChart.class);

    private static WKTReader wktReader = new WKTReader();
    private        Point     lastPoint;
    private        double    distance;


    public HorizontalProfileChart(
        ChartLabels labels,
        ChartTheme  theme,
        Collection  parameters,
        Collection  measurements,
        Collection  result,
        Collection  dates,
        Locale      locale
    ) {
        super(labels, theme, parameters, measurements, result, dates, locale);
        this.PLOT_ORIENTATION = PlotOrientation.VERTICAL;
        this.distance         = 0;
    }


    protected void addValue(Result row, Series series) {
        // TODO look for gaps between two values
        try {
            Point point = (Point) wktReader.read(row.getString("SHAPE"));
            if (lastPoint != null)
                distance = distance + DistanceCalculator.calculateDistance(
                    lastPoint, point
                );
            lastPoint = point;

            ((XYSeries) series).add(
                distance,
                row.getDouble("YORDINATE")
            );
        }
        catch(ParseException pe) {
            log.warn("No data found while parsing.");
        }
    }


    protected void addSeries(Series series, int idx) {
        super.addSeries(series, idx);

        // reset values used by current series for next series
        lastPoint = null;
        distance  = 0;
    }


    protected String createSeriesName(
        String breakPoint1,
        String breakPoint2,
        String breakPoint3
    ) {
        log.debug("create seriesname of horizontalprofile chart");
        return super.createSeriesName(
            breakPoint1,
            breakPoint2,
            breakPoint3) +
            " " +
            findValueTitle(dates, breakPoint3);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=latin1 :

http://dive4elements.wald.intevation.org