changeset 511:c5ed4ea8fb64

Make the mean with of an Mesh configurable issue93 gnv-artifacts/trunk@602 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Fri, 22 Jan 2010 12:48:16 +0000
parents 9e5ed3eebf29
children 12ab08de9de5
files gnv-artifacts/ChangeLog gnv-artifacts/doc/conf/meshwidth.xml gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh.xml gnv-artifacts/doc/conf/products/timeseries/conf_mesh.xml gnv-artifacts/doc/conf/products/verticalprofile/conf_mesh.xml gnv-artifacts/src/main/java/de/intevation/gnv/state/CoordinateSelectionState.java
diffstat 6 files changed, 92 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Fri Jan 22 10:32:49 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Fri Jan 22 12:48:16 2010 +0000
@@ -1,5 +1,22 @@
 2010-01-22  Tim Englich  <tim.englich@intevation.de>
 
+	  Issue93
+
+	* doc/conf/meshwidth.xml: 
+	  Added file for the global Configuration of MeshWidths to the Project.
+	  This file has to be edited if the mean Distance between two MeshPoints has
+	  changed or a new Mesh will be introduced.
+	  
+	* doc/conf/products/verticalprofile/conf_mesh.xml,
+	  doc/conf/products/timeseries/conf_mesh.xml, 
+	  doc/conf/products/horizontalprofile/conf_mesh.xml:
+	  Added Elemet with Link to the MeshWidth-Document to Configurations 
+	  for CoordinateSelectionStates.
+	  
+	* src/main/java/de/intevation/gnv/state/CoordinateSelectionState.java : 
+	  Added the possibility to configure the different width of the Meshes.
+
+2010-01-22  Tim Englich  <tim.englich@intevation.de>
 	* src/test/java/de/intevation/gnv/artifacts/TestArtifactDatabase.java (serviceNamesAndDescriptions),(process):
 	  Fixed Compiler-Error after adding further Methods to the Interface ArtifactDatabase.
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/doc/conf/meshwidth.xml	Fri Jan 22 12:48:16 2010 +0000
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mesh-widths>
+    <mesh id="1" width="0.03" description="Küstenmodell"/>
+    <mesh id="2" width="0.30" description="Ostseemodell"/>
+    <mesh id="3" width="0.15" description="SST"/>
+    <mesh id="4" width="0.03" description="Küstenmodell Tagesmittel"/>
+    <mesh id="5" width="0.16" description="Nord-Ostseemodell Tagesmittel"/>
+    <mesh id="321" width="0.30" description="SST"/>
+    <mesh id="641" width="0.30" description="Eisdaten"/>
+</mesh-widths>
\ No newline at end of file
--- a/gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh.xml	Fri Jan 22 10:32:49 2010 +0000
+++ b/gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh.xml	Fri Jan 22 12:48:16 2010 +0000
@@ -99,6 +99,7 @@
                 <inputvalue name="fisname" type="String" multiselect="false" usedinquery="0"/>
                 <inputvalue name="mesh_point" type="Integer" multiselect="false" usedinquery="0"/>
            </inputvalues>
+           <mesh-width xlink:href="${artifacts.config.dir}/meshwidth.xml"/>
        </state>
        
        <transition transition="de.intevation.gnv.transition.DefaultTransition">
--- a/gnv-artifacts/doc/conf/products/timeseries/conf_mesh.xml	Fri Jan 22 10:32:49 2010 +0000
+++ b/gnv-artifacts/doc/conf/products/timeseries/conf_mesh.xml	Fri Jan 22 12:48:16 2010 +0000
@@ -99,6 +99,7 @@
                  <inputvalue name="fisname" type="String" multiselect="false" usedinquery="0"/>
                  <inputvalue name="mesh_point" type="Integer" multiselect="false" usedinquery="0"/>
             </inputvalues>
+            <mesh-width xlink:href="${artifacts.config.dir}/meshwidth.xml"/>
         </state>
         
         <transition transition="de.intevation.gnv.transition.DefaultTransition">
--- a/gnv-artifacts/doc/conf/products/verticalprofile/conf_mesh.xml	Fri Jan 22 10:32:49 2010 +0000
+++ b/gnv-artifacts/doc/conf/products/verticalprofile/conf_mesh.xml	Fri Jan 22 12:48:16 2010 +0000
@@ -99,6 +99,7 @@
                 <inputvalue name="fisname" type="String" multiselect="false" usedinquery="0"/>
                 <inputvalue name="mesh_point" type="Integer" multiselect="false" usedinquery="0"/>
            </inputvalues>
+           <mesh-width xlink:href="${artifacts.config.dir}/meshwidth.xml"/>
        </state>
        
        <transition transition="de.intevation.gnv.transition.DefaultTransition">
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/CoordinateSelectionState.java	Fri Jan 22 10:32:49 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/CoordinateSelectionState.java	Fri Jan 22 12:48:16 2010 +0000
@@ -5,20 +5,24 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 
 import org.apache.log4j.Logger;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 import com.vividsolutions.jts.geom.Point;
-import com.vividsolutions.jts.io.ParseException;
-import com.vividsolutions.jts.io.WKTReader;
 
+import de.intevation.artifactdatabase.Config;
 import de.intevation.gnv.geobackend.base.Result;
 import de.intevation.gnv.state.describedata.DefaultKeyValueDescribeData;
 import de.intevation.gnv.state.describedata.KeyValueDescibeData;
 import de.intevation.gnv.state.describedata.NamedArrayList;
 import de.intevation.gnv.state.describedata.NamedCollection;
+import de.intevation.gnv.utils.ArtifactXMLUtilities;
 import de.intevation.gnv.utils.InputValidator;
 import de.intevation.gnv.utils.WKTUtils;
 import de.intevation.gnv.utils.exception.ValidationException;
@@ -38,6 +42,21 @@
      * The UID of this Class
      */
     private static final long serialVersionUID = 6318923553625195063L;
+    
+    /**
+     * XPATH Expressions for the setup.
+     */
+    
+    private final static String MESH_WIDTH_XPATH = "mesh-width";
+    private final static String XLINK_XPATH = "xlink:href";
+    private final static String MESH_LIST_XPATH = "/mesh-widths/mesh";
+    private final static String ID_XPATH = "id";
+    private final static String WIDTH_VALUE_XPATH = "width";
+    
+    /**
+     * Holds all given Widths between two MeshPoints for different Meshes.
+     */
+    private HashMap<String, Double> meshWidths = null;
 
     /**
      * Constructor
@@ -59,6 +78,9 @@
         this.setDescibeData(uuid, describeData);
     }
     
+    /**
+     * @see de.intevation.gnv.state.StateBase#prepareInputData4RegionDBQuery(java.lang.String)
+     */
     @Override
     protected String prepareInputData4RegionDBQuery(String value) {
         log.debug("CoordinateSelectionState.prepareInputData4RegionDBQuery");
@@ -66,17 +88,18 @@
         String returnValue = null;
         try {
             Point center = new InputValidator().getPointValue(value);
-            String meshIDValue = super.inputData.get("meshid").getValue();
+            String meshId = 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
+            if (meshWidths != null){
+                Double distanceValue = this.meshWidths.get(meshId);
+                if (distanceValue != null){
+                    log.debug("User "+distanceValue+" as Buffer around given Point");
+                    distance = distanceValue.doubleValue();
+                }else{
+                    log.warn("No distance is configured for Mesh with id"+ meshId);
+                }
+            }else{
+                log.warn("No MeshWidth configured. Check if this is correct.");
             }
             returnValue = center.buffer(distance,segments).toText();
         } catch (NumberFormatException e) {
@@ -122,4 +145,31 @@
     protected static String convert2DisplayCoordinate(String wkt){
         return WKTUtils.toText(wkt);
     }
+
+    /**
+     * @see de.intevation.gnv.state.StateBase#setup(org.w3c.dom.Node)
+     */
+    @Override
+    public void setup(Node configuration) {
+        super.setup(configuration);
+        Element widthElement = (Element)Config.getNodeXPath(configuration, MESH_WIDTH_XPATH);
+        
+        if (widthElement != null){
+            String fileName = widthElement.getAttribute(XLINK_XPATH);
+            fileName = Config.replaceConfigDir(fileName);
+            Node configurationNode = new ArtifactXMLUtilities().readConfiguration(fileName);
+            NodeList meshNodes = Config.getNodeSetXPath(configurationNode,MESH_LIST_XPATH );
+            if (meshNodes != null){
+                meshWidths = new HashMap<String, Double>(meshNodes.getLength());
+                for (int i = 0; i < meshNodes.getLength(); i++){
+                    Element meshNode = (Element)meshNodes.item(i);
+                    String id = meshNode.getAttribute(ID_XPATH);
+                    Double value = Double.parseDouble(meshNode.getAttribute(WIDTH_VALUE_XPATH));
+                    meshWidths.put(id, value);
+                }
+            }
+        }else{
+            log.warn("No Mesh Width defined.");
+        }
+    }
 }

http://dive4elements.wald.intevation.org