# HG changeset patch # User Sascha L. Teichmann # Date 1262772591 0 # Node ID 92d6cf44859834a0fff1de009c9523a237aafcc7 # Parent 47ad9721e692ad1261ac32d036fa1e940264319c Improved raster tile based height evaluation. gnv-artifacts/trunk@512 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 47ad9721e692 -r 92d6cf448598 gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Tue Jan 05 14:12:03 2010 +0000 +++ b/gnv-artifacts/ChangeLog Wed Jan 06 10:09:51 2010 +0000 @@ -1,3 +1,12 @@ +2010-01-05 Sascha L. Teichmann + + * src/main/java/de/intevation/gnv/math/QueriedXYDepth.java: + - Simplified code + - Search tile cache in reversed order because its more likely + that last loaded tile is used more than once. + - Stores cached tiles under soft references to prevent the + possible case to flood the memory with hires tiles. + 2010-01-05 Tim Englich * src/main/java/de/intevation/gnv/math/QueriedXYDepth.java (depth): diff -r 47ad9721e692 -r 92d6cf448598 gnv-artifacts/src/main/java/de/intevation/gnv/math/QueriedXYDepth.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/QueriedXYDepth.java Tue Jan 05 14:12:03 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/QueriedXYDepth.java Wed Jan 06 10:09:51 2010 +0000 @@ -7,6 +7,8 @@ import java.util.Collection; import java.util.HashMap; +import java.lang.ref.SoftReference; + import org.apache.log4j.Logger; import com.vividsolutions.jts.geom.Coordinate; @@ -17,10 +19,11 @@ 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 - * + * @author Tim Englich (tim.englich@intevation.de) + * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) */ public class QueriedXYDepth implements XYDepth { @@ -29,62 +32,55 @@ */ private static Logger log = Logger.getLogger(QueriedXYDepth.class); - private String queryID = "rasterQuery"; + private static final String queryID = "rasterQuery"; - private QueryExecutor queryExecutor = null; + private QueryExecutor queryExecutor; - private ArrayList rasterData = new ArrayList(); + private ArrayList> rasterData; /** * Constructor */ public QueriedXYDepth() { - this.queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor(); + rasterData = new ArrayList>(); + queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor(); } /** * @see de.intevation.gnv.math.XYDepth#depth(com.vividsolutions.jts.geom.Coordinate) */ public double depth(Coordinate coordinate) { - log.debug("QueriedXYDepth.depth for " + coordinate.x+" "+ coordinate.y); double resultValue = Double.NaN; - RasterObject ro = this.getRasterObject(coordinate); + RasterObject ro = getRasterObject(coordinate); - if (ro == null){ - Collection result = null; + if (ro == null) { try { - String[] filterValues = new String[]{"Point ("+coordinate.x+" "+coordinate.y+")"}; - result = this.queryExecutor.executeQuery(this.queryID,filterValues); + String[] filterValues = new String[] { WKTUtils.toWKT(coordinate) }; + Collection result = queryExecutor.executeQuery(this.queryID,filterValues); + for (Result row: result) { + if ((ro = (RasterObject)row.getObject(0)) != null) { + rasterData.add(new SoftReference(ro)); + } + break; + } } catch (QueryException e) { - log.error(e,e); - } - - if (result != null){ - if (!result.isEmpty()){ - Result row = result.iterator().next(); - ro = (RasterObject)row.getObject(0); - synchronized (rasterData) { - rasterData.add(ro); - } - } + log.error(e, e); } } - if (ro != null){ - resultValue = ro.getValue(coordinate); - } - return resultValue; + return ro != null + ? ro.getValue(coordinate) + : Double.NaN; } private RasterObject getRasterObject(Coordinate coordinate){ - for (int i = 0; i < rasterData.size(); i++){ - RasterObject ro = rasterData.get(i); - if (ro.getEnvelope().contains(coordinate)){ + for (int i = rasterData.size()-1; i >= 0; --i) { + SoftReference ref = rasterData.get(i); + RasterObject ro = ref.get(); + if (ro != null && ro.getEnvelope().contains(coordinate)) { return ro; } } return null; - } - }