changeset 4753:a310aceb2e51

Fetch calculation range (Berechnungsstrecke) for FLYS rivers, too.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 03 Jan 2013 14:19:45 +0100
parents ce570c74aa94
children 04377ccef10a
files flys-aft/src/main/java/de/intevation/aft/IdPair.java flys-aft/src/main/java/de/intevation/aft/River.java flys-aft/src/main/java/de/intevation/aft/Rivers.java flys-aft/src/main/resources/sql/flys-common.properties
diffstat 4 files changed, 67 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/flys-aft/src/main/java/de/intevation/aft/IdPair.java	Thu Jan 03 11:43:16 2013 +0100
+++ b/flys-aft/src/main/java/de/intevation/aft/IdPair.java	Thu Jan 03 14:19:45 2013 +0100
@@ -8,8 +8,12 @@
     public IdPair() {
     }
 
+    public IdPair(int id1) {
+        this.id1 = id1;
+    }
+
     public IdPair(int id1, int id2) {
-        this.id1 = id1;
+        this(id1);
         this.id2 = id2;
     }
 
--- a/flys-aft/src/main/java/de/intevation/aft/River.java	Thu Jan 03 11:43:16 2013 +0100
+++ b/flys-aft/src/main/java/de/intevation/aft/River.java	Thu Jan 03 14:19:45 2013 +0100
@@ -20,9 +20,19 @@
 
     protected String name;
 
+    protected double from;
+    protected double to;
+
     public River() {
     }
 
+    public River(int id1, String name, double from, double to) {
+        super(id1);
+        this.name = name;
+        this.from = from;
+        this.to   = to;
+    }
+
     public River(int id1, int id2, String name) {
         super(id1, id2);
         this.name = name;
@@ -32,6 +42,25 @@
         return name;
     }
 
+    public double getFrom() {
+        return from;
+    }
+
+    public void setFrom(double from) {
+        this.from = from;
+    }
+
+    public double getTo() {
+        return to;
+    }
+
+    public void setTo(double to) {
+        this.to = to;
+    }
+
+    public boolean inside(double x) {
+        return x >= from && x <= to;
+    }
 
     public boolean sync(SyncContext context) throws SQLException {
         log.info("sync river: " + this);
--- a/flys-aft/src/main/java/de/intevation/aft/Rivers.java	Thu Jan 03 11:43:16 2013 +0100
+++ b/flys-aft/src/main/java/de/intevation/aft/Rivers.java	Thu Jan 03 14:19:45 2013 +0100
@@ -27,35 +27,44 @@
         ConnectedStatements flysStatements = context.getFlysStatements();
         ConnectedStatements aftStatements  = context.getAftStatements();
 
-        Map<String, Integer> flysRivers = new HashMap<String, Integer>();
+        Map<String, River> flysRivers = new HashMap<String, River>();
 
         ResultSet flysRs = flysStatements
-            .getStatement("select.river").executeQuery();
+            .getStatement("select.rivers").executeQuery();
 
-        while (flysRs.next()) {
-            Integer id   = flysRs.getInt("id");
-            String  name = flysRs.getString("name").toLowerCase();
-            flysRivers.put(name, id);
+        try {
+            while (flysRs.next()) {
+                int    id   = flysRs.getInt("id");
+                String name = flysRs.getString("name");
+                double from = flysRs.getDouble("min_km");
+                double to   = flysRs.getDouble("max_km");
+                flysRivers.put(name.toLowerCase(), new River(id, name, from, to));
+            }
         }
-
-        flysRs.close();
+        finally {
+            flysRs.close();
+        }
 
         List<River> commonRivers = new ArrayList<River>();
 
         ResultSet aftRs = aftStatements
             .getStatement("select.gewaesser").executeQuery();
 
-        while (aftRs.next()) {
-            String name = aftRs.getString("NAME");
-            Integer id1 = flysRivers.get(name.toLowerCase());
-            if (id1 != null) {
-                int id2 = aftRs.getInt("GEWAESSER_NR");
-                River river = new River(id1, id2, name);
-                commonRivers.add(river);
+        try {
+            while (aftRs.next()) {
+                String name = aftRs.getString("NAME");
+                River river = flysRivers.get(name.toLowerCase());
+                if (river != null) {
+                    int id2 = aftRs.getInt("GEWAESSER_NR");
+                    river.setId2(id2);
+                    commonRivers.add(river);
+                }
             }
         }
+        finally {
+            aftRs.close();
+        }
 
-        aftRs.close();
 
         boolean modified = false;
 
--- a/flys-aft/src/main/resources/sql/flys-common.properties	Thu Jan 03 11:43:16 2013 +0100
+++ b/flys-aft/src/main/resources/sql/flys-common.properties	Thu Jan 03 14:19:45 2013 +0100
@@ -1,4 +1,11 @@
-select.river = SELECT id, name FROM rivers 
+select.rivers = \
+    SELECT r.id AS id, r.name AS name, min(wcv.position) AS min_km, max(wcv.position) AS max_km \
+    FROM rivers r \
+        JOIN wsts w ON r.id = w.river_id \
+        JOIN wst_columns wc ON w.id = wc.wst_id \
+        JOIN wst_column_values wcv ON wcv.wst_column_id = wc.id \
+    WHERE w.kind = 0 \
+    GROUP BY r.id, r.name
 select.gauges = SELECT id, name, official_number FROM gauges WHERE river_id = :river_id
 next.gauge.id = SELECT NEXTVAL('GAUGES_ID_SEQ') AS gauge_id
 insert.gauge = INSERT INTO gauges (id, name, river_id, station, aeo, official_number, datum) \

http://dive4elements.wald.intevation.org