Mercurial > dive4elements > gnv-client
view gnv-artifacts/src/main/java/de/intevation/gnv/math/QueriedXYDepth.java @ 461:3ddc22aab764
Removed Encodingerrors from listed Files. All Files are now UTF-8 compliant.
ISSUE137
gnv-artifacts/trunk@515 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Fri, 08 Jan 2010 14:27:49 +0000 |
parents | 92d6cf448598 |
children | 912797826099 |
line wrap: on
line source
/** * */ package de.intevation.gnv.math; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.lang.ref.SoftReference; import org.apache.log4j.Logger; import com.vividsolutions.jts.geom.Coordinate; 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.RasterObject; import de.intevation.gnv.utils.WKTUtils; /** * @author Tim Englich (tim.englich@intevation.de) * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) */ public class QueriedXYDepth implements XYDepth { /** * the logger, used to log exceptions and additonaly information */ private static Logger log = Logger.getLogger(QueriedXYDepth.class); private static final String queryID = "rasterQuery"; private QueryExecutor queryExecutor; private ArrayList<SoftReference<RasterObject>> rasterData; /** * Constructor */ public QueriedXYDepth() { rasterData = new ArrayList<SoftReference<RasterObject>>(); queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor(); } /** * @see de.intevation.gnv.math.XYDepth#depth(com.vividsolutions.jts.geom.Coordinate) */ public double depth(Coordinate coordinate) { double resultValue = Double.NaN; RasterObject ro = getRasterObject(coordinate); if (ro == null) { try { String[] filterValues = new String[] { WKTUtils.toWKT(coordinate) }; Collection<Result> result = queryExecutor.executeQuery(this.queryID,filterValues); for (Result row: result) { if ((ro = (RasterObject)row.getObject(0)) != null) { rasterData.add(new SoftReference<RasterObject>(ro)); } break; } } catch (QueryException e) { log.error(e, e); } } return ro != null ? ro.getValue(coordinate) : Double.NaN; } private RasterObject getRasterObject(Coordinate coordinate){ for (int i = rasterData.size()-1; i >= 0; --i) { SoftReference<RasterObject> ref = rasterData.get(i); RasterObject ro = ref.get(); if (ro != null && ro.getEnvelope().contains(coordinate)) { return ro; } } return null; } }