Mercurial > dive4elements > gnv-client
changeset 837:43f3c0cd60f2
First implementation of an odv export of a 'Profilschnitt' (issue217).
gnv-artifacts/trunk@944 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 19 Apr 2010 10:55:25 +0000 |
parents | 05bf8534a35a |
children | e91ebe3696ec |
files | gnv-artifacts/ChangeLog gnv-artifacts/doc/conf/products/verticalcrosssection/conf_mesh.xml gnv-artifacts/src/main/java/de/intevation/gnv/exports/VerticalCrossODVExport.java gnv-artifacts/src/main/java/de/intevation/gnv/math/Interpolation3D.java gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java |
diffstat | 5 files changed, 310 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Sun Apr 18 09:17:25 2010 +0000 +++ b/gnv-artifacts/ChangeLog Mon Apr 19 10:55:25 2010 +0000 @@ -1,3 +1,24 @@ +2010-04-19 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + Issue217 + + * doc/conf/products/verticalcrosssection/conf_mesh.xml: Added odv as + possible export format. + + * src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java: + Collect the necessary data for an odv export and trigger + VerticalCrossODVExport that writes this data as odv to an output stream. + + * src/main/java/de/intevation/gnv/math/Interpolation3D.java: Store + coordinates for each colum in a class variable. + + * src/main/java/de/intevation/gnv/exports/VerticalCrossODVExport.java: + Write data used in 'Profilschnitten' to an odv file. + + TODO: The implementation is not finished yet. There are no cruises and + stations for 'Profilschnitte', so we need to clarify if this columns can + be skipped. + 2010-04-18 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/gnv/**/*.java:
--- a/gnv-artifacts/doc/conf/products/verticalcrosssection/conf_mesh.xml Sun Apr 18 09:17:25 2010 +0000 +++ b/gnv-artifacts/doc/conf/products/verticalcrosssection/conf_mesh.xml Mon Apr 19 10:55:25 2010 +0000 @@ -249,6 +249,7 @@ <export name="svg" description="SVG-Export der Daten" mime-type="image/svg+xml" /> </exportModes> </outputsMode> + <outputsMode name="odv" description="ODV-Export der Daten" mime-type="text/plain"/> </outputsModes> </state> </states>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/exports/VerticalCrossODVExport.java Mon Apr 19 10:55:25 2010 +0000 @@ -0,0 +1,202 @@ +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.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.apache.log4j.Logger; + +import au.com.bytecode.opencsv.CSVWriter; +import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.math.Interpolation3D; +import de.intevation.gnv.state.describedata.KeyValueDescibeData; +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; + + /** + * 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[] raster, + String time, + int width, + int height) + { + this.coordinates = coordinates; + this.cellHeight = cellHeight; + 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, raster); + + writer.close(); + } + + protected void writeData( + CSVWriter writer, + String time, + Coordinate[] coordinates, + double cellHeight, + double[] raster) + { + if (logger.isDebugEnabled()) { + logger.debug("+++++++ ODV Export information ++++++++++"); + logger.debug("+ raster width: " + width); + logger.debug("+ raster height: " + height); + 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); + } + + String[] row = new String[10]; + for (int i = 0; i < width; i++) { + row[0] = "Station_" + i; + //row[0] = ""; + row[1] = ""; + row[2] = "*"; + row[3] = datetime; + row[4] = Double.toString(coordinates[i].x); + row[5] = Double.toString(coordinates[i].y); + row[6] = "0"; + + for (int j = 0; j < height; j++) { + if (j == 1) { + row[0] = ""; + //row[0] = "Station_"; + row[1] = ""; + row[2] = ""; + row[3] = ""; + row[4] = ""; + row[5] = ""; + row[6] = ""; + } + + // row[2] = Double.toString(depths[j]); + // + row[7] = Double.toString(j * cellHeight + cellHeight / 2d); + row[8] = "1"; + double value = raster[i+(j*height)]; + + if (Double.isNaN(value)) { + break; + } + + row[9] = Double.toString(value); + + writer.writeNext(row); + } + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/Interpolation3D.java Sun Apr 18 09:17:25 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/Interpolation3D.java Mon Apr 19 10:55:25 2010 +0000 @@ -61,6 +61,11 @@ protected double cellHeight; /** + * The coordinates of the interpolation. + */ + protected Coordinate[] coordinates; + + /** * The generated raster. */ protected double [] raster; @@ -128,6 +133,14 @@ } /** + * Returns the coordinates used for the interpolation. + * @return the coordinates used for the interpolation. + */ + public Coordinate[] getCoordinates() { + return coordinates; + } + + /** * Returns the generated raster. * @return The generated raster. */ @@ -212,6 +225,8 @@ double [] depths = new double[width]; Arrays.fill(depths, Double.NaN); + Coordinate[] coordinates = new Coordinate[width]; + double cellWidth = (to - from)/width; double maxDepth = Double.MAX_VALUE; @@ -220,6 +235,7 @@ Coordinate center = new Coordinate(); for (double p = cellWidth*0.5; i < depths.length; ++i, p += cellWidth) { if (linearToMap.locate(p, center)) { + coordinates[i] = (Coordinate) center.clone(); double depth = xyDepth.depth(center); depths[i] = depth; if (depth < maxDepth) { @@ -315,10 +331,11 @@ } // down the x/y column } // all along the track - this.depths = depths; - this.raster = raster; - this.cellWidth = cellWidth; - this.cellHeight = cellHeight; + this.coordinates = coordinates; + this.depths = depths; + this.raster = raster; + this.cellWidth = cellWidth; + this.cellHeight = cellHeight; return true; }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java Sun Apr 18 09:17:25 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java Mon Apr 19 10:55:25 2010 +0000 @@ -1,5 +1,7 @@ package de.intevation.gnv.state.profile.verticalcrosssection; +import au.com.bytecode.opencsv.CSVWriter; + import java.awt.Color; import java.awt.Dimension; import java.awt.Paint; @@ -30,6 +32,9 @@ import de.intevation.gnv.chart.Chart; import de.intevation.gnv.chart.ChartLabels; import de.intevation.gnv.chart.VerticalCrossSectionChart; +import de.intevation.gnv.exports.DefaultProfile; +import de.intevation.gnv.exports.Export; +import de.intevation.gnv.exports.VerticalCrossODVExport; import de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.geobackend.base.ResultDescriptor; import de.intevation.gnv.geobackend.base.query.QueryExecutor; @@ -668,13 +673,66 @@ } @Override - protected void createODV(OutputStream outputStream, String uuid, - CallContext callContext) throws IOException, - StateException { - Object chartResult = this.getChartResult(uuid, callContext); - log.debug("Hier gehts weiter"); + protected void createODV( + OutputStream outputStream, + String uuid, + CallContext callContext) + throws IOException, StateException + { + // 'Profilschnitte' contain one parameter only + Collection tmp = getParameters(uuid); + KeyValueDescibeData param = (KeyValueDescibeData) tmp.toArray()[0]; + + String [] COLUMN_HEADER = { + "Cruise", + "Station", + "Type", + "yyyy-mm-dd hh:mm", + "Lon (°E)", + "Lat (°N)", + "Bot. Depth [m]", + "Depth [m]", + "QF", + param.getValue() + }; + + Export.Profile ODV_PROFILE = new DefaultProfile( + COLUMN_HEADER, + '\t', + CSVWriter.NO_QUOTE_CHARACTER, + CSVWriter.NO_ESCAPE_CHARACTER, + "ODV", + "ISO-8859-1"); + + Object chartResult = getChartResult(uuid, callContext); + + if (chartResult == null) { + log.error("No data for export found."); + return; + } + + List result = new ArrayList(1); + result.add(chartResult); + + InputData data = inputData.get(dateValueName); + String date = data.getDescription()[0]; + + Interpolation3D interpol = ((AttributedXYColumns) + chartResult).getInterpolation(); + + Coordinate[] coords = interpol.getCoordinates(); + double[] depth = interpol.getDepths(); + double[] raster = interpol.getRaster(); + + Export export = new VerticalCrossODVExport( + interpol.getCoordinates(), + interpol.getCellHeight(), + interpol.getRaster(), + date, + interpol.getWidth(), + interpol.getHeight()); + + export.create(ODV_PROFILE, outputStream, null); } - - } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :