changeset 5146:d4fdd98a04f7

Add kind_id to river_axes table and add AxisKind object to model There are currently three kinds: 0 for unkown, 1 for current, 2 for everything else. Only current is used for calculation
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 28 Feb 2013 18:04:19 +0100
parents 801175535406
children 48b231a02d3a
files flys-backend/contrib/shpimporter/axis.py flys-backend/doc/schema/oracle-drop-spatial.sql flys-backend/doc/schema/oracle-spatial.sql flys-backend/doc/schema/postgresql-drop-spatial.sql flys-backend/doc/schema/postgresql-spatial.sql flys-backend/src/main/java/de/intevation/flys/backend/FLYSCredentials.java flys-backend/src/main/java/de/intevation/flys/model/AxisKind.java flys-backend/src/main/java/de/intevation/flys/model/RiverAxis.java
diffstat 8 files changed, 96 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/contrib/shpimporter/axis.py	Thu Feb 28 17:12:46 2013 +0100
+++ b/flys-backend/contrib/shpimporter/axis.py	Thu Feb 28 18:04:19 2013 +0100
@@ -32,7 +32,7 @@
                             ogr.wkbMultiLineString]
 
     def isShapeRelevant(self, name, path):
-        return "achse" in name.lower()
+        return "km.shp" not in path.lower()
 
 
     def createNewFeature(self, featureDef, feat, **args):
@@ -45,12 +45,10 @@
         else:
             riverId = self.river_id
 
-        if self.IsFieldSet(feat, "kind"):
-            kind = feat.GetField("kind")
+        newFeat.SetField("river_id", riverId)
+        if args.get("name", "").lower() == "achse":
+            newFeat.SetField("kind_id", 1) # 1 is Current
         else:
-            kind = 0
-
-        newFeat.SetField("river_id", riverId)
-        newFeat.SetField("kind", kind)
+            newFeat.SetField("kind_id", 2) # 2 Is Other
 
         return utils.convertToMultiLine(newFeat)
--- a/flys-backend/doc/schema/oracle-drop-spatial.sql	Thu Feb 28 17:12:46 2013 +0100
+++ b/flys-backend/doc/schema/oracle-drop-spatial.sql	Thu Feb 28 18:04:19 2013 +0100
@@ -71,4 +71,5 @@
 DROP TABLE sectie_kinds;
 DROP TABLE sobek_kinds;
 DROP TABLE fed_states;
+DROP TABLE axis_kinds;
 DROP TABLE boundary_kinds;
--- a/flys-backend/doc/schema/oracle-spatial.sql	Thu Feb 28 17:12:46 2013 +0100
+++ b/flys-backend/doc/schema/oracle-spatial.sql	Thu Feb 28 18:04:19 2013 +0100
@@ -1,11 +1,20 @@
 WHENEVER SQLERROR EXIT;
