changeset 2869:e29781310140

Added new model class GaugeLocation for storing locations of gauges. flys-backend/trunk@4384 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 10 May 2012 11:52:37 +0000
parents b6f94c5db89e
children 28526b0b0a90
files flys-backend/ChangeLog flys-backend/contrib/shpimporter/gauges.py flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java flys-backend/src/main/java/de/intevation/flys/model/GaugeLocation.java
diffstat 4 files changed, 120 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Thu May 10 11:05:25 2012 +0000
+++ b/flys-backend/ChangeLog	Thu May 10 11:52:37 2012 +0000
@@ -1,3 +1,14 @@
+2012-05-10  Ingo Weinzierl <ingo@intevation.de>
+
+	* contrib/shpimporter/gauges.py: Search for field 'MPNAAM' and use its
+	  value as name for the geometry.
+
+	* src/main/java/de/intevation/flys/model/GaugeLocation.java: New model
+	  class for storing locations of gauges.
+
+	* src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java:
+	  Registered GaugeLocation class.
+
 2012-05-10  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/model/HydrBoundary.java,
--- a/flys-backend/contrib/shpimporter/gauges.py	Thu May 10 11:05:25 2012 +0000
+++ b/flys-backend/contrib/shpimporter/gauges.py	Thu May 10 11:52:37 2012 +0000
@@ -38,6 +38,8 @@
 
         if self.IsFieldSet(feat, "Name"):
             newFeat.SetField("name", feat.GetField("name"))
+        elif self.IsFieldSet(feat, "MPNAAM"):
+            newFeat.SetField("name", feat.GetField("MPNAAM"))
         else:
             newFeat.SetField("name", args['name'])
 
--- a/flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java	Thu May 10 11:05:25 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java	Thu May 10 11:52:37 2012 +0000
@@ -50,6 +50,7 @@
 import de.intevation.flys.model.FlowVelocityModel;
 import de.intevation.flys.model.FlowVelocityModelValue;
 import de.intevation.flys.model.Gauge;
+import de.intevation.flys.model.GaugeLocation;
 import de.intevation.flys.model.GrainFraction;
 import de.intevation.flys.model.Hws;
 import de.intevation.flys.model.HydrBoundary;
@@ -267,6 +268,7 @@
         cfg.addAnnotatedClass(FlowVelocityModel.class);
         cfg.addAnnotatedClass(FlowVelocityModelValue.class);
         cfg.addAnnotatedClass(Gauge.class);
+        cfg.addAnnotatedClass(GaugeLocation.class);
         cfg.addAnnotatedClass(GrainFraction.class);
         cfg.addAnnotatedClass(Hws.class);
         cfg.addAnnotatedClass(HydrBoundary.class);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/model/GaugeLocation.java	Thu May 10 11:52:37 2012 +0000
@@ -0,0 +1,105 @@
+package de.intevation.flys.model;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.List;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+
+import org.hibernate.Session;
+import org.hibernate.Query;
+import org.hibernate.annotations.Type;
+
+import com.vividsolutions.jts.geom.Point;
+
+import de.intevation.flys.backend.SessionHolder;
+
+
+@Entity
+@Table(name = "gauge_location")
+public class GaugeLocation
+implements   Serializable
+{
+    private Integer    id;
+    private River      river;
+    private String     name;
+    private Point      geom;
+
+
+    public GaugeLocation() {
+    }
+
+
+    @Id
+    @Column(name = "id")
+    public Integer getId() {
+        return id;
+    }
+
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+
+    @OneToOne
+    @JoinColumn(name = "river_id")
+    public River getRiver() {
+        return river;
+    }
+
+
+    public void setRiver(River river) {
+        this.river = river;
+    }
+
+
+    @Column(name = "name")
+    public String getName() {
+        return name;
+    }
+
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+
+    @Column(name = "geom")
+    @Type(type = "org.hibernatespatial.GeometryUserType")
+    public Point getGeom() {
+        return geom;
+    }
+
+
+    public void setGeom(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.
+     *
+     * @return a list of RiverAxisKm objects.
+     */
+    public static List<GaugeLocation> getGaugeLocations(int riverid, String name) {
+        Session session = SessionHolder.HOLDER.get();
+
+        Query query = session.createQuery(
+            "from GaugeLocation where river.id =:riverid and name=:name");
+        query.setParameter("riverid", riverid);
+        query.setParameter("name", name);
+
+        List<GaugeLocation> list = query.list();
+
+        return list;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org