Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 383:dcc3cd962c0e
Enhanced the transition model to reach a state that creates duration curves.
flys-artifacts/trunk@1799 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 02 May 2011 16:58:04 +0000 |
parents | c21fb8de54f8 |
children | 435058da0eae |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Mon May 02 16:50:58 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Mon May 02 16:58:04 2011 +0000 @@ -470,14 +470,72 @@ * @return the selected distance or points. */ public double[] getDistance() { - StateData dFrom = getData("ld_from"); - StateData dTo = getData("ld_to"); + StateData dFrom = getData("ld_from"); + StateData dTo = getData("ld_to"); + StateData dLocations = getData("ld_locations"); + if (dFrom != null && dTo != null) { + return getDistanceByRange(dFrom, dTo); + } + else if (dLocations != null) { + double[] locations = getLocations(); + return new double[] { locations[0], locations[locations.length-1] }; + } + + logger.warn("No data found for distance determination!"); + + return null; + } + + + /** + * Returns the selected locations based on a given array of locations. + * + * @param locations The StateData that contains the locations. + * + * @return the selected locations. + */ + public double[] getLocations() { + StateData dLocations = getData("ld_locations"); + String locationStr = dLocations != null + ? (String) dLocations.getValue() + : ""; + + if (locationStr == null || locationStr.length() == 0) { + logger.warn("No valid location string found!"); + return null; + } + + String[] tmp = locationStr.split(" "); + TDoubleArrayList locations = new TDoubleArrayList(); + + for (String l: tmp) { + try { + locations.add(Double.parseDouble(l)); + } + catch (NumberFormatException nfe) { + logger.warn(nfe, nfe); + } + } + + locations.sort(); + + return locations.toNativeArray(); + } + + + /** + * Returns the selected distance based on a given range (from, to). + * + * @param dFrom The StateData that contains the lower value. + * @param dTo The StateData that contains the upper value. + * + * @return the selected distance. + */ + protected double[] getDistanceByRange(StateData dFrom, StateData dTo) { double from = Double.parseDouble((String) dFrom.getValue()); double to = Double.parseDouble((String) dTo.getValue()); - // TODO take point selection into account - return new double[] { from, to }; }