changeset 5170:c1b60f8c3390

Made river mapfile generator more tolerant. * Ignores missing river axes. * Ignores invalid river axes. * Ignores invalid geometries.
author Raimund Renkert <rrenkert@intevation.de>
date Mon, 04 Mar 2013 17:11:31 +0100
parents db1a000a21a9
children f52bb7178eda
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java flys-artifacts/src/main/java/de/intevation/flys/utils/RiverMapfileGenerator.java flys-backend/src/main/java/de/intevation/flys/backend/SpatialInfo.java flys-backend/src/main/java/de/intevation/flys/model/RiverAxis.java
diffstat 5 files changed, 66 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Mon Mar 04 17:08:14 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Mon Mar 04 17:11:31 2013 +0100
@@ -616,8 +616,14 @@
         String river = artifact.getDataAsString("river");
         String srid    = FLYSUtils.getRiverDGMSrid(river);
         String srs     = "EPSG:" + srid;
-logger.debug("srs: " + srs);
-        List<RiverAxis> axes = RiverAxis.getRiverAxis(river);
+
+        List<RiverAxis> axes = null;
+        try {
+            axes = RiverAxis.getRiverAxis(river);
+        }
+        catch (RuntimeException e) {
+            return;
+        }
         if (axes == null || axes.isEmpty()) {
             logger.warn("Could not find river axis for: '" + river + "'");
             return;
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java	Mon Mar 04 17:08:14 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java	Mon Mar 04 17:11:31 2013 +0100
@@ -50,24 +50,29 @@
     }
 
     public static Envelope getRiverBoundary(String rivername) {
-        List<RiverAxis> axes = RiverAxis.getRiverAxis(rivername);
-        if (axes != null && axes.size() > 0) {
-            Envelope max = null;
-
-            for (RiverAxis axis: axes) {
-                // TODO Take the correct EPSG into account. Maybe, we need to
-                // reproject the geometry.
-                Envelope env = axis.getGeom().getEnvelopeInternal();
+        try {
+            List<RiverAxis> axes = RiverAxis.getRiverAxis(rivername);
+            if (axes != null && axes.size() > 0) {
+                Envelope max = null;
 
-                if (max == null) {
-                    max = env;
+                for (RiverAxis axis: axes) {
+                    // TODO Take the correct EPSG into account. Maybe, we need to
+                    // reproject the geometry.
+                    Envelope env = axis.getGeom().getEnvelopeInternal();
+
+                    if (max == null) {
+                        max = env;
+                    }
+                    else {
+                        max.expandToInclude(env);
+                    }
                 }
-                else {
-                    max.expandToInclude(env);
-                }
+
+                return max;
             }
-
-            return max;
+        }
+        catch(RuntimeException e) {
+            return null;
         }
 
         return null;
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/RiverMapfileGenerator.java	Mon Mar 04 17:08:14 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/RiverMapfileGenerator.java	Mon Mar 04 17:11:31 2013 +0100
@@ -66,11 +66,24 @@
             // We expect that every river has only one RiverAxis.
             // This is not correct but currently the case here, see
             // RiverAxis.java.
-            List<RiverAxis> riverAxis = RiverAxis.getRiverAxis(river.getName());
+            List<RiverAxis> riverAxis = null;
+            try {
+                riverAxis = RiverAxis.getRiverAxis(river.getName());
+            }
+            catch (RuntimeException he) {
+                logger.error("No valid riveraxis found for " + river.getName());
+                continue;
+            }
+
             if (riverAxis == null) {
                 logger.warn("River " + river.getName() + " has no river axis!");
                 continue;
             }
+            if (riverAxis.get(0).getGeom() == null) {
+                logger.warn("River " + river.getName() +
+                    " has no riveraxis geometry!");
+                continue;
+            }
             MultiLineString geom = riverAxis.get(0).getGeom();
             Envelope extent = geom.getEnvelopeInternal();
 
--- a/flys-backend/src/main/java/de/intevation/flys/backend/SpatialInfo.java	Mon Mar 04 17:08:14 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/backend/SpatialInfo.java	Mon Mar 04 17:11:31 2013 +0100
@@ -84,13 +84,19 @@
 
 
     protected void doRiverAxisInfo(River river) {
-        List<RiverAxis> axis = RiverAxis.getRiverAxis(river.getName());
-        if (axis != null && axis.size() > 0) {
-            logger.debug("TODO: Compute length and boundary.");
+        try {
+            List<RiverAxis> axis = RiverAxis.getRiverAxis(river.getName());
+            if (axis != null && axis.size() > 0) {
+                logger.debug("TODO: Compute length and boundary.");
+            }
+            else {
+                logger.warn("River has no RiverAxis.");
+            }
         }
-        else {
-            logger.warn("River has no RiverAxis.");
+        catch(RuntimeException e) {
+            return;
         }
+ 
     }
 
 
--- a/flys-backend/src/main/java/de/intevation/flys/model/RiverAxis.java	Mon Mar 04 17:08:14 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/model/RiverAxis.java	Mon Mar 04 17:11:31 2013 +0100
@@ -10,6 +10,7 @@
 import javax.persistence.OneToOne;
 import javax.persistence.Table;
 
+import org.hibernate.HibernateException;
 import org.hibernate.Session;
 import org.hibernate.Query;
 import org.hibernate.annotations.Type;
@@ -100,21 +101,28 @@
     }
 
 
-    public static List<RiverAxis> getRiverAxis(String river) {
+    public static List<RiverAxis> getRiverAxis(String river)
+    throws RuntimeException {
         return getRiverAxis(river, KIND_CURRENT);
     }
 
-    public static List<RiverAxis> getRiverAxis(String river, int kind) {
+    public static List<RiverAxis> getRiverAxis(String river, int kind)
+    throws RuntimeException {
         Session session = SessionHolder.HOLDER.get();
-
         Query query = session.createQuery(
             "from RiverAxis where river.name =:river AND kind.id =:kind");
         query.setParameter("river", river);
         query.setParameter("kind", kind);
 
-        List<RiverAxis> list = query.list();
+        try {
+            List<RiverAxis> list = query.list();
+            return list.isEmpty() ? null : list;
+        }
+        catch (RuntimeException re) {
+            throw iae;
+        }
 
-        return list.isEmpty() ? null : list;
+
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org