Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/exports/SimpleOdvDataCollector.java @ 592:3c939c95c477
Removed accidental checkin of Test-Shapefiles
gnv-artifacts/trunk@647 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Fri, 29 Jan 2010 13:28:28 +0000 |
parents | e964a3d8f7bc |
children | a0e63136954e |
rev | line source |
---|---|
238
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.gnv.exports; |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.util.Date; |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 import java.text.DateFormat; |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 import java.text.SimpleDateFormat; |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 import org.apache.log4j.Logger; |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import com.vividsolutions.jts.io.ParseException; |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import com.vividsolutions.jts.geom.Point; |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 import de.intevation.gnv.geobackend.base.Result; |
335
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
301
diff
changeset
|
13 import de.intevation.gnv.state.exception.StateException; |
238
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 /** |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 */ |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 public class SimpleOdvDataCollector |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 extends ShapeDataCollector |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 { |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 private static Logger log = Logger.getLogger(SimpleOdvDataCollector.class); |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 public static final String SRC_FORMAT = "yyyy.MM.dd HH:mm:ss"; |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 public static final String DEST_FORMAT = "yyyy-MM-dd HH:mm"; |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 public static DateFormat srcFormat = new SimpleDateFormat(SRC_FORMAT); |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 public static DateFormat destFormat = new SimpleDateFormat(DEST_FORMAT); |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 public SimpleOdvDataCollector(String[] names) { |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 super(names); |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 } |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 public String[] getData(Result result) |
335
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
301
diff
changeset
|
34 throws StateException |
238
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 { |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 if (rd == null) |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 init(result); |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 try { |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 String [] entries = new String[names.length+1]; |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 int j = 0; |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 for (int i = 0; i < names.length; i++) { |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 if (names[i].equals("SHAPE")) { |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 Point p = (Point)wktReader.read(result.getString("SHAPE")); |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 entries[j++] = ""+p.getX(); |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 entries[j++] = ""+p.getY(); |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 } |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 // Change the datetime format from yyyy.MM.dd HH:mm:ss to |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 // yyyy-MM-dd HH:mm |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 else if (names[i].equals("TIMEVALUE")) { |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 Date source = srcFormat.parse(result.getString(names[i])); |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 entries[j++] = destFormat.format(source); |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 } |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 else { |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 entries[j++] = result.getString(names[i]); |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 } |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 } |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 return entries; |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 } |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 catch (ParseException pe) { |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 log.error(pe, pe); |
335
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
301
diff
changeset
|
65 throw new StateException( |
238
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 "Error occured while parsing source data."); |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 } |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 catch (java.text.ParseException pe) { |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 log.error(pe, pe); |
335
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
301
diff
changeset
|
70 throw new StateException( |
238
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 "Error occured while parsing source data."); |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 } |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 } |
a157c6042cb4
ODV-export for timeseries completed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 } |