Mercurial > dive4elements > river
changeset 9563:3955ecc1a516
Restrict inundation map to selected river range
author | gernotbelger |
---|---|
date | Mon, 29 Oct 2018 17:57:30 +0100 |
parents | 2b1626fa4a95 |
children | 1f6fbbe88af8 |
files | artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationState.java backend/src/main/java/org/dive4elements/river/model/RiverAxisKm.java |
diffstat | 2 files changed, 79 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationState.java Thu Oct 25 17:11:59 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationState.java Mon Oct 29 17:57:30 2018 +0100 @@ -24,6 +24,10 @@ import org.dive4elements.river.artifacts.model.map.WMSLayerFacet; import org.dive4elements.river.artifacts.uinfo.UINFOArtifact; import org.dive4elements.river.artifacts.uinfo.inundationduration.InundationDurationCalculationResult.WmsLayer; +import org.dive4elements.river.model.RiverAxisKm; +import org.dive4elements.river.utils.GeometryUtils; + +import com.vividsolutions.jts.geom.Envelope; /** * @author Domenico Nardi Tironi @@ -121,4 +125,31 @@ return new InundationDurationCalculation(context).calculate(artifact); } + + /** + * The extent is restricted to the selected station range + */ + @Override + protected Envelope getExtent(final boolean reproject) { + + final InundationDurationAccess access = new InundationDurationAccess((UINFOArtifact) this.artifact); + + final double lowerKm = access.getLowerKm(); + final double upperKm = access.getUpperKm(); + + final List<RiverAxisKm> axisKms = RiverAxisKm.getRiverAxisKms(getRiverId(), lowerKm, upperKm); + + Envelope max = null; + + for (final RiverAxisKm ax : axisKms) { + final Envelope env = ax.getGeom().getEnvelopeInternal(); + + if (max == null) + max = env; + else + max.expandToInclude(env); + } + + return max != null && reproject ? GeometryUtils.transform(max, getSrid()) : max; + } } \ No newline at end of file
--- a/backend/src/main/java/org/dive4elements/river/model/RiverAxisKm.java Thu Oct 25 17:11:59 2018 +0200 +++ b/backend/src/main/java/org/dive4elements/river/model/RiverAxisKm.java Mon Oct 29 17:57:30 2018 +0100 @@ -10,6 +10,7 @@ import java.io.Serializable; import java.math.BigDecimal; +import java.util.Collections; import java.util.List; import javax.persistence.Column; @@ -19,94 +20,105 @@ import javax.persistence.OneToOne; import javax.persistence.Table; +import org.dive4elements.river.backend.SessionHolder; +import org.hibernate.Query; import org.hibernate.Session; -import org.hibernate.Query; import org.hibernate.annotations.Type; import com.vividsolutions.jts.geom.Point; -import org.dive4elements.river.backend.SessionHolder; - - @Entity @Table(name = "river_axes_km") -public class RiverAxisKm -implements Serializable -{ - private Integer id; - private River river; +public class RiverAxisKm implements Serializable { + + private static final long serialVersionUID = 1L; + + private Integer id; + private River river; private BigDecimal km; - private Point geom; - + private Point geom; public RiverAxisKm() { } - @Id @Column(name = "id") public Integer getId() { - return id; + return this.id; } - - public void setId(Integer id) { + public void setId(final Integer id) { this.id = id; } - @OneToOne @JoinColumn(name = "river_id") public River getRiver() { - return river; + return this.river; } - - public void setRiver(River river) { + public void setRiver(final River river) { this.river = river; } - @Column(name = "km") public BigDecimal getKm() { - return km; + return this.km; } - - public void setKm(BigDecimal km) { + public void setKm(final BigDecimal km) { this.km = km; } - @Column(name = "geom") @Type(type = "org.hibernatespatial.GeometryUserType") public Point getGeom() { - return geom; + return this.geom; } - - public void setGeom(Point geom) { + public void setGeom(final Point geom) { this.geom = geom; } - /** * Returns a list of RiverAxisKm objects for a given river. * - * @param riverid The ID of a river in the database. + * @param riverid + * The ID of a river in the database. * * @return a list of RiverAxisKm objects. */ - public static List<RiverAxisKm> getRiverAxisKms(int riverid) { - Session session = SessionHolder.HOLDER.get(); + public static List<RiverAxisKm> getRiverAxisKms(final int riverid) { + final Session session = SessionHolder.HOLDER.get(); - Query query = session.createQuery( - "from RiverAxisKm where river.id =:riverid"); + final Query query = session.createQuery("from RiverAxisKm where river.id =:riverid"); query.setParameter("riverid", riverid); - List<RiverAxisKm> list = query.list(); + final List<RiverAxisKm> list = query.list(); return list; } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : + + public static List<RiverAxisKm> getRiverAxisKms(final int riverId, final double lowerKm, final double upperKm) { + final Session session = SessionHolder.HOLDER.get(); + + assert lowerKm <= upperKm; + + if (Double.isNaN(lowerKm) || Double.isInfinite(lowerKm)) + return Collections.emptyList(); + if (Double.isNaN(upperKm) || Double.isInfinite(upperKm)) + return Collections.emptyList(); + + final BigDecimal fromKm = BigDecimal.valueOf(lowerKm); + final BigDecimal toKm = BigDecimal.valueOf(upperKm); + + final Query query = session.createQuery("from RiverAxisKm where river.id =:riverid AND km >= :fromKm AND km <= :toKm"); + query.setParameter("riverid", riverId); + query.setParameter("fromKm", fromKm); + query.setParameter("toKm", toKm); + + final List<RiverAxisKm> list = query.list(); + + return list; + } +} \ No newline at end of file