view gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java @ 429:bed9735adf84

Finished preprocessing data for interpolation in verticalcrosssection charts.ß gnv-artifacts/trunk@477 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 22 Dec 2009 17:19:10 +0000
parents 2f7a28f211c7
children 8975de9d7483
line wrap: on
line source
/**
 *
 */
package de.intevation.gnv.state.profile.horizontalcrosssection;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.util.Collection;
import java.util.Iterator;
import java.util.Locale;

import org.apache.log4j.Logger;

import org.jfree.chart.ChartTheme;

import au.com.bytecode.opencsv.CSVWriter;
import de.intevation.gnv.chart.Chart;
import de.intevation.gnv.chart.ChartLabels;
import de.intevation.gnv.geobackend.base.Result;
import de.intevation.gnv.state.exception.StateException;
import de.intevation.gnv.state.timeseries.TimeSeriesOutputState;
import de.intevation.gnv.statistics.Statistics;

/**
 * @author Tim Englich <tim.englich@intevation.de>
 * 
 */
public class HorizontalCrossSectionMeshOutputState 
                                      extends TimeSeriesOutputState {

    private static Logger log = Logger
    .getLogger(HorizontalCrossSectionMeshOutputState.class);
    
    /**
     * The UID of this Class
     */
    private static final long serialVersionUID = 3233620652465061860L;

    /**
     * Constructor
     */
    public HorizontalCrossSectionMeshOutputState() {
        super();
        super.domainLable = "chart.horizontalcrosssection.title.xaxis";
    }

    @Override
    protected Chart getChart(
        ChartLabels  chartLables,
        ChartTheme   theme,
        Collection   parameters,
        Collection   measurements,
        Collection   dates,
        Object       result,
        Locale       locale,
        String       uuid,
        boolean      linesVisible,
        boolean      shapesVisible
    ) {
        Chart chart = null;

        if (CACHE_CHART) {
            log.info("Try to get horizontalcrosssection chart from cache.");
            chart = (Chart) getChartFromCache(uuid);
        }

        if (chart != null)
            return chart;

        log.info("Chart not in cache yet.");
        
        log.warn("This sort of chart is not implemented yet.");
        /* TODO Implement a special chart for this sort of charts.
        chart = new HorizontalProfileChart(
            chartLables,
            chartTheme,
            parameters,
            measurements,
            result,
            dates,
            locale
        );
        chart.generateChart();

        if (CACHE_CHART) {
            log.info("Put chart into cache.");
            purifyChart(chart, uuid);
        }
        */

        return chart;
    }


    /**
     * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#getStatisticsGenerator()
     */
    @Override
    protected Statistics getStatisticsGenerator() {
        return null; //Statistiken werden nicht f�r diesen Out-Typ unterst�tzt.
    }
    
    /**
     * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#createCSV(java.io.OutputStream,
     *      java.util.Collection)
     */
    @Override
    protected void createCSV(OutputStream outputStream,
                             Collection<Result> chartResult)
                                            throws UnsupportedEncodingException,
                                                   IOException,
                                                   StateException {
        if (chartResult != null) {
            try {
                CSVWriter writer = new CSVWriter(new OutputStreamWriter(
                        outputStream, "ISO-8859-1"), ','); 
                // USE THIS ENCODING BECAUSE OF
                // PROBLEMS WITH EXCEL AND UTF-8
                Iterator<Result> it = chartResult.iterator();
                while (it.hasNext()) {
                    Result result = it.next();
                    int i = 0;
                    String[] entries = new String[5];
                    entries[i++] = result.getString("SHAPE");
                    entries[i++] = result.getString("YORDINATE");
                    entries[i++] = result.getString("IPOSITION");
                    entries[i++] = result.getString("JPOSITION");
                    entries[i++] = result.getString("KPOSITION");
                    writer.writeNext(entries);
                }
                writer.close();
            } catch (Exception e) {
                log.error(e,e);
                throw new StateException(
                "Exception occured while parsing an Point from WKT.");
            }
        } else {
            log.error("No Data given for generating an CSV-File.");
            throw new StateException(
                    "No Data given for generating an CSV-File.");
        }
    }

}

http://dive4elements.wald.intevation.org