[Dive4elements-commits] [PATCH 2 of 2] Add support for multiple floodplains and add them to the datacage accordingly

Wald Commits scm-commit at wald.intevation.org
Thu Mar 28 12:39:18 CET 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1364470754 -3600
# Node ID 23d8f2700b383baf1eab10ee916b91d6e514481c
# Parent  1488227b97b7ef4e9f059b1de1a5813151cb87f3
Add support for multiple floodplains and add them to the datacage accordingly

diff -r 1488227b97b7 -r 23d8f2700b38 flys-artifacts/doc/conf/meta-data.xml
--- a/flys-artifacts/doc/conf/meta-data.xml	Thu Mar 28 12:38:06 2013 +0100
+++ b/flys-artifacts/doc/conf/meta-data.xml	Thu Mar 28 12:39:14 2013 +0100
@@ -1321,17 +1321,42 @@
             <dc:macro name="flood-map-floodplain">
               <dc:context>
                 <dc:statement>
-                  SELECT count(*) as km_exists
-                  FROM floodplain WHERE river_id = ${river_id}
+                  SELECT DISTINCT
+                  fp.kind_id as kind_id,
+                  flk.name as kind_name
+                  FROM floodplain fp
+                  JOIN floodplain_kinds flk on fp.kind_id = flk.id
+                  WHERE river_id = ${river_id}
+                  AND kind_id=1
                 </dc:statement>
-                 <dc:elements>
-                  <dc:if test="$km_exists>0">
-                    <floodplain>
-                      <dc:attribute name="factory" value="wmsfloodplainfactory"/>
-                      <dc:attribute name="ids" value="${river_id}"/>
-                    </floodplain>
-                  </dc:if>
-                </dc:elements>
+                <dc:if test="dc:has-result()">
+                  <dc:elements>
+                    <floody factory="wmsfloodplainfactory"
+                      description="{$kind_name}"
+                      ids="{$river_id};{$kind_name};{$kind_id}"/>
+                  </dc:elements>
+                </dc:if>
+              </dc:context>
+              <dc:context>
+                <dc:statement>
+                  SELECT DISTINCT
+                  flk.name as kind_name,
+                  fp.kind_id as kind_id,
+                  fp.name as layer_name
+                  FROM floodplain fp
+                  JOIN floodplain_kinds flk on fp.kind_id = flk.id
+                  WHERE river_id = ${river_id}
+                  AND kind_id <> 1
+                </dc:statement>
+                <dc:if test="dc:has-result()">
+                  <other>
+                    <dc:elements>
+                      <floody factory="wmsfloodplainfactory"
+                        description="{$layer_name}"
+                        ids="{$river_id};{$layer_name};{$kind_id}"/>
+                    </dc:elements>
+                  </other>
+                </dc:if>
               </dc:context>
             </dc:macro>
 
@@ -1809,8 +1834,8 @@
                   <dc:call-macro name="flood-map-routing"/>
                 </route_data>
                 <hydrboundaries>
+                  <dc:call-macro name="flood-map-floodplain"/>
                   <dc:call-macro name="flood-map-hydr-boundaries"/>
-                  <dc:call-macro name="flood-map-floodplain"/>
                 </hydrboundaries>
                 <dc:call-macro name="flood-map-uesk"/>
                 <gaugelocations>
diff -r 1488227b97b7 -r 23d8f2700b38 flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSFloodplainArtifact.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSFloodplainArtifact.java	Thu Mar 28 12:38:06 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSFloodplainArtifact.java	Thu Mar 28 12:39:14 2013 +0100
@@ -84,21 +84,6 @@
             riverId = 0;
         }
 
-        public int getRiverId() {
-            if (riverId == 0) {
-                String ids = artifact.getDataAsString("ids");
-
-                try {
-                    riverId = Integer.parseInt(ids);
-                }
-                catch (NumberFormatException nfe) {
-                    logger.error("Cannot parse river id from '" + ids + "'");
-                }
-            }
-
-            return riverId;
-        }
-
         protected River getRiver() {
             return RiverFactory.getRiver(getRiverId());
         }
