Mercurial > dive4elements > gnv-client
view gnv-artifacts/src/main/java/de/intevation/gnv/exports/VerticalCrossODVExport.java @ 1052:b30361464775
The pdf format depends on the chart's aspect ratio (issue290).
gnv-artifacts/trunk@1126 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 26 May 2010 06:45:03 +0000 |
parents | dfd02f8d3602 |
children | f953c9a559d8 |
line wrap: on
line source
package de.intevation.gnv.exports; import com.vividsolutions.jts.geom.Coordinate; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Collection; import java.util.Date; import org.apache.log4j.Logger; import au.com.bytecode.opencsv.CSVWriter; import de.intevation.gnv.state.exception.StateException; public class VerticalCrossODVExport implements Export { /** * Constant field which defines the source format of a given datetime. */ public static final String SRC_FORMAT = "yyyy.MM.dd HH:mm:ss"; /** * Constant field which defines the target format of a given datetime. */ public static final String DEST_FORMAT = "yyyy-MM-dd HH:mm"; /** * Source format. */ public static DateFormat srcFormat = new SimpleDateFormat(SRC_FORMAT); /** * Target format. */ public static DateFormat destFormat = new SimpleDateFormat(DEST_FORMAT); /** * Logger used for logging via log4j. */ private static Logger logger = Logger.getLogger(VerticalCrossODVExport.class); /** * The path in coordinates. */ protected Coordinate[] coordinates; /** * */ protected double cellHeight; /** * */ protected double cellWidth; /** * The raster array storing the values for a specific coordinate in a * specific depth. */ protected double[] raster; /** * The raster width. */ protected int width; /** * The raster height. */ protected int height; /** * The date of this export. */ protected String time; /** * The constructor used to create a new export helper object. */ public VerticalCrossODVExport( Coordinate[] coordinates, double cellHeight, double cellWidth, double[] raster, String time, int width, int height) { this.coordinates = coordinates; this.cellHeight = cellHeight; this.cellWidth = cellWidth; this.raster = raster; this.width = width; this.height = height; this.time = time; } /** * * @param profile The Profile used to create column headers. * @param outputStream The stream where the odv data are written to. * @param result Not used here, might be null. */ public void create( Profile profile, OutputStream outputStream, Collection result) throws IOException, UnsupportedEncodingException, StateException { CSVWriter writer = new CSVWriter( new OutputStreamWriter(outputStream, profile.getEncoding()), profile.getSeparator(), profile.getQuoteCharacter(), profile.getEscapeCharacter()); writer.writeNext(profile.getHeader()); writeData(writer, time, coordinates, cellHeight, cellWidth, raster); writer.close(); } protected void writeData( CSVWriter writer, String time, Coordinate[] coordinates, double cellHeight, double cellWidth, double[] raster) { if (logger.isDebugEnabled()) { logger.debug("+++++++ ODV Export information ++++++++++"); logger.debug("+ raster width: " + width); logger.debug("+ raster height: " + height); logger.debug("+ cell height: " + cellHeight); logger.debug("+ cell width: " + cellWidth); logger.debug("+ items in raster: " + raster.length); logger.debug("+ number of coordinates: " + coordinates.length); logger.debug("+++++++++++++++++++++++++++++++++++++++++"); } String datetime = null; try { Date tmp = srcFormat.parse(time); datetime = destFormat.format(tmp); } catch (ParseException pe) { logger.error(pe, pe); } double maxDepth = 0; String[] row = new String[10]; for (int i = 0; i < width; i++) { row[0] = "GNVExport"; row[1] = "Station_" + i; row[2] = "*"; row[3] = datetime; row[4] = Double.toString(coordinates[i].x); row[5] = Double.toString(coordinates[i].y); row[6] = "0"; double depth = cellHeight * 0.5d; for (int j = i; j < raster.length; j += width, depth += cellHeight) { if (j == (i+width)) { row[0] = ""; row[1] = ""; row[2] = ""; row[3] = ""; row[4] = ""; row[5] = ""; row[6] = ""; } double value = raster[j]; row[7] = Double.toString(depth); row[8] = "1"; row[9] = Double.toString(value); maxDepth = maxDepth >= depth ? maxDepth : depth; if (Double.isNaN(value)) { break; } writer.writeNext(row); } } logger.info("Detected max depth: " + maxDepth); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :