# HG changeset patch # User Andre Heinecke # 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 @@ - 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 - - - - - - - - + + + + + + + + + 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 + + + + + + + + @@ -1809,8 +1834,8 @@ + - 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 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 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 list = query.list(); + return list.isEmpty() ? null : list; + } + + public static List 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 list = query.list(); + return list.isEmpty() ? null : list; + } public static Floodplain getFloodplain(String river) { Session session = SessionHolder.HOLDER.get();