@@ -121,19 +106,46 @@
 
         @Override
         protected Envelope getExtent(boolean reproject) {
-            River      river = getRiver();
-            Floodplain plain = Floodplain.getFloodplain(river.getName());
+            River river = getRiver();
+            List<Floodplain> fps;
 
-            Envelope e = plain.getGeom().getEnvelopeInternal();
+            String kind = getIdPart(2);
 
-            return e != null && reproject
-                ? GeometryUtils.transform(e, getSrid())
-                : e;
+            if (kind != null && ! kind.equals("1")) {
+                fps = Floodplain.getFloodplains(river.getName(),
+                        getName(), Integer.parseInt(kind));
+            } else {
+                fps = Floodplain.getFloodplains(river.getName(), 1);
+            }
+
+            Envelope max = null;
+
+            for (Floodplain fp: fps) {
+                Envelope env = fp.getGeom().getEnvelopeInternal();
+
+                if (max == null) {
+                    max = env;
+                    continue;
+                }
+
+                max.expandToInclude(env);
+            }
+
+            return max != null && reproject
+                ? GeometryUtils.transform(max, getSrid())
+                : max;
         }
 
         @Override
         protected String getFilter() {
-            return "river_id=" + String.valueOf(getRiverId());
+            String kind = getIdPart(2);
+            if (kind != null && ! kind.equals("1")) {
+                return "river_id=" + String.valueOf(getRiverId()) +
+                    " AND kind_id=" + kind +
+                    " AND name='" + getName() + "'";
+            }
+            return "river_id=" + String.valueOf(getRiverId()) +
+                    " AND kind_id=1";
         }
 
         @Override
diff -r 1488227b97b7 -r 23d8f2700b38 flys-backend/src/main/java/de/intevation/flys/model/Floodplain.java
--- a/flys-backend/src/main/java/de/intevation/flys/model/Floodplain.java	Thu Mar 28 12:38:06 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/model/Floodplain.java	Thu Mar 28 12:39:14 2013 +0100
@@ -13,6 +13,7 @@
 import org.hibernate.Query;
 import org.hibernate.Session;
 import org.hibernate.annotations.Type;
+import org.hibernate.HibernateException;
 
 import com.vividsolutions.jts.geom.Polygon;
 
@@ -32,6 +33,8 @@
 
     private Polygon        geom;
 
+    private String         name;
+
 
     public Floodplain() {
     }
@@ -77,6 +80,42 @@
         this.geom = geom;
     }
 
+    @Column(name = "name")
+    public String getName() {
+        return name;
+    }
+
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public static List<Floodplain> getFloodplains(String river, String name, int kind)
+    throws HibernateException {
+        Session session = SessionHolder.HOLDER.get();
+        Query query = session.createQuery(
+            "from Floodplain as fp where river.name =:river" +
+            " and kind.id =:kind" +
+            " and fp.name=:name");
+        query.setParameter("river", river);
+        query.setParameter("kind", kind);
+        query.setParameter("name", name);
+
+        List<Floodplain> list = query.list();
+        return list.isEmpty() ? null : list;
+    }
+
+    public static List<Floodplain> getFloodplains(String river, int kind)
+    throws HibernateException {
+        Session session = SessionHolder.HOLDER.get();
+        Query query = session.createQuery(
+            "from Floodplain where river.name =:river AND kind.id =:kind");
+        query.setParameter("river", river);
+        query.setParameter("kind", kind);
+
+        List<Floodplain> list = query.list();
+        return list.isEmpty() ? null : list;
+    }
 
     public static Floodplain getFloodplain(String river) {
         Session session = SessionHolder.HOLDER.get();


More information about the Dive4elements-commits mailing list