[PATCH] WQSelect can now handle distance-only data

Wald Commits scm-commit at wald.intevation.org
Wed Jun 6 14:24:57 CEST 2018


# HG changeset patch
# User gernotbelger
# Date 1528287891 -7200
# Node ID 8cc192731c7dc34020bcd1af767f7782ff785e05
# Parent  0a19a79663ddbe8bac2665b1b081b5d45f366b81
WQSelect can now handle distance-only data

diff -r 0a19a79663dd -r 8cc192731c7d artifacts/src/main/java/org/dive4elements/river/artifacts/access/ComputationRangeAccess.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/access/ComputationRangeAccess.java	Wed Jun 06 14:17:18 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/access/ComputationRangeAccess.java	Wed Jun 06 14:24:51 2018 +0200
@@ -54,6 +54,26 @@
         }
     }
 
+    public final double getStartKm() {
+
+        final KM_MODE mode = getKmRangeMode();
+        switch (mode) {
+        case RANGE:
+        case DISTANCE_ONLY:
+            return getFrom();
+
+        case LOCATIONS:
+        case NONE:
+        default:
+            final double[] locations = getLocations();
+            if( locations != null && locations.length > 0 )
+                // TODO: this is the old behaviour, but what happens if the user enters the values unsorted?
+                return locations[0];
+
+            return Double.NaN;
+        }
+    }
+
     public double[] getKms() {
 
         if (isRange())
diff -r 0a19a79663dd -r 8cc192731c7d artifacts/src/main/java/org/dive4elements/river/artifacts/access/DGMAccess.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/access/DGMAccess.java	Wed Jun 06 14:17:18 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/access/DGMAccess.java	Wed Jun 06 14:24:51 2018 +0200
@@ -18,9 +18,6 @@
 
     private String geoJSON;
 
-    public DGMAccess() {
-    }
-
     public DGMAccess(D4EArtifact artifact) {
         super(artifact);
     }
diff -r 0a19a79663dd -r 8cc192731c7d artifacts/src/main/java/org/dive4elements/river/artifacts/access/RangeAccess.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/access/RangeAccess.java	Wed Jun 06 14:17:18 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/access/RangeAccess.java	Wed Jun 06 14:24:51 2018 +0200
@@ -23,49 +23,55 @@
     private static Logger log = Logger.getLogger(RangeAccess.class);
 
     public static enum KM_MODE {
-        RANGE, LOCATIONS, NONE
-    };
+        RANGE, LOCATIONS, NONE, DISTANCE_ONLY
+    }
 
     /** The default step width between the start end end kilometer. */
     public static final double DEFAULT_KM_STEPS = 0.1;
 
-    double[] kmRange;
+    private Double from;
 
-    Double from;
+    private Double to;
 
-    Double to;
-
-    Double step;
+    private Double step;
 
     private KM_MODE mode;
 
-    public RangeAccess() {
-    }
-
     public RangeAccess(final D4EArtifact artifact) {
         super(artifact);
     }
 
     /** Evaluate the ld_mode data of artifact. */
     public KM_MODE getKmRangeMode() {
-        if (this.mode != null) {
+        if (this.mode != null)
             return this.mode;
-        }
+
         final String modeData = getString("ld_mode");
-
-        if (modeData == null || modeData.length() == 0) {
-            this.mode = KM_MODE.NONE;
-        } else if (modeData.equals("distance")) {
-            this.mode = KM_MODE.RANGE;
-        } else if (modeData.equals("locations")) {
-            this.mode = KM_MODE.LOCATIONS;
-        } else {
-            this.mode = KM_MODE.NONE;
-        }
+        this.mode = parseRangeMode(modeData);
 
         return this.mode;
     }
 
+    private KM_MODE parseRangeMode(final String modeData) {
+
+        if (modeData == null)
+            return KM_MODE.NONE;
+
+        switch (modeData) {
+        case "distance":
+            return KM_MODE.RANGE;
+
+        case "distance_only":
+            return KM_MODE.DISTANCE_ONLY;
+
+        case "locations":
+            return KM_MODE.LOCATIONS;
+
+        default:
+            return KM_MODE.NONE;
+        }
+    }
+
     public final DoubleRange getRange() {
         final double from = getFrom();
         final double to = getTo();
@@ -204,9 +210,9 @@
     public double[] getKmRange() {
         // TODO store kmRange in field.
         switch (getKmRangeMode()) {
-        case RANGE: {
+        case RANGE:
+        case DISTANCE_ONLY:
             return getKmFromTo();
-        }
 
         case LOCATIONS: {
             final double[] locs = getLocations();
diff -r 0a19a79663dd -r 8cc192731c7d artifacts/src/main/java/org/dive4elements/river/artifacts/access/RiverAccess.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/access/RiverAccess.java	Wed Jun 06 14:17:18 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/access/RiverAccess.java	Wed Jun 06 14:24:51 2018 +0200
@@ -24,11 +24,7 @@
     private static Logger log = Logger.getLogger(RiverAccess.class);
 
     /** River name. */
-    protected String river;
-
-
-    public RiverAccess() {
-    }
+    private String river;
 
     public RiverAccess(D4EArtifact artifact) {
         super(artifact);
diff -r 0a19a79663dd -r 8cc192731c7d artifacts/src/main/java/org/dive4elements/river/artifacts/access/SQRelationAccess.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/access/SQRelationAccess.java	Wed Jun 06 14:17:18 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/access/SQRelationAccess.java	Wed Jun 06 14:24:51 2018 +0200
@@ -22,18 +22,15 @@
 {
     private static Logger log = Logger.getLogger(SQRelationAccess.class);
 
-    protected Double    location;
+    private Double    location;
 
-    protected DateRange period;
+    private DateRange period;
 
-    protected Double    outliers;
+    private Double    outliers;
 
     private String      method;
 
-    protected MeasurementStation measurementStation;
-
-    public SQRelationAccess() {
-    }
+    private MeasurementStation measurementStation;
 
     public SQRelationAccess(D4EArtifact artifact) {
         super(artifact);


More information about the Dive4Elements-commits mailing list