comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/CoordinateSelectionState.java @ 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 45be952a3215
children 292fbcd5e9ac
comparison
equal deleted inserted replaced
510:9e5ed3eebf29 511:c5ed4ea8fb64
3 */ 3 */
4 package de.intevation.gnv.state; 4 package de.intevation.gnv.state;
5 5
6 import java.util.ArrayList; 6 import java.util.ArrayList;
7 import java.util.Collection; 7 import java.util.Collection;
8 import java.util.HashMap;
8 import java.util.Iterator; 9 import java.util.Iterator;
9 import java.util.List; 10 import java.util.List;
10 11
11 import org.apache.log4j.Logger; 12 import org.apache.log4j.Logger;
13 import org.w3c.dom.Element;
14 import org.w3c.dom.Node;
15 import org.w3c.dom.NodeList;
12 16
13 import com.vividsolutions.jts.geom.Point; 17 import com.vividsolutions.jts.geom.Point;
14 import com.vividsolutions.jts.io.ParseException;
15 import com.vividsolutions.jts.io.WKTReader;
16 18
19 import de.intevation.artifactdatabase.Config;
17 import de.intevation.gnv.geobackend.base.Result; 20 import de.intevation.gnv.geobackend.base.Result;
18 import de.intevation.gnv.state.describedata.DefaultKeyValueDescribeData; 21 import de.intevation.gnv.state.describedata.DefaultKeyValueDescribeData;
19 import de.intevation.gnv.state.describedata.KeyValueDescibeData; 22 import de.intevation.gnv.state.describedata.KeyValueDescibeData;
20 import de.intevation.gnv.state.describedata.NamedArrayList; 23 import de.intevation.gnv.state.describedata.NamedArrayList;
21 import de.intevation.gnv.state.describedata.NamedCollection; 24 import de.intevation.gnv.state.describedata.NamedCollection;
25 import de.intevation.gnv.utils.ArtifactXMLUtilities;
22 import de.intevation.gnv.utils.InputValidator; 26 import de.intevation.gnv.utils.InputValidator;
23 import de.intevation.gnv.utils.WKTUtils; 27 import de.intevation.gnv.utils.WKTUtils;
24 import de.intevation.gnv.utils.exception.ValidationException; 28 import de.intevation.gnv.utils.exception.ValidationException;
25 29
26 /** 30 /**
36 40
37 /** 41 /**
38 * The UID of this Class 42 * The UID of this Class
39 */ 43 */
40 private static final long serialVersionUID = 6318923553625195063L; 44 private static final long serialVersionUID = 6318923553625195063L;
45
46 /**
47 * XPATH Expressions for the setup.
48 */
49
50 private final static String MESH_WIDTH_XPATH = "mesh-width";
51 private final static String XLINK_XPATH = "xlink:href";
52 private final static String MESH_LIST_XPATH = "/mesh-widths/mesh";
53 private final static String ID_XPATH = "id";
54 private final static String WIDTH_VALUE_XPATH = "width";
55
56 /**
57 * Holds all given Widths between two MeshPoints for different Meshes.
58 */
59 private HashMap<String, Double> meshWidths = null;
41 60
42 /** 61 /**
43 * Constructor 62 * Constructor
44 */ 63 */
45 public CoordinateSelectionState() { 64 public CoordinateSelectionState() {
57 .extractKVP(result, "FEATUREID", "SHAPE"); 76 .extractKVP(result, "FEATUREID", "SHAPE");
58 describeData.add(keyValueDescibeData); 77 describeData.add(keyValueDescibeData);
59 this.setDescibeData(uuid, describeData); 78 this.setDescibeData(uuid, describeData);
60 } 79 }
61 80
81 /**
82 * @see de.intevation.gnv.state.StateBase#prepareInputData4RegionDBQuery(java.lang.String)
83 */
62 @Override 84 @Override
63 protected String prepareInputData4RegionDBQuery(String value) { 85 protected String prepareInputData4RegionDBQuery(String value) {
64 log.debug("CoordinateSelectionState.prepareInputData4RegionDBQuery"); 86 log.debug("CoordinateSelectionState.prepareInputData4RegionDBQuery");
65 double distance=0.; 87 double distance=0.;
66 String returnValue = null; 88 String returnValue = null;
67 try { 89 try {
68 Point center = new InputValidator().getPointValue(value); 90 Point center = new InputValidator().getPointValue(value);
69 String meshIDValue = super.inputData.get("meshid").getValue(); 91 String meshId = super.inputData.get("meshid").getValue();
70 int segments = 97; 92 int segments = 97;
71 int meshid = new Integer(meshIDValue); 93 if (meshWidths != null){
72 if (meshid == 3 || meshid == 5){ // TODO nicht hier festbrennen. 94 Double distanceValue = this.meshWidths.get(meshId);
73 distance = 0.15; //nord-ostsee 6nm // 97 Stützpunkte 95 if (distanceValue != null){
74 }else if (meshid == 1 || meshid == 4){ 96 log.debug("User "+distanceValue+" as Buffer around given Point");
75 distance = 0.03; //Kuestenmodell 1 nm 97 distance = distanceValue.doubleValue();
76 }else if (meshid == 2 || meshid == 321){ 98 }else{
77 distance = 0.3; //SST Karten ca 20km 99 log.warn("No distance is configured for Mesh with id"+ meshId);
78 }else if (meshid == 641){ 100 }
79 distance = 0.3; //Eisdaten Klima 101 }else{
102 log.warn("No MeshWidth configured. Check if this is correct.");
80 } 103 }
81 returnValue = center.buffer(distance,segments).toText(); 104 returnValue = center.buffer(distance,segments).toText();
82 } catch (NumberFormatException e) { 105 } catch (NumberFormatException e) {
83 log.error(e,e); 106 log.error(e,e);
84 } catch (ValidationException e) { 107 } catch (ValidationException e) {
120 } 143 }
121 144
122 protected static String convert2DisplayCoordinate(String wkt){ 145 protected static String convert2DisplayCoordinate(String wkt){
123 return WKTUtils.toText(wkt); 146 return WKTUtils.toText(wkt);
124 } 147 }
148
149 /**
150 * @see de.intevation.gnv.state.StateBase#setup(org.w3c.dom.Node)
151 */
152 @Override
153 public void setup(Node configuration) {
154 super.setup(configuration);
155 Element widthElement = (Element)Config.getNodeXPath(configuration, MESH_WIDTH_XPATH);
156
157 if (widthElement != null){
158 String fileName = widthElement.getAttribute(XLINK_XPATH);
159 fileName = Config.replaceConfigDir(fileName);
160 Node configurationNode = new ArtifactXMLUtilities().readConfiguration(fileName);
161 NodeList meshNodes = Config.getNodeSetXPath(configurationNode,MESH_LIST_XPATH );
162 if (meshNodes != null){
163 meshWidths = new HashMap<String, Double>(meshNodes.getLength());
164 for (int i = 0; i < meshNodes.getLength(); i++){
165 Element meshNode = (Element)meshNodes.item(i);
166 String id = meshNode.getAttribute(ID_XPATH);
167 Double value = Double.parseDouble(meshNode.getAttribute(WIDTH_VALUE_XPATH));
168 meshWidths.put(id, value);
169 }
170 }
171 }else{
172 log.warn("No Mesh Width defined.");
173 }
174 }
125 } 175 }

http://dive4elements.wald.intevation.org