+
+CREATE TABLE axis_kinds(
+    id NUMBER PRIMARY KEY NOT NULL,
+    name VARCHAR(64)
+);
+INSERT INTO axis_kinds(id, name, use_for_caclulation) VALUES (0, 'Unbekannt');
+INSERT INTO axis_kinds(id, name, use_for_caclulation) VALUES (1, 'Aktuell');
+INSERT INTO axis_kinds(id, name, use_for_caclulation) VALUES (2, 'Sonstige');
+
 -- Geodaesie/Flussachse+km/achse
 CREATE SEQUENCE RIVER_AXES_ID_SEQ;
 CREATE TABLE river_axes(
     OGR_FID NUMBER(38),
     GEOM MDSYS.SDO_GEOMETRY,
     river_id NUMBER(38) REFERENCES rivers(id) ON DELETE CASCADE,
-    kind     NUMBER(38) DEFAULT 0 NOT NULL,
+    kind_id  NUMBER(38) REFERENCES axis_kinds(id) NOT NULL,
     name     VARCHAR(64),
     path     VARCHAR(256),
     ID NUMBER PRIMARY KEY NOT NULL
--- a/flys-backend/doc/schema/postgresql-drop-spatial.sql	Thu Feb 28 17:12:46 2013 +0100
+++ b/flys-backend/doc/schema/postgresql-drop-spatial.sql	Thu Feb 28 18:04:19 2013 +0100
@@ -44,5 +44,6 @@
 DROP TABLE sobek_kinds;
 DROP TABLE sectie_kinds;
 DROP TABLE boundary_kinds;
+DROP TABLE axis_kinds;
 
 COMMIT;
--- a/flys-backend/doc/schema/postgresql-spatial.sql	Thu Feb 28 17:12:46 2013 +0100
+++ b/flys-backend/doc/schema/postgresql-spatial.sql	Thu Feb 28 18:04:19 2013 +0100
@@ -1,11 +1,19 @@
 BEGIN;
 
+CREATE TABLE axis_kinds(
+    id int PRIMARY KEY NOT NULL,
+    name VARCHAR(64)
+);
+INSERT INTO axis_kinds(id, name) VALUES (0, 'Unbekannt');
+INSERT INTO axis_kinds(id, name) VALUES (1, 'Aktuell');
+INSERT INTO axis_kinds(id, name) VALUES (2, 'Sonstige');
+
 -- Geodaesie/Flussachse+km/achse
 CREATE SEQUENCE RIVER_AXES_ID_SEQ;
 CREATE TABLE river_axes (
     id       int PRIMARY KEY NOT NULL,
     river_id int REFERENCES rivers(id) ON DELETE CASCADE,
-    kind     int             NOT NULL DEFAULT 0,
+    kind_id  int REFERENCES axis_kinds(id) NOT NULL DEFAULT 0,
     name     VARCHAR(64),
     path     VARCHAR(256)
 );
--- a/flys-backend/src/main/java/de/intevation/flys/backend/FLYSCredentials.java	Thu Feb 28 17:12:46 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/backend/FLYSCredentials.java	Thu Feb 28 18:04:19 2013 +0100
@@ -5,6 +5,7 @@
 import de.intevation.flys.model.Annotation;
 import de.intevation.flys.model.AnnotationType;
 import de.intevation.flys.model.Attribute;
+import de.intevation.flys.model.AxisKind;
 import de.intevation.flys.model.BedHeightEpoch;
 import de.intevation.flys.model.BedHeightEpochValue;
 import de.intevation.flys.model.BedHeightSingle;
@@ -120,6 +121,7 @@
         Annotation.class,
         AnnotationType.class,
         Attribute.class,
+        AxisKind.class,
         BedHeightEpoch.class,
         BedHeightEpochValue.class,
         BedHeightSingle.class,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/model/AxisKind.java	Thu Feb 28 18:04:19 2013 +0100
@@ -0,0 +1,44 @@
+package de.intevation.flys.model;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "axis_kinds")
+public class AxisKind implements Serializable {
+    private Integer id;
+    private String name;
+
+    @Id
+    @Column(name = "id")
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    /**
+     * Get name.
+     *
+     * @return The display Name of the kind as String.
+     */
+    @Column(name = "name")
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * Set name.
+     *
+     * @param name the value to set.
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+}
--- a/flys-backend/src/main/java/de/intevation/flys/model/RiverAxis.java	Thu Feb 28 17:12:46 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/model/RiverAxis.java	Thu Feb 28 18:04:19 2013 +0100
@@ -17,14 +17,13 @@
 import com.vividsolutions.jts.geom.MultiLineString;
 
 import de.intevation.flys.backend.SessionHolder;
+import de.intevation.flys.model.AxisKind;
 
 
 /**
- * There is a modeling problem with the RiverAxis. The initial idea was, that a
- * river can have a riveraxis that consist of exact one geometry. Now, it has
- * turned out, that a single geometry is not enough for a riveraxis (arm of a
- * river, inflows, ...). As workaround, we now expect, that a river can just
- * have a single riveraxis.
+ * A river has one axis that is used for calculation.
+ * Additional axes of a river can be used to be painted int maps etc.
+ * which one is the main river axis can be determined over the axis kind.
  */
 @Entity
 @Table(name = "river_axes")
@@ -32,14 +31,13 @@
 implements   Serializable
 {
     private Integer    id;
-    private Integer    kind;
+    private AxisKind   kind;
     private River      river;
     private MultiLineString geom;
 
-    public static final int DEFAULT_KIND = 0;
-
-    public static final int KIND_OFFICIAL = 1;
-    public static final int KIND_OUTSOURCED = 2;
+    public static final int KIND_UNKOWN = 0;
+    public static final int KIND_CURRENT = 1;
+    public static final int KIND_OTHER = 2;
 
     public RiverAxis() {
     }
@@ -69,13 +67,23 @@
     }
 
 
-    @Column(name = "kind")
-    public Integer getKind() {
+    /**
+     * Get kind.
+     *
+     * @return kind as AxisKind.
+     */
+    @OneToOne
+    @JoinColumn(name = "kind_id")
+    public AxisKind getKind() {
         return kind;
     }
 
-
-    public void setKind(Integer kind) {
+    /**
+     * Set kind.
+     *
+     * @param kind the value to set.
+     */
+    public void setKind(AxisKind kind) {
         this.kind = kind;
     }
 
@@ -93,14 +101,14 @@
 
 
     public static List<RiverAxis> getRiverAxis(String river) {
-        return getRiverAxis(river, DEFAULT_KIND);
+        return getRiverAxis(river, KIND_CURRENT);
     }
 
     public static List<RiverAxis> getRiverAxis(String river, int kind) {
         Session session = SessionHolder.HOLDER.get();
 
         Query query = session.createQuery(
-            "from RiverAxis where river.name =:river AND kind =:kind");
+            "from RiverAxis where river.name =:river AND kind.id =:kind");
         query.setParameter("river", river);
         query.setParameter("kind", kind);
 

http://dive4elements.wald.intevation.org