comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java @ 352:24c21a720aa5

Added Support for "horizontale Schnittprofile" gnv-artifacts/trunk@425 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 15 Dec 2009 10:20:16 +0000
parents
children 25e4724aa504
comparison
equal deleted inserted replaced
351:4ac3c1c1c060 352:24c21a720aa5
1 /**
2 *
3 */
4 package de.intevation.gnv.state.profile.horizontal;
5
6 import java.util.ArrayList;
7 import java.util.Arrays;
8 import java.util.Collection;
9 import java.util.List;
10
11 import org.apache.log4j.Logger;
12 import org.w3c.dom.Node;
13
14 import com.vividsolutions.jts.geom.Coordinate;
15 import com.vividsolutions.jts.geom.LineString;
16 import com.vividsolutions.jts.io.ParseException;
17 import com.vividsolutions.jts.io.WKTReader;
18
19 import de.intevation.artifactdatabase.Config;
20 import de.intevation.gnv.artifacts.cache.CacheFactory;
21 import de.intevation.gnv.geobackend.base.Result;
22 import de.intevation.gnv.geobackend.base.query.QueryExecutor;
23 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory;
24 import de.intevation.gnv.geobackend.base.query.exception.QueryException;
25 import de.intevation.gnv.geobackend.sde.datasources.ResultSet;
26 import de.intevation.gnv.utils.IndexBuffer;
27
28 /**
29 * @author Tim Englich <tim.englich@intevation.de>
30 *
31 */
32 public class HorizontalProfileMeshCrossOutputState extends
33 HorizontalProfileOutputState {
34
35 /**
36 *
37 */
38 private static final long serialVersionUID = 2205958041745637263L;
39
40 /**
41 * the logger, used to log exceptions and additonaly information
42 */
43 private static Logger log =
44 Logger.getLogger(HorizontalProfileMeshCrossOutputState.class);
45
46
47 private String ijkQueryID = null;
48
49 /**
50 * Constructor
51 */
52 public HorizontalProfileMeshCrossOutputState() {
53 super();
54 }
55
56 /**
57 * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#setup(org.w3c.dom.Node)
58 */
59 @Override
60 public void setup(Node configuration) {
61 super.setup(configuration);
62 this.ijkQueryID = Config.getStringXPath(configuration,"queryID-ijk");
63
64 }
65
66 @Override
67 protected Collection<Result> getChartResult(String uuid) {
68 log.debug("OutputStateBase.getChartResult");
69 Collection<Result> result = null;
70 if (CacheFactory.getInstance().isInitialized()) {
71 String key = uuid + super.getID();
72 log.debug("Hash for Queryelements: " + key);
73 net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key);
74 if (value != null) {
75 result = (Collection<Result>) (value.getObjectValue());
76 }else{
77
78 if (this.inputData.containsKey("mesh_linestring")){
79
80 try {
81 // 1. IJK Anfragen für Stützpunkte im Netz ausführen.
82 LineString ls = (LineString)new WKTReader().read(this.inputData
83 .get("mesh_linestring")
84 .getValue());
85 Coordinate[] coords = ls.getCoordinates();
86
87 List<java.awt.Point> points = new ArrayList<java.awt.Point>(coords.length);
88
89 String meshid = this.inputData.get("meshid").getValue();
90 QueryExecutor queryExecutor = QueryExecutorFactory
91 .getInstance()
92 .getQueryExecutor();
93 for (int i = 0; i < coords.length; i++){
94 String wkt = "POINT( "+coords[i].x+" "+coords[i].y+" )";
95
96 result = queryExecutor.executeQuery(this.ijkQueryID,
97 new String[]{meshid,wkt});
98 if (!result.isEmpty()){
99 Result resultValue = result.iterator().next();
100 int iPos = resultValue.getInteger(1);
101 int jPos = resultValue.getInteger(0);
102 log.debug("Found Pos "+iPos+"/"+jPos +" for "+wkt);
103 points.add(i, new java.awt.Point(iPos,jPos));
104 }else{
105 log.debug("No i/j Pos found for "+wkt);
106 points.add(i, null);
107 // Special Case no i,j found for Coordinate
108 }
109 }
110 // TODO: Make Tablenames and Columns Configurable
111 IndexBuffer ib = new IndexBuffer(points, "MEDIAN.MESHPOINT.IPOSITION", " MEDIAN.MESHPOINT.JPOSITION" );
112 String additionWhere = ib.toWhereClause();
113 log.debug("Additional Where Clause = "+additionWhere);
114 // 2. Aus diesen Stützpunkten den Resultset generieren.
115
116 String[] filterValues = this.generateFilterValuesFromInputData();
117 String[] addedFilterValues = new String[filterValues.length+1];
118 System.arraycopy(filterValues, 0, addedFilterValues, 0, filterValues.length);
119 addedFilterValues[filterValues.length] = additionWhere;
120
121 result = queryExecutor.executeQuery(this.queryID,
122 addedFilterValues);
123
124
125 } catch (ParseException e) {
126 log.error(e,e);
127 }catch (QueryException e) {
128 log.error(e,e);
129 }
130 }else{
131 // TODO: definieren was passiert wenn kein linestring vorhanden ist.
132 }
133
134 if (CacheFactory.getInstance().isInitialized()) {
135 CacheFactory.getInstance().getCache().put(new net.sf.ehcache.Element(key, result));
136 }
137
138 }
139 }
140 return result;
141 }
142
143
144
145 }

http://dive4elements.wald.intevation.org