Mercurial > dive4elements > gnv-client
view gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshVectorOutputState.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 | 5659b5c5e4b5 |
children | f953c9a559d8 |
line wrap: on
line source
package de.intevation.gnv.state.profile.horizontal; import au.com.bytecode.opencsv.CSVWriter; import de.intevation.artifacts.CallContext; import de.intevation.gnv.artifacts.cache.CacheFactory; import de.intevation.gnv.chart.Chart; import de.intevation.gnv.chart.ChartLabels; import de.intevation.gnv.chart.HorizontalProfileVectorChart; import de.intevation.gnv.exports.DefaultExport; import de.intevation.gnv.exports.DefaultProfile; import de.intevation.gnv.exports.Export; import de.intevation.gnv.exports.Export.Profile; import de.intevation.gnv.exports.SimpleOdvDataCollector; import de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.utils.VectorDataProcessor; import de.intevation.gnv.state.describedata.KeyValueDescibeData; import de.intevation.gnv.state.exception.StateException; import de.intevation.gnv.statistics.Statistics; import de.intevation.gnv.statistics.HorizontalProfileVectorStatistics; import java.io.IOException; import java.io.OutputStream; import java.util.Collection; import java.util.Locale; import java.util.Map; import net.sf.ehcache.Cache; import org.apache.log4j.Logger; import org.jfree.chart.ChartTheme; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class HorizontalProfileMeshVectorOutputState extends HorizontalProfileMeshOutputState { private static Logger logger = Logger.getLogger(HorizontalProfileMeshVectorOutputState.class); public static final String[] RESULT_COLUMNS = { "YORDINATE", "SHAPE", "GROUP1", "GROUP2", "GROUP3", "IPOSITION", "JPOSITION", "DATAID", "MESHID", "SERIES" }; public static final String[] ODV_COLUMN_HEADERS = { "Cruise", "Station", "Type", "yyyy-mm-dd hh:mm", "Lon (°E)", "Lat (°N)", "Bot. Depth [m]", "Depth [m]", "QF", "XComponent", "QF", "YComponent", "QF", "ZComponent", "QF", "Speed", "QF", "Direction", "QF" }; public static final String[] ODV_PROFILE_NAMES = { "CRUISE", "STATION", "TYPE", "TIMEVALUE", "SHAPE", "BOTDEPTH", "DEPTH", "QF", "XCOMPONENT", "QF", "YCOMPONENT", "QF", "ZCOMPONENT", "QF", "SPEED", "QF", "DIRECTION", "QF"}; @Override protected Object getChartResult(String uuid, CallContext callContext) { logger.debug("Fetch data for horizontalprofile chart with vector data"); CacheFactory factory = CacheFactory.getInstance(); if (factory.isInitialized()) { // we use a cache logger.info("Using cache."); Cache cache = factory.getCache(); String key = "chart_" + getHash(); net.sf.ehcache.Element value = cache.get(key); if (value != null) { logger.debug("Found element in cache."); return value.getObjectValue(); } else { logger.debug("Element not in cache, we ask the database"); Collection<Result> res = (Collection<Result>)getData(queryID); res = VectorDataProcessor.process(res, RESULT_COLUMNS); logger.debug("Got " + res.size() + " elements from database."); cache.put(new net.sf.ehcache.Element(key, res)); return res; } } else { // we don't use a cache, so we have to query the database every // single time logger.info("Not using a cache."); return VectorDataProcessor.process( getData(queryID), RESULT_COLUMNS); } } @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 = new HorizontalProfileVectorChart( chartLables, theme, parameters, measurements, dates, (Collection)result, timeGapDefinitions, locale, linesVisible, shapesVisible ); chart.generateChart(); return chart; } @Override protected Chart[] getHistograms( String uuid, CallContext callContext, Collection<KeyValueDescibeData> parameters, Collection<KeyValueDescibeData> measurements, Collection<KeyValueDescibeData> dates, Map requestParameter ) { Collection results = (Collection) getChartResult(uuid, callContext); ChartTheme theme = createStyle(callContext); return VectorDataProcessor.getHistograms( uuid, callContext, results, theme, requestParameter); } @Override protected void createODV( OutputStream outputStream, Collection result, String uuid) throws IOException, StateException { logger.info("Start exporting " + result.size() + " items to odv."); Export export = new DefaultExport( new SimpleOdvDataCollector(ODV_PROFILE_NAMES)); Profile profile = new DefaultProfile( ODV_COLUMN_HEADERS, '\t', CSVWriter.NO_QUOTE_CHARACTER, CSVWriter.NO_ESCAPE_CHARACTER, "ODV", "ISO-8859-1"); export.create(profile, outputStream, result); } protected Statistics getStatisticsGenerator() { return new HorizontalProfileVectorStatistics(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :