Mercurial > dive4elements > river
changeset 2341:8e2fe935ddf1
Added function to retrieve nearest CrossSectionTrack to a given kilometer.
flys-backend/trunk@2826 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 26 Sep 2011 15:26:44 +0000 |
parents | c4f090a00178 |
children | 3efc3942b765 |
files | flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/model/CrossSectionTrack.java |
diffstat | 2 files changed, 33 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-backend/ChangeLog Fri Sep 23 11:15:20 2011 +0000 +++ b/flys-backend/ChangeLog Mon Sep 26 15:26:44 2011 +0000 @@ -1,3 +1,9 @@ +2011-09-26 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/model/CrossSectionTrack.java: + Added new function that the nearest CrossSectionTrack of a river to a + given kilometer. + 2011-09-23 Bjoern Schilberg <bjoern@intevation.de> * doc/schema/postgresql-spatial.sql:
--- a/flys-backend/src/main/java/de/intevation/flys/model/CrossSectionTrack.java Fri Sep 23 11:15:20 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/CrossSectionTrack.java Mon Sep 26 15:26:44 2011 +0000 @@ -104,5 +104,32 @@ return query.list(); } + + + /** + * Returns the nearest CrossSectionTrack of <i>river</i> to a given + * <i>km</i>. + * + * @param river The name of a river. + * @param km The kilometer value. + * + * @return the nearest CrossSectionTrack to <i>km</i> of river <i>river</i>. + */ + public static CrossSectionTrack getCrossSectionTrack( + String river, + double km + ) { + Session session = SessionHolder.HOLDER.get(); + + Query query = session.createQuery( + "from CrossSectionTrack where river.name =:river " + + "order by abs( km - :mykm)"); + query.setParameter("river", river); + query.setParameter("mykm", new BigDecimal(km)); + + List<CrossSectionTrack> cst = query.list(); + + return cst != null && !cst.isEmpty() ? cst.get(0) : null; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :