tim@113: package de.intevation.gnv.statistics;
tim@113:
sascha@779: import com.vividsolutions.jts.geom.Point;
tim@113:
tim@255: import com.vividsolutions.jts.io.ParseException;
tim@255: import com.vividsolutions.jts.io.WKTReader;
tim@255:
tim@113: import de.intevation.gnv.geobackend.base.Result;
sascha@779:
tim@335: import de.intevation.gnv.state.describedata.KeyValueDescibeData;
sascha@779:
tim@255: import de.intevation.gnv.utils.DistanceCalculator;
tim@113:
sascha@779: import java.sql.SQLException;
sascha@779:
sascha@779: import java.util.Collection;
sascha@779:
sascha@779: import org.apache.log4j.Logger;
sascha@779:
tim@113: /**
sascha@780: * @author Tim Englich
sascha@778: *
tim@113: */
tim@113: public class HorizontalProfileStatistics extends TimeseriesStatistics {
sascha@778:
tim@255: private static Logger log = Logger.getLogger(HorizontalProfileStatistics.class);
tim@113:
tim@255: private WKTReader wktReader = new WKTReader();
sascha@778:
tim@255: private DistanceCalculator dc = new DistanceCalculator();
sascha@778:
tim@255: private double distance = 0;
sascha@778:
tim@113: /**
tim@113: * Constructor
tim@113: */
tim@113: public HorizontalProfileStatistics() {
tim@113: super();
tim@113: }
tim@171:
tim@255: /**
tim@255: * @see de.intevation.gnv.statistics.TimeseriesStatistics#calculateXOrdinateValue(de.intevation.gnv.geobackend.base.Result, de.intevation.gnv.geobackend.base.Result)
tim@255: */
tim@113: @Override
tim@255: protected double calculateXOrdinateValue(Result previousRow,Result row)
tim@255: throws SQLException {
tim@255: try {
tim@255: Point start = (Point)this.wktReader.read(previousRow.getString("SHAPE"));
tim@255: Point current = (Point)this.wktReader.read(row.getString("SHAPE"));
tim@255: double delta = this.dc.calculateDistance(start, current);
sascha@778:
tim@255: if (!Double.isNaN(delta)){
tim@255: this.distance = this.distance + delta;
tim@255: }
tim@255: } catch (ParseException e) {
tim@255: log.error(e,e);
tim@255: }
tim@255: return this.distance;
tim@113: }
tim@253:
tim@255: /**
tim@255: * @see de.intevation.gnv.statistics.TimeseriesStatistics#generateStatisticsName(java.lang.String, java.lang.String, java.lang.String, java.util.Collection, java.util.Collection, java.util.Collection)
tim@255: */
tim@253: @Override
tim@253: protected String generateStatisticsName(
tim@253: String break1,
tim@253: String break2,
tim@253: String break3,
tim@253: Collection parameters,
tim@253: Collection measurements,
tim@253: Collection dates) {
sascha@778: return (this.findValueTitle(parameters, break1)+ " "+
tim@253: this.findValueTitle(measurements,break2)).trim()+" "+
tim@253: this.findValueTitle(dates,break3);
tim@253: }
sascha@778:
tim@255: /**
tim@255: * @see de.intevation.gnv.statistics.TimeseriesStatistics#clearStatistics()
tim@255: */
tim@255: @Override
tim@255: protected void clearStatistics() {
tim@255: log.debug("HorizontalProfileStatistics.clearStatistics");
tim@255: super.clearStatistics();
tim@255: this.distance = 0;
tim@255: }
tim@253:
tim@113: }