ingo@1115: /* ingo@1115: * Copyright (c) 2010 by Intevation GmbH ingo@1115: * ingo@1115: * This program is free software under the LGPL (>=v2.1) ingo@1115: * Read the file LGPL.txt coming with the software for details ingo@1115: * or visit http://www.gnu.org/licenses/ if it does not exist. ingo@1115: */ ingo@1115: tim@113: package de.intevation.gnv.statistics; tim@113: tim@823: import java.sql.SQLException; tim@823: import java.util.Collection; tim@823: tim@823: import org.apache.log4j.Logger; tim@823: sascha@779: import com.vividsolutions.jts.geom.Point; 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; tim@335: import de.intevation.gnv.state.describedata.KeyValueDescibeData; tim@255: import de.intevation.gnv.utils.DistanceCalculator; tim@113: tim@113: /** ingo@814: * This class is used to create a statistic for 'Horizontalprofil' products. sascha@835: * 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: ingo@814: 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")); ingo@814: double delta = DistanceCalculator.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: ingo@814: 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: ingo@814: 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: }