comparison gnv-artifacts/src/main/java/de/intevation/gnv/exports/VerticalCrossODVExport.java @ 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
children 39d06d01825a
comparison
equal deleted inserted replaced
836:05bf8534a35a 837:43f3c0cd60f2
1 package de.intevation.gnv.exports;
2
3 import com.vividsolutions.jts.geom.Coordinate;
4
5 import java.io.IOException;
6 import java.io.OutputStream;
7 import java.io.OutputStreamWriter;
8 import java.io.UnsupportedEncodingException;
9
10 import java.text.DateFormat;
11 import java.text.ParseException;
12 import java.text.SimpleDateFormat;
13
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.Date;
17 import java.util.HashMap;
18 import java.util.Iterator;
19 import java.util.Map;
20
21 import org.apache.log4j.Logger;
22
23 import au.com.bytecode.opencsv.CSVWriter;
24 import de.intevation.gnv.geobackend.base.Result;
25 import de.intevation.gnv.math.Interpolation3D;
26 import de.intevation.gnv.state.describedata.KeyValueDescibeData;
27 import de.intevation.gnv.state.exception.StateException;
28
29
30 public class VerticalCrossODVExport implements Export {
31
32 /**
33 * Constant field which defines the source format of a given datetime.
34 */
35 public static final String SRC_FORMAT = "yyyy.MM.dd HH:mm:ss";
36
37 /**
38 * Constant field which defines the target format of a given datetime.
39 */
40 public static final String DEST_FORMAT = "yyyy-MM-dd HH:mm";
41
42 /**
43 * Source format.
44 */
45 public static DateFormat srcFormat = new SimpleDateFormat(SRC_FORMAT);
46
47 /**
48 * Target format.
49 */
50 public static DateFormat destFormat = new SimpleDateFormat(DEST_FORMAT);
51
52 /**
53 * Logger used for logging via log4j.
54 */
55 private static Logger logger =
56 Logger.getLogger(VerticalCrossODVExport.class);
57
58 /**
59 * The path in coordinates.
60 */
61 protected Coordinate[] coordinates;
62
63 /**
64 *
65 */
66 protected double cellHeight;
67
68 /**
69 * The raster array storing the values for a specific coordinate in a
70 * specific depth.
71 */
72 protected double[] raster;
73
74 /**
75 * The raster width.
76 */
77 protected int width;
78
79 /**
80 * The raster height.
81 */
82 protected int height;
83
84 /**
85 * The date of this export.
86 */
87 protected String time;
88
89 /**
90 * The constructor used to create a new export helper object.
91 */
92 public VerticalCrossODVExport(
93 Coordinate[] coordinates,
94 double cellHeight,
95 double[] raster,
96 String time,
97 int width,
98 int height)
99 {
100 this.coordinates = coordinates;
101 this.cellHeight = cellHeight;
102 this.raster = raster;
103 this.width = width;
104 this.height = height;
105 this.time = time;
106 }
107
108
109 /**
110 *
111 * @param profile The Profile used to create column headers.
112 * @param outputStream The stream where the odv data are written to.
113 * @param result Not used here, might be null.
114 */
115 public void create(
116 Profile profile,
117 OutputStream outputStream,
118 Collection result)
119 throws
120 IOException,
121 UnsupportedEncodingException,
122 StateException
123 {
124 CSVWriter writer = new CSVWriter(
125 new OutputStreamWriter(outputStream, profile.getEncoding()),
126 profile.getSeparator(),
127 profile.getQuoteCharacter(),
128 profile.getEscapeCharacter());
129
130 writer.writeNext(profile.getHeader());
131
132 writeData(writer, time, coordinates, cellHeight, raster);
133
134 writer.close();
135 }
136
137 protected void writeData(
138 CSVWriter writer,
139 String time,
140 Coordinate[] coordinates,
141 double cellHeight,
142 double[] raster)
143 {
144 if (logger.isDebugEnabled()) {
145 logger.debug("+++++++ ODV Export information ++++++++++");
146 logger.debug("+ raster width: " + width);
147 logger.debug("+ raster height: " + height);
148 logger.debug("+ items in raster: " + raster.length);
149 logger.debug("+ number of coordinates: " + coordinates.length);
150 logger.debug("+++++++++++++++++++++++++++++++++++++++++");
151 }
152
153 String datetime = null;
154 try {
155 Date tmp = srcFormat.parse(time);
156 datetime = destFormat.format(tmp);
157 }
158 catch (ParseException pe) {
159 logger.error(pe, pe);
160 }
161
162 String[] row = new String[10];
163 for (int i = 0; i < width; i++) {
164 row[0] = "Station_" + i;
165 //row[0] = "";
166 row[1] = "";
167 row[2] = "*";
168 row[3] = datetime;
169 row[4] = Double.toString(coordinates[i].x);
170 row[5] = Double.toString(coordinates[i].y);
171 row[6] = "0";
172
173 for (int j = 0; j < height; j++) {
174 if (j == 1) {
175 row[0] = "";
176 //row[0] = "Station_";
177 row[1] = "";
178 row[2] = "";
179 row[3] = "";
180 row[4] = "";
181 row[5] = "";
182 row[6] = "";
183 }
184
185 // row[2] = Double.toString(depths[j]);
186 //
187 row[7] = Double.toString(j * cellHeight + cellHeight / 2d);
188 row[8] = "1";
189 double value = raster[i+(j*height)];
190
191 if (Double.isNaN(value)) {
192 break;
193 }
194
195 row[9] = Double.toString(value);
196
197 writer.writeNext(row);
198 }
199 }
200 }
201 }
202 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org