Mercurial > dive4elements > river
changeset 8747:e9d912c97fa8
We expect that every river has only one RiverAxis of kind 1
This allowed to reduce code duplication and some cleanups.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 05 Jun 2015 16:56:47 +0200 |
parents | e701ef544ffa |
children | 36d7bda0b47a |
files | artifacts/src/main/java/org/dive4elements/river/artifacts/RiverAxisArtifact.java artifacts/src/main/java/org/dive4elements/river/artifacts/states/FloodMapState.java artifacts/src/main/java/org/dive4elements/river/utils/GeometryUtils.java artifacts/src/main/java/org/dive4elements/river/utils/MapfileGenerator.java artifacts/src/main/java/org/dive4elements/river/utils/RiverMapfileGenerator.java backend/src/main/java/org/dive4elements/river/model/RiverAxis.java |
diffstat | 6 files changed, 35 insertions(+), 60 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/RiverAxisArtifact.java Fri Jun 05 16:53:07 2015 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/RiverAxisArtifact.java Fri Jun 05 16:56:47 2015 +0200 @@ -113,10 +113,7 @@ String kind = getIdPart(2); - if (kind != null && kind.equals("1")) { - axes = RiverAxis.getRiverAxis(river.getName(), - Integer.parseInt(kind)); - } else if (kind != null) { + if (kind != null && !kind.equals(RiverAxis.KIND_CURRENT)) { axes = RiverAxis.getRiverAxis(river.getName(), getName(), Integer.parseInt(kind)); } else { @@ -125,11 +122,8 @@ return GeometryUtils.transform( GeometryUtils.getRiverBoundary(river.getName()), getSrid()); - } else { - return GeometryUtils.transform( - GeometryUtils.getRiverBoundary(river.getName()), - "31467"); } + return GeometryUtils.getRiverBoundary(river.getName()); } Envelope max = null; @@ -153,14 +147,16 @@ @Override protected String getFilter() { String kind = getIdPart(2); - if (kind != null && kind.equals("1")) { + if (kind != null && kind.equals(RiverAxis.KIND_CURRENT)) { return "river_id=" + String.valueOf(getRiverId()) + " AND kind_id=" + kind; - } else if (kind != null) { + } + if (kind != null) { return "river_id=" + String.valueOf(getRiverId()) + " AND kind_id=" + kind + " AND name='" + getName() + "'"; - } else if (getIdPart(1) != null) { + } + if (getIdPart(1) != null) { return "river_id=" + String.valueOf(getRiverId()) + " AND name='" + getName() + "'"; } @@ -173,9 +169,7 @@ if (RiverUtils.isUsingOracle()) { return "geom FROM river_axes USING SRID " + getSrid(); } - else { - return "geom FROM river_axes USING UNIQUE id"; - } + return "geom FROM river_axes USING UNIQUE id"; } @Override
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/FloodMapState.java Fri Jun 05 16:53:07 2015 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/FloodMapState.java Fri Jun 05 16:56:47 2015 +0200 @@ -787,15 +787,15 @@ String srid = String.valueOf(access.getDGM().getSrid()); String srs = "EPSG:" + srid; - List<RiverAxis> axes = null; + RiverAxis axis = null; try { - axes = RiverAxis.getRiverAxis(river); + axis = RiverAxis.getRiverAxis(river); } catch (HibernateException iae) { log.warn("No valid river axis found for " + river); return; } - if (axes == null || axes.isEmpty()) { + if (axis == null) { log.warn("Could not find river axis for: '" + river + "'"); return; } @@ -806,14 +806,8 @@ SimpleFeatureBuilder builder = new SimpleFeatureBuilder(ft); FeatureCollection collection = FeatureCollections.newCollection(); - for (int i = 0, n = axes.size(); i < n; i++) { - RiverAxis axis = axes.get(i); - - builder.add(axis.getGeom()); - collection.add(builder.buildFeature(String.valueOf(i))); - - builder.reset(); - } + builder.add(axis.getGeom()); + collection.add(builder.buildFeature("0")); File axisShape = new File(dir, WSPLGEN_AXIS);
--- a/artifacts/src/main/java/org/dive4elements/river/utils/GeometryUtils.java Fri Jun 05 16:53:07 2015 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/utils/GeometryUtils.java Fri Jun 05 16:56:47 2015 +0200 @@ -60,24 +60,9 @@ public static Envelope getRiverBoundary(String rivername) { try { - 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(); - - if (max == null) { - max = env; - } - else { - max.expandToInclude(env); - } - } - - return max; + RiverAxis axis = RiverAxis.getRiverAxis(rivername); + if (axis != null) { + return axis.getGeom().getEnvelopeInternal(); } } catch(HibernateException iae) {
--- a/artifacts/src/main/java/org/dive4elements/river/utils/MapfileGenerator.java Fri Jun 05 16:53:07 2015 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/utils/MapfileGenerator.java Fri Jun 05 16:56:47 2015 +0200 @@ -282,10 +282,9 @@ /** * Creates a layer snippet which might be included in the mapfile. * - * @param layerinfo A LayerInfo object that contains all necessary + * @param layerInfo A LayerInfo object that contains all necessary * information to build a Mapserver LAYER section. - * @param dir The base dir for the LAYER snippet. - * @param filename The name of the file that is written. + * @param layerFile The file that is written. * @param tpl The Velocity template which is used to create the LAYER * section. */
--- a/artifacts/src/main/java/org/dive4elements/river/utils/RiverMapfileGenerator.java Fri Jun 05 16:53:07 2015 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/utils/RiverMapfileGenerator.java Fri Jun 05 16:56:47 2015 +0200 @@ -69,10 +69,7 @@ List<String> riverFiles = new ArrayList<String>(); for (River river : rivers) { - // We expect that every river has only one RiverAxis. - // This is not correct but currently the case here, see - // RiverAxis.java. - List<RiverAxis> riverAxis = null; + RiverAxis riverAxis = null; try { riverAxis = RiverAxis.getRiverAxis(river.getName()); } @@ -85,12 +82,12 @@ log.warn("River " + river.getName() + " has no river axis!"); continue; } - if (riverAxis.get(0).getGeom() == null) { + if (riverAxis.getGeom() == null) { log.warn("River " + river.getName() + " has no riveraxis geometry!"); continue; } - MultiLineString geom = riverAxis.get(0).getGeom(); + MultiLineString geom = riverAxis.getGeom(); Envelope extent = geom.getEnvelopeInternal(); createRiverAxisLayer(
--- a/backend/src/main/java/org/dive4elements/river/model/RiverAxis.java Fri Jun 05 16:53:07 2015 +0200 +++ b/backend/src/main/java/org/dive4elements/river/model/RiverAxis.java Fri Jun 05 16:56:47 2015 +0200 @@ -29,6 +29,8 @@ import org.hibernate.annotations.Type; +import org.apache.log4j.Logger; + /** * A river has one axis that is used for calculation. * Additional axes of a river can be used to be painted int maps etc. @@ -39,6 +41,8 @@ public class RiverAxis implements Serializable { + private static Logger log = Logger.getLogger(RiverAxis.class); + private Integer id; private AxisKind kind; private River river; @@ -119,11 +123,6 @@ } - public static List<RiverAxis> getRiverAxis(String river) - throws IllegalArgumentException { - return getRiverAxis(river, KIND_CURRENT); - } - public static List<RiverAxis> getRiverAxis(String river, String name, int kind) throws HibernateException { Session session = SessionHolder.HOLDER.get(); @@ -139,16 +138,23 @@ return list.isEmpty() ? null : list; } - public static List<RiverAxis> getRiverAxis(String river, int kind) + public static RiverAxis getRiverAxis(String river) throws HibernateException { 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); + query.setParameter("kind", KIND_CURRENT); List<RiverAxis> list = query.list(); - return list.isEmpty() ? null : list; + + /* We expect that every river has only one RiverAxis of kind 1 + thow this is not currently enforced in database schema. */ + if (list.size() > 1) { + log.error("River " + river + " has more than one current axis."); + } + + return list.isEmpty() ? null : list.get(0); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :