changeset 173:1b2fc94766c9

Added real Coordinate-Query to TimeSeries-Mesh gnv-artifacts/trunk@212 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 13 Oct 2009 09:11:23 +0000
parents b5e55f460f0b
children dbf68950b4d9
files gnv-artifacts/ChangeLog gnv-artifacts/pom.xml gnv-artifacts/src/main/java/de/intevation/gnv/transition/CoordinateSelectionTransition.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java gnv-artifacts/src/main/java/de/intevation/gnv/utils/exception/ValidationException.java gnv-artifacts/src/main/resources/lang/artifactMessages.properties gnv-artifacts/src/main/resources/lang/artifactMessages_de.properties gnv-artifacts/src/main/resources/lang/artifactMessages_de_DE.properties gnv-artifacts/src/main/resources/lang/artifactMessages_en.properties gnv-artifacts/src/test/ressources/conf.xml gnv-artifacts/src/test/ressources/queries.properties gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_02_feed.xml gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_03_feed.xml gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_04_feed.xml gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_05_feed.xml gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_07_feed.xml
diffstat 17 files changed, 260 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Mon Oct 12 09:19:16 2009 +0000
+++ b/gnv-artifacts/ChangeLog	Tue Oct 13 09:11:23 2009 +0000
@@ -1,3 +1,21 @@
+2009-10-13  Tim Englich  <tim.englich@intevation.de>
+
+    * src/main/resources/lang/artifactMessages_*.properties: 
+      Switched to better Description of an Coordinate-Input-Field
+    * src/test/ressources/timeseries_mesh/timeseries_*_feed.xml:
+      Switched to Szenario where it is possible to select Data using the Coordinate. 
+    * src/test/ressources/queries.properties, 
+      src/test/ressources/conf.xml: 
+      Switched to SFS-Conformant-Queries in Timeseries-Mesh
+    * pom.xml: 
+      Added dependency to JTS 1.9
+    * src/main/java/de/intevation/gnv/utils/exception/ValidationException.java (ValidationException): 
+      src/main/java/de/intevation/gnv/utils/InputValidator.java (getPointValue): 
+      src/main/java/de/intevation/gnv/transition/TransitionBase.java (prepareInputData4RegionDBQuery): 
+      Added the Support for specialized Handling of InputValues of type Coordinate.
+    * src/main/java/de/intevation/gnv/transition/CoordinateSelectionTransition.java: 
+      Added Transition for the Support of Coordinateinput handling.
+      
 2009-10-12	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java:
--- a/gnv-artifacts/pom.xml	Mon Oct 12 09:19:16 2009 +0000
+++ b/gnv-artifacts/pom.xml	Tue Oct 13 09:11:23 2009 +0000
@@ -80,5 +80,17 @@
       <artifactId>oro</artifactId>
       <version>2.0.8</version>
     </dependency>
+  <dependency>
+      <groupId>com.vividsolutions</groupId>
+      <artifactId>jts</artifactId>
+      <version>1.9</version>
+    </dependency>
   </dependencies>
+  <repositories>
+    <repository>
+      <id>gt2.repo</id>
+      <name>GeoTools2 Repository including JTS</name>
+      <url>http://maven.geotools.fr/repository</url>
+    </repository>
+  </repositories>
 </project>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/CoordinateSelectionTransition.java	Tue Oct 13 09:11:23 2009 +0000
@@ -0,0 +1,88 @@
+/**
+ *
+ */
+package de.intevation.gnv.transition;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.log4j.Logger;
+
+import com.vividsolutions.jts.geom.Point;
+
+import de.intevation.gnv.geobackend.base.Result;
+import de.intevation.gnv.transition.describedata.KeyValueDescibeData;
+import de.intevation.gnv.transition.describedata.NamedCollection;
+import de.intevation.gnv.utils.InputValidator;
+import de.intevation.gnv.utils.exception.ValidationException;
+
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public class CoordinateSelectionTransition extends TransitionBase {
+
+    /**
+     * the logger, used to log exceptions and additonaly information
+     */
+    private static Logger log = Logger.getLogger(CoordinateSelectionTransition.class);
+    
+    /**
+     * The UID of this Class
+     */
+    private static final long serialVersionUID = 6318923553625195063L;
+
+    /**
+     * Constructor
+     */
+    public CoordinateSelectionTransition() {
+        super();
+    }
+
+    /**
+     * @see de.intevation.gnv.transition.Transition#validate()
+     */
+    public boolean validate() {
+        return true;
+    }
+
+    @Override
+    protected void purifyResult(Collection<Result> result, String uuid) {
+        log.debug("CoordinateSelectionTransition.purifyResult");
+        if (this.descibeData == null) {
+            this.descibeData = new ArrayList<Object>();
+        }
+        NamedCollection<KeyValueDescibeData> keyValueDescibeData = this
+                .extractKVP(result, "FEATUREID", "SHAPE");
+        this.descibeData.add(keyValueDescibeData);
+    }
+    
+    @Override
+    protected String prepareInputData4RegionDBQuery(String value) {
+        log.debug("CoordinateSelectionTransition.prepareInputData4RegionDBQuery");
+        double distance=0.;
+        String returnValue = null;
+        try {
+            Point center = new InputValidator().getPointValue(value);
+            String meshIDValue = super.inputData.get("meshid").getValue();
+            int segments = 97;
+            int meshid = new Integer(meshIDValue);
+            if (meshid == 3 || meshid == 5){ // TODO nicht hier festbrennen.
+                distance = 0.15; //nord-ostsee 6nm // 97 Stützpunkte
+            }else if (meshid == 1 || meshid == 4){
+                distance = 0.03; //Kuestenmodell 1 nm
+            }else if (meshid == 2 || meshid == 321){
+                distance = 0.3; //SST Karten ca 20km
+            }else if (meshid == 641){
+                distance = 0.3; //Eisdaten Klima
+            }
+            returnValue = center.buffer(distance,segments).toText();
+        } catch (NumberFormatException e) {
+            log.error(e,e);
+        } catch (ValidationException e) {
+            log.error(e,e);
+        }
+        return returnValue;
+        
+    }
+}
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java	Mon Oct 12 09:19:16 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java	Tue Oct 13 09:11:23 2009 +0000
@@ -335,6 +335,9 @@
                     } else if (type.equalsIgnoreCase("date")) {
                         requestValue = this
                                 .prepareInputData4DateDBQuery(requestValue);
+                    } else if (type.equalsIgnoreCase("coordinate")){
+                        requestValue = this
+                        .prepareInputData4RegionDBQuery(requestValue);
                     }
                     for (int j = 0; j < size; j++) {
                         list.add(requestValue);
@@ -359,6 +362,10 @@
             throw new TransitionException(e);
         }
     }
+    
+    protected String prepareInputData4RegionDBQuery(String value){
+        return value;
+    }
 
     private String prepareInputData4DateDBQuery(String value) {
         log.debug("TransitionBase.prepareInputData4DateDBQuery");
@@ -405,6 +412,18 @@
         if (this.descibeData == null) {
             this.descibeData = new ArrayList<Object>();
         }
+        NamedCollection<KeyValueDescibeData> keyValueDescibeData = extractKVP(result, "KEY", "VALUE");
+        this.descibeData.add(keyValueDescibeData);
+    }
+
+    /**
+     * @param result
+     * @return
+     */
+    protected NamedCollection<KeyValueDescibeData> extractKVP(
+                                                              Collection<Result> result,
+                                                              String keyid,
+                                                              String valueid) {
         Iterator<Result> rit = result.iterator();
         NamedCollection<KeyValueDescibeData> keyValueDescibeData = new NamedArrayList<KeyValueDescibeData>(
                 this.dataName, result.size());
@@ -412,9 +431,9 @@
         while (rit.hasNext()) {
             Result resultValue = rit.next();
             keyValueDescibeData.add(new DefaultKeyValueDescribeData(resultValue
-                    .getString("KEY"), resultValue.getString("VALUE")));
+                    .getString(keyid), resultValue.getString(valueid)));
         }
-        this.descibeData.add(keyValueDescibeData);
+        return keyValueDescibeData;
     }
 
     /**
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java	Mon Oct 12 09:19:16 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java	Tue Oct 13 09:11:23 2009 +0000
@@ -6,7 +6,12 @@
 import org.apache.commons.validator.GenericValidator;
 import org.apache.log4j.Logger;
 
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.GeometryFactory;
+import com.vividsolutions.jts.geom.Point;
+
 import de.intevation.gnv.geobackend.util.DateUtils;
+import de.intevation.gnv.utils.exception.ValidationException;
 
 /**
  * @author Tim Englich <tim.englich@intevation.de>
@@ -53,6 +58,13 @@
                         .matchRegexp(values[i], "[a-zA-Z0-9]"); // TODO: FIXME:
                                                                 // VALIDATE
                                                                 // REGEXP
+            } else if ("Coordinate".equalsIgnoreCase(type)) {
+                    try {
+                        valid = this.getPointValue(values[i]) != null;
+                    } catch (ValidationException e) {
+                        log.debug(e.getMessage());
+                        valid = false;
+                    }
             } else {
                 valid = false;
             }
@@ -66,5 +78,44 @@
         log.debug("Is valid? " + returnValue);
         return returnValue;
     }
+    
+    
+    public Point getPointValue(String value) throws ValidationException{
+        log.debug("InputValidator.getPointValue " + value);
+        String[] s, p;
+        
+        double x=0,y=0;
+        log.info("Position :"+value);
+        s = value.split(" ");
+        if (s.length != 2) {
+              throw new ValidationException("Kein Blank separiert Breite und Länge");
+        }
+        p = s[0].split("[nNsS]");
+        try {
+            if (p.length == 1)
+                y = new Double(p[0]);
+            else
+                y = new Double(p[0]) +   new Double(p[1]) / new Double(60.);
+            if (s[0].toLowerCase().contains("s"))
+                y = -y;
+        }
+        catch (Exception e) {
+            throw new ValidationException("Kein N|S oder nicht im ersten Substring, zB 56n42");
+        
+        } 
+        p = s[1].split("[eEwW]");
+        try {
+            if (p.length ==1)
+                x = new Double(p[0]);
+            else
+                x = new Double(p[0]) +  new Double(p[1]) / new Double(60.) ;
+            if (s[1].toLowerCase().contains("w"))
+                x = -x;
+        }
+        catch (Exception e) {
+            throw new ValidationException("Kein E|W oder nicht im zweiten Substring");
+        } 
+        return new GeometryFactory().createPoint(new Coordinate(x,y));
+    }
 
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/exception/ValidationException.java	Tue Oct 13 09:11:23 2009 +0000
@@ -0,0 +1,48 @@
+/**
+ *
+ */
+package de.intevation.gnv.utils.exception;
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public class ValidationException extends Exception {
+
+    /**
+     * The Uid of this Class
+     */
+    private static final long serialVersionUID = -6189218101861801079L;
+
+    /**
+     * Constructor
+     */
+    public ValidationException() {
+        super();
+    }
+
+    /**
+     * Constructor
+     * @param arg0
+     */
+    public ValidationException(String arg0) {
+        super(arg0);
+    }
+
+    /**
+     * Constructor
+     * @param arg0
+     */
+    public ValidationException(Throwable arg0) {
+        super(arg0);
+    }
+
+    /**
+     * Constructor
+     * @param arg0
+     * @param arg1
+     */
+    public ValidationException(String arg0, Throwable arg1) {
+        super(arg0, arg1);
+    }
+
+}
--- a/gnv-artifacts/src/main/resources/lang/artifactMessages.properties	Mon Oct 12 09:19:16 2009 +0000
+++ b/gnv-artifacts/src/main/resources/lang/artifactMessages.properties	Tue Oct 13 09:11:23 2009 +0000
@@ -11,7 +11,7 @@
 verticalProfile = Verticalprofile
 horizontalProfile = Horizontalprofile
 featureid = Object
-mesh_coordinate = Coordinate Value (x y)
+mesh_coordinate = Position (e.g. 56n30 6e20)
 mesh_point = Meshpoint
 measurementid = Measurement depth
 parameterid = Parameter
--- a/gnv-artifacts/src/main/resources/lang/artifactMessages_de.properties	Mon Oct 12 09:19:16 2009 +0000
+++ b/gnv-artifacts/src/main/resources/lang/artifactMessages_de.properties	Tue Oct 13 09:11:23 2009 +0000
@@ -12,7 +12,7 @@
 horizontalProfile = Horizontalprofil
 featureid = Station
 meshid= Netz
-mesh_coordinate = Koordinaten Wert (x y)
+mesh_coordinate = Position (z.B. 56n30 6e20)
 mesh_point = Messpunkt
 measurementid = Messtiefe
 parameterid = Parameter
--- a/gnv-artifacts/src/main/resources/lang/artifactMessages_de_DE.properties	Mon Oct 12 09:19:16 2009 +0000
+++ b/gnv-artifacts/src/main/resources/lang/artifactMessages_de_DE.properties	Tue Oct 13 09:11:23 2009 +0000
@@ -12,7 +12,7 @@
 horizontalProfile = Horizontalprofil
 featureid = Station
 meshid= Netz
-mesh_coordinate = Koordinaten Wert (x y)
+mesh_coordinate = Position (z.B. 56n30 6e20)
 mesh_point = Messpunkt
 measurementid = Messtiefe
 parameterid = Parameter
--- a/gnv-artifacts/src/main/resources/lang/artifactMessages_en.properties	Mon Oct 12 09:19:16 2009 +0000
+++ b/gnv-artifacts/src/main/resources/lang/artifactMessages_en.properties	Tue Oct 13 09:11:23 2009 +0000
@@ -11,7 +11,7 @@
 verticalProfile = Verticalprofile
 horizontalProfile = Horizontalprofile
 featureid = Object
-mesh_coordinate = Coordinate Value (x y)
+mesh_coordinate = Position (e.g. 56n30 6e20)
 mesh_point = Meshpoint
 measurementid = Measurement depth
 parameterid = Parameter
--- a/gnv-artifacts/src/test/ressources/conf.xml	Mon Oct 12 09:19:16 2009 +0000
+++ b/gnv-artifacts/src/test/ressources/conf.xml	Tue Oct 13 09:11:23 2009 +0000
@@ -193,7 +193,7 @@
                     </inputvalues>
                 </transition>
                 
-                <transition id="timeseries_meshpoint" description="timeseries_meshpoint" transition="de.intevation.gnv.transition.DefaultTransition">
+                <transition id="timeseries_meshpoint" description="timeseries_meshpoint" transition="de.intevation.gnv.transition.CoordinateSelectionTransition">
                     <queryID>timeseries_meshpoint</queryID>
                     <dataname>mesh_point</dataname>
                     <data-multiselect>false</data-multiselect>
@@ -202,7 +202,7 @@
                     </reachableTransitions>
                     <inputvalues>
                          <inputvalue name="meshid" type="Integer" multiselect="false"/>
-                         <inputvalue name="mesh_coordinate" type="Point" multiselect="false" usedinquery="0"/>
+                         <inputvalue name="mesh_coordinate" type="Coordinate" multiselect="false" usedinquery="1"/>
                     </inputvalues>
                 </transition>
                 
--- a/gnv-artifacts/src/test/ressources/queries.properties	Mon Oct 12 09:19:16 2009 +0000
+++ b/gnv-artifacts/src/test/ressources/queries.properties	Tue Oct 13 09:11:23 2009 +0000
@@ -94,14 +94,15 @@
         m.NAME VALUE \
     FROM MEDIAN.MESH m \
     order by m.NAME
-timeseries_meshpoint = SELECT FEATUREID KEY, \
-        SHAPE VALUE \
-    FROM MEDIAN.MESHPOINT mp , \
-         MEDIAN.MESH m \
-    WHERE m.OBJECTID = ? AND \
-          mp.MESHID = m.MESHID AND \
-          KPOSITION = 1 AND \
-          rownum < 10
+timeseries_meshpoint = SELECT FEATUREID, \
+        ST_ASTEXT(SHAPE) \
+    FROM MEDIAN.MESHPOINT \
+    WHERE MESHID  in \
+        (SELECT DISTINCT MESHID \
+         FROM MEDIAN.MESH \
+         WHERE OBJECTID = ?) AND \
+         KPOSITION = 1 AND \
+         INTERSECTS(SHAPE,"?")
 
 timeseries_meshpoint_depth = select mp.FEATUREID KEY, \
         -ml.UPPERZLOCATION || ' - '|| -ml.LOWERZLOCATION as VALUE \
--- a/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_02_feed.xml	Mon Oct 12 09:19:16 2009 +0000
+++ b/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_02_feed.xml	Tue Oct 13 09:11:23 2009 +0000
@@ -4,6 +4,6 @@
 	<art:uuid value="1e9f6583-9073-4409-aac1-432ad06d7ce1" />
 	<art:hash value="29913235" />
 	<art:data>
-		<art:input name="meshid" value="1" />
+		<art:input name="meshid" value="3" />
 	</art:data>
 </art:action>
\ No newline at end of file
--- a/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_03_feed.xml	Mon Oct 12 09:19:16 2009 +0000
+++ b/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_03_feed.xml	Tue Oct 13 09:11:23 2009 +0000
@@ -4,6 +4,6 @@
 	<art:uuid value="1e9f6583-9073-4409-aac1-432ad06d7ce1" />
 	<art:hash value="29913235" />
 	<art:data>
-		<art:input name="mesh_coordinate" value="6.5 58.1" />
+		<art:input name="mesh_coordinate" value="56n30 6e20" />
 	</art:data>
 </art:action>
\ No newline at end of file
--- a/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_04_feed.xml	Mon Oct 12 09:19:16 2009 +0000
+++ b/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_04_feed.xml	Tue Oct 13 09:11:23 2009 +0000
@@ -4,6 +4,6 @@
 	<art:uuid value="1e9f6583-9073-4409-aac1-432ad06d7ce1" />
 	<art:hash value="29913235" />
 	<art:data>
-		<art:input name="mesh_point" value="3021827" />
+		<art:input name="mesh_point" value="2003771" />
 	</art:data>
 </art:action>
\ No newline at end of file
--- a/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_05_feed.xml	Mon Oct 12 09:19:16 2009 +0000
+++ b/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_05_feed.xml	Tue Oct 13 09:11:23 2009 +0000
@@ -4,7 +4,7 @@
 	<art:uuid value="1e9f6583-9073-4409-aac1-432ad06d7ce1" />
 	<art:hash value="29913235" />
 	<art:data>
-		<art:input name="measurementid" value="3043872" />
-		<art:input name="measurementid" value="3060353" />
+		<art:input name="measurementid" value="2003771" />
+		<art:input name="measurementid" value="2012198" />
 	</art:data>
 </art:action>
\ No newline at end of file
--- a/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_07_feed.xml	Mon Oct 12 09:19:16 2009 +0000
+++ b/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_07_feed.xml	Tue Oct 13 09:11:23 2009 +0000
@@ -4,7 +4,7 @@
 	<art:uuid value="1e9f6583-9073-4409-aac1-432ad06d7ce1" />
 	<art:hash value="29913235" />
 	<art:data>
-		<art:input name="maxvalue" value="2009.10.02 00:00:00" />
-		<art:input name="minvalue" value="2009.09.17 00:15:00" />
+		<art:input name="maxvalue" value="2009.10.15 00:00:00" />
+		<art:input name="minvalue" value="2009.10.05 00:15:00" />
 	</art:data>
 </art:action>
\ No newline at end of file

http://dive4elements.wald.intevation.org