comparison gnv-artifacts/src/main/java/de/intevation/gnv/statistics/HorizontalProfileStatistics.java @ 1119:7c4f81f74c47

merged gnv-artifacts
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:00 +0200
parents f953c9a559d8
children
comparison
equal deleted inserted replaced
1027:fca4b5eb8d2f 1119:7c4f81f74c47
1 /*
2 * Copyright (c) 2010 by Intevation GmbH
3 *
4 * This program is free software under the LGPL (>=v2.1)
5 * Read the file LGPL.txt coming with the software for details
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
7 */
8
9 package de.intevation.gnv.statistics;
10
11 import java.sql.SQLException;
12 import java.util.Collection;
13
14 import org.apache.log4j.Logger;
15
16 import com.vividsolutions.jts.geom.Point;
17 import com.vividsolutions.jts.io.ParseException;
18 import com.vividsolutions.jts.io.WKTReader;
19
20 import de.intevation.gnv.geobackend.base.Result;
21 import de.intevation.gnv.state.describedata.KeyValueDescibeData;
22 import de.intevation.gnv.utils.DistanceCalculator;
23
24 /**
25 * This class is used to create a statistic for 'Horizontalprofil' products.
26 *
27 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
28 *
29 */
30 public class HorizontalProfileStatistics extends TimeseriesStatistics {
31
32 private static Logger log = Logger.getLogger(HorizontalProfileStatistics.class);
33
34 private WKTReader wktReader = new WKTReader();
35
36 private DistanceCalculator dc = new DistanceCalculator();
37
38 private double distance = 0;
39
40 /**
41 * Constructor
42 */
43 public HorizontalProfileStatistics() {
44 super();
45 }
46
47
48 @Override
49 protected double calculateXOrdinateValue(Result previousRow,Result row)
50 throws SQLException {
51 try {
52 Point start = (Point)this.wktReader.read(previousRow.getString("SHAPE"));
53 Point current = (Point)this.wktReader.read(row.getString("SHAPE"));
54 double delta = DistanceCalculator.calculateDistance(start, current);
55
56 if (!Double.isNaN(delta)){
57 this.distance = this.distance + delta;
58 }
59 } catch (ParseException e) {
60 log.error(e,e);
61 }
62 return this.distance;
63 }
64
65
66 @Override
67 protected String generateStatisticsName(
68 String break1,
69 String break2,
70 String break3,
71 Collection<KeyValueDescibeData> parameters,
72 Collection<KeyValueDescibeData> measurements,
73 Collection<KeyValueDescibeData> dates) {
74 return (this.findValueTitle(parameters, break1)+ " "+
75 this.findValueTitle(measurements,break2)).trim()+" "+
76 this.findValueTitle(dates,break3);
77 }
78
79
80 @Override
81 protected void clearStatistics() {
82 log.debug("HorizontalProfileStatistics.clearStatistics");
83 super.clearStatistics();
84 this.distance = 0;
85 }
86
87 }

http://dive4elements.wald.intevation.org