Mercurial > dive4elements > gnv-client
view 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 |
line wrap: on
line source
/** * */ package de.intevation.gnv.state.profile.horizontal; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import org.apache.log4j.Logger; import org.w3c.dom.Node; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.LineString; import com.vividsolutions.jts.io.ParseException; import com.vividsolutions.jts.io.WKTReader; import de.intevation.artifactdatabase.Config; import de.intevation.gnv.artifacts.cache.CacheFactory; import de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.geobackend.base.query.QueryExecutor; import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; import de.intevation.gnv.geobackend.base.query.exception.QueryException; import de.intevation.gnv.geobackend.sde.datasources.ResultSet; import de.intevation.gnv.utils.IndexBuffer; /** * @author Tim Englich <tim.englich@intevation.de> * */ public class HorizontalProfileMeshCrossOutputState extends HorizontalProfileOutputState { /** * */ private static final long serialVersionUID = 2205958041745637263L; /** * the logger, used to log exceptions and additonaly information */ private static Logger log = Logger.getLogger(HorizontalProfileMeshCrossOutputState.class); private String ijkQueryID = null; /** * Constructor */ public HorizontalProfileMeshCrossOutputState() { super(); } /** * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#setup(org.w3c.dom.Node) */ @Override public void setup(Node configuration) { super.setup(configuration); this.ijkQueryID = Config.getStringXPath(configuration,"queryID-ijk"); } @Override protected Collection<Result> getChartResult(String uuid) { log.debug("OutputStateBase.getChartResult"); Collection<Result> result = null; if (CacheFactory.getInstance().isInitialized()) { String key = uuid + super.getID(); log.debug("Hash for Queryelements: " + key); net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key); if (value != null) { result = (Collection<Result>) (value.getObjectValue()); }else{ if (this.inputData.containsKey("mesh_linestring")){ try { // 1. IJK Anfragen f�r St�tzpunkte im Netz ausf�hren. LineString ls = (LineString)new WKTReader().read(this.inputData .get("mesh_linestring") .getValue()); Coordinate[] coords = ls.getCoordinates(); List<java.awt.Point> points = new ArrayList<java.awt.Point>(coords.length); String meshid = this.inputData.get("meshid").getValue(); QueryExecutor queryExecutor = QueryExecutorFactory .getInstance() .getQueryExecutor(); for (int i = 0; i < coords.length; i++){ String wkt = "POINT( "+coords[i].x+" "+coords[i].y+" )"; result = queryExecutor.executeQuery(this.ijkQueryID, new String[]{meshid,wkt}); if (!result.isEmpty()){ Result resultValue = result.iterator().next(); int iPos = resultValue.getInteger(1); int jPos = resultValue.getInteger(0); log.debug("Found Pos "+iPos+"/"+jPos +" for "+wkt); points.add(i, new java.awt.Point(iPos,jPos)); }else{ log.debug("No i/j Pos found for "+wkt); points.add(i, null); // Special Case no i,j found for Coordinate } } // TODO: Make Tablenames and Columns Configurable IndexBuffer ib = new IndexBuffer(points, "MEDIAN.MESHPOINT.IPOSITION", " MEDIAN.MESHPOINT.JPOSITION" ); String additionWhere = ib.toWhereClause(); log.debug("Additional Where Clause = "+additionWhere); // 2. Aus diesen St�tzpunkten den Resultset generieren. String[] filterValues = this.generateFilterValuesFromInputData(); String[] addedFilterValues = new String[filterValues.length+1]; System.arraycopy(filterValues, 0, addedFilterValues, 0, filterValues.length); addedFilterValues[filterValues.length] = additionWhere; result = queryExecutor.executeQuery(this.queryID, addedFilterValues); } catch (ParseException e) { log.error(e,e); }catch (QueryException e) { log.error(e,e); } }else{ // TODO: definieren was passiert wenn kein linestring vorhanden ist. } if (CacheFactory.getInstance().isInitialized()) { CacheFactory.getInstance().getCache().put(new net.sf.ehcache.Element(key, result)); } } } return result; } }