# HG changeset patch # User Raimund Renkert # Date 1362413491 -3600 # Node ID c1b60f8c3390a20c90a2e8a1115e51ab71c8d06a # Parent db1a000a21a9d2eb98218c4068d5383631d278ce Made river mapfile generator more tolerant. * Ignores missing river axes. * Ignores invalid river axes. * Ignores invalid geometries. diff -r db1a000a21a9 -r c1b60f8c3390 flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java --- 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 axes = RiverAxis.getRiverAxis(river); + + List 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; diff -r db1a000a21a9 -r c1b60f8c3390 flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java --- 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 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 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; diff -r db1a000a21a9 -r c1b60f8c3390 flys-artifacts/src/main/java/de/intevation/flys/utils/RiverMapfileGenerator.java --- 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.getRiverAxis(river.getName()); + List 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(); diff -r db1a000a21a9 -r c1b60f8c3390 flys-backend/src/main/java/de/intevation/flys/backend/SpatialInfo.java --- 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 axis = RiverAxis.getRiverAxis(river.getName()); - if (axis != null && axis.size() > 0) { - logger.debug("TODO: Compute length and boundary."); + try { + List 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; } + } diff -r db1a000a21a9 -r c1b60f8c3390 flys-backend/src/main/java/de/intevation/flys/model/RiverAxis.java --- 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 getRiverAxis(String river) { + public static List getRiverAxis(String river) + throws RuntimeException { return getRiverAxis(river, KIND_CURRENT); } - public static List getRiverAxis(String river, int kind) { + public static List 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 list = query.list(); + try { + List 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 :