changeset 8386:a9d493aba926

Try to determine gauge by km in gauge discharge facet for exporter.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 07 Oct 2014 13:41:54 +0200
parents 24d3370af00b
children 8c60595fd74c
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/GaugeDischargeCurveFacet.java
diffstat 1 files changed, 18 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/GaugeDischargeCurveFacet.java	Tue Oct 07 11:24:13 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/GaugeDischargeCurveFacet.java	Tue Oct 07 13:41:54 2014 +0200
@@ -17,7 +17,7 @@
 import org.dive4elements.artifactdatabase.state.Facet;
 
 import org.dive4elements.river.artifacts.D4EArtifact;
-
+import org.dive4elements.river.artifacts.access.RangeAccess;
 import org.dive4elements.river.model.Gauge;
 
 import org.dive4elements.river.utils.RiverUtils;
@@ -25,6 +25,7 @@
 import org.apache.log4j.Logger;
 
 import static org.dive4elements.river.exports.injector.InjectorConstants.PNP;
+import static org.dive4elements.river.exports.injector.InjectorConstants.GAUGE_EPSILON;
 
 /**
  * A Facet that returns discharge curve data at a gauge
@@ -82,10 +83,24 @@
 
         Object pnpObject = context.getContextValue(PNP);
         if (!(pnpObject instanceof Number)) {
+            RangeAccess access = new RangeAccess(flys);
+            double km = Double.NaN;
+            if (access.getLocations() != null &&
+                access.getLocations().length > 0) {
+                km = access.getLocations()[0];
+            }
+            Gauge g = access.getRiver().determineGaugeByStation(
+                    km - GAUGE_EPSILON,
+                    km + GAUGE_EPSILON);
+            if (g != null) {
+                return new WQKms(
+                    kms,
+                    values[0],
+                    transformToM(values[1], g.getDatum().doubleValue()));
+            }
             return new WQKms(kms, values[0], values[1], name);
         }
-        double pnp = ((Number)pnpObject).doubleValue();
-        double[] ws = transformToM(values[1], pnp);
+        double[] ws = transformToM(values[1], ((Number)pnpObject).doubleValue());
 
         return new WQKms(kms, values[0], ws, name);
     }

http://dive4elements.wald.intevation.org