Mercurial > dive4elements > gnv-client
view gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/vertical/VerticalProfileOutputState.java @ 1082:3c0fd3c2fd6b
Enabled histogram creation for vectorial horizontalprofiles.
gnv-artifacts/trunk@1184 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 09 Jun 2010 09:58:38 +0000 |
parents | 05bf8534a35a |
children | f953c9a559d8 |
line wrap: on
line source
package de.intevation.gnv.state.profile.vertical; import de.intevation.artifacts.CallContext; import de.intevation.gnv.chart.Chart; import de.intevation.gnv.chart.ChartLabels; import de.intevation.gnv.chart.VerticalProfileChart; import de.intevation.gnv.exports.DefaultDataCollector; import de.intevation.gnv.exports.DefaultExport; import de.intevation.gnv.exports.DefaultProfile; import de.intevation.gnv.exports.Export.Profile; 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; import de.intevation.gnv.statistics.VerticalProfileStatistics; import java.io.IOException; import java.io.OutputStream; 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; /** * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> * */ public class VerticalProfileOutputState extends TimeSeriesOutputState { public static final String [] VERTICAL_PROFILE_COLUMNS = { "XORDINATE", // not quite sure if this is depth "YORDINATE", "GROUP1", "FEATUREID", "TIMESERIESID" }; public static final String [] VERTICAL_PROFILE_MESH_COLUMNS = { "XORDINATE", // not quite sure if this is depth "YORDINATE", "GROUP1", "FEATUREID", "MESHID" }; public static final String [] VERTICAL_PROFILE_MEASUREMENT_COLUMNS = { "XORDINATE", // not quite sure if this is depth "YORDINATE", "GROUP1", "FEATUREID", "SERIESID" }; public static final String [] VERTICAL_MESH_CSV_COLUMN_LABEL = { "CentralDepth", "Value", "ParameterID", "FeatureID", "MeshID" }; public static final String [] VERTICAL_TIMESERIES_CSV_COLUMN_LABEL = { "Depth", "Value", "ParameterID", "FeatureID", "TimeseriesID" }; public static final String [] VERTICAL_MEASUREMENT_CSV_COLUMN_LABEL = { "Depth", "Value", "ParameterID", "FeatureID", "SeriesID" }; /** * The UID of this class */ private static final long serialVersionUID = 4401516087492028840L; private static Logger log = Logger .getLogger(TimeSeriesOutputState.class); /** * Creates a new VerticalProfileOutputState object. */ public VerticalProfileOutputState() { super(); super.domainLable = "chart.verticalprofile.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, CallContext callContext ) { Chart chart = null; if (CACHE_CHART) { log.info("Try to get verticalprofile chart from cache."); chart = (Chart) getChartFromCache(uuid, callContext); } if (chart != null) return chart; log.info("Chart not in cache yet."); chart = new VerticalProfileChart( chartLables, theme, parameters, measurements, dates, (Collection)result, null, locale, linesVisible, shapesVisible ); chart.generateChart(); if (CACHE_CHART) { log.info("Put chart into cache."); purifyChart(chart, uuid); } return chart; } /** * Creates a csv file of the resulting data and writes it to output stream. * * @param out The output stream. * @param results The data used to create the csv file. * @throws UnsupportedEncodingException if the encoding is not supported. * @throws IOException if an error occured while writing to output stream. * @throws StateException if an error occured while creating the csv file. */ @Override protected void createCSV(OutputStream out, Collection<Result> results) throws UnsupportedEncodingException, IOException, StateException { Iterator<Result> iter = results.iterator(); Result res = iter.hasNext() ? iter.next() : null; if (res == null) return; Profile profile = null; int dataid = res.getInteger("DATAID").intValue(); DefaultExport export = null; // on meshes if (dataid == 2) { profile = new DefaultProfile( VERTICAL_MESH_CSV_COLUMN_LABEL, ',', '"', '"', "CSV", "ISO-8859-1"); export = new DefaultExport( new DefaultDataCollector(VERTICAL_PROFILE_MESH_COLUMNS)); } // on timeseries else if (dataid == 1) { profile = new DefaultProfile( VERTICAL_TIMESERIES_CSV_COLUMN_LABEL, ',', '"', '"', "CSV", "ISO-8859-1"); export = new DefaultExport( new DefaultDataCollector(VERTICAL_PROFILE_COLUMNS)); } // on measurements else { profile = new DefaultProfile( VERTICAL_MEASUREMENT_CSV_COLUMN_LABEL, ',', '"', '"', "CSV", "ISO-8859-1"); export = new DefaultExport( new DefaultDataCollector(VERTICAL_PROFILE_MEASUREMENT_COLUMNS)); } export.create(profile, out, results); } @Override protected String createChartSubtitle(Locale locale, String uuid) { return getSelectedFeatureName(uuid); } @Override protected Statistics getStatisticsGenerator() { return new VerticalProfileStatistics(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :