# HG changeset patch # User Tim Englich # Date 1262700723 0 # Node ID 47ad9721e692ad1261ac32d036fa1e940264319c # Parent b8080695ea62ad554b75acb95a98909dde082f1c Added RasterObject for caching the Rastertiles to get a better performance. gnv-artifacts/trunk@509 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r b8080695ea62 -r 47ad9721e692 gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Mon Jan 04 15:41:29 2010 +0000 +++ b/gnv-artifacts/ChangeLog Tue Jan 05 14:12:03 2010 +0000 @@ -1,3 +1,9 @@ +2010-01-05 Tim Englich + + * src/main/java/de/intevation/gnv/math/QueriedXYDepth.java (depth): + Added the usage of the new RasterObject integrated in the geo-backend. + Now the Performance is much better accessing the depth to an coordinate. + 2010-01-04 Ingo Weinzierl * src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java: Declared diff -r b8080695ea62 -r 47ad9721e692 gnv-artifacts/src/main/java/de/intevation/gnv/math/QueriedXYDepth.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/QueriedXYDepth.java Mon Jan 04 15:41:29 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/QueriedXYDepth.java Tue Jan 05 14:12:03 2010 +0000 @@ -3,7 +3,9 @@ */ package de.intevation.gnv.math; +import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import org.apache.log4j.Logger; @@ -13,6 +15,7 @@ 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; /** @@ -30,6 +33,8 @@ private QueryExecutor queryExecutor = null; + private ArrayList rasterData = new ArrayList(); + /** * Constructor */ @@ -42,26 +47,44 @@ */ public double depth(Coordinate coordinate) { log.debug("QueriedXYDepth.depth for " + coordinate.x+" "+ coordinate.y); - double resultValue = 0; - Collection result = null; - try { - String[] filterValues = new String[]{"Point ("+coordinate.x+" "+coordinate.y+")"}; - result = this.queryExecutor.executeQuery(this.queryID,filterValues); - } catch (QueryException e) { - log.error(e,e); - } + double resultValue = Double.NaN; - if (result != null){ - if (!result.isEmpty()){ - Result row = result.iterator().next(); - resultValue = row.getDouble(0); - }else{ - resultValue = Double.NaN; + RasterObject ro = this.getRasterObject(coordinate); + + if (ro == null){ + Collection result = null; + try { + String[] filterValues = new String[]{"Point ("+coordinate.x+" "+coordinate.y+")"}; + result = this.queryExecutor.executeQuery(this.queryID,filterValues); + } catch (QueryException e) { + log.error(e,e); } - }else{ - resultValue = Double.NaN; + + if (result != null){ + if (!result.isEmpty()){ + Result row = result.iterator().next(); + ro = (RasterObject)row.getObject(0); + synchronized (rasterData) { + rasterData.add(ro); + } + } + } + } + if (ro != null){ + resultValue = ro.getValue(coordinate); } return resultValue; } + + private RasterObject getRasterObject(Coordinate coordinate){ + for (int i = 0; i < rasterData.size(); i++){ + RasterObject ro = rasterData.get(i); + if (ro.getEnvelope().contains(coordinate)){ + return ro; + } + } + return null; + + } }