Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/math/QueriedXYDepth.java @ 458:92d6cf448598
Improved raster tile based height evaluation.
gnv-artifacts/trunk@512 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 06 Jan 2010 10:09:51 +0000 |
parents | 47ad9721e692 |
children | 912797826099 |
comparison
equal
deleted
inserted
replaced
457:47ad9721e692 | 458:92d6cf448598 |
---|---|
4 package de.intevation.gnv.math; | 4 package de.intevation.gnv.math; |
5 | 5 |
6 import java.util.ArrayList; | 6 import java.util.ArrayList; |
7 import java.util.Collection; | 7 import java.util.Collection; |
8 import java.util.HashMap; | 8 import java.util.HashMap; |
9 | |
10 import java.lang.ref.SoftReference; | |
9 | 11 |
10 import org.apache.log4j.Logger; | 12 import org.apache.log4j.Logger; |
11 | 13 |
12 import com.vividsolutions.jts.geom.Coordinate; | 14 import com.vividsolutions.jts.geom.Coordinate; |
13 | 15 |
15 import de.intevation.gnv.geobackend.base.query.QueryExecutor; | 17 import de.intevation.gnv.geobackend.base.query.QueryExecutor; |
16 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; | 18 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; |
17 import de.intevation.gnv.geobackend.base.query.exception.QueryException; | 19 import de.intevation.gnv.geobackend.base.query.exception.QueryException; |
18 import de.intevation.gnv.geobackend.sde.datasources.RasterObject; | 20 import de.intevation.gnv.geobackend.sde.datasources.RasterObject; |
19 | 21 |
22 import de.intevation.gnv.utils.WKTUtils; | |
20 | 23 |
21 /** | 24 /** |
22 * @author Tim Englich <tim.englich@intevation.de> | 25 * @author Tim Englich (tim.englich@intevation.de) |
23 * | 26 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) |
24 */ | 27 */ |
25 public class QueriedXYDepth implements XYDepth { | 28 public class QueriedXYDepth implements XYDepth { |
26 | 29 |
27 /** | 30 /** |
28 * the logger, used to log exceptions and additonaly information | 31 * the logger, used to log exceptions and additonaly information |
29 */ | 32 */ |
30 private static Logger log = Logger.getLogger(QueriedXYDepth.class); | 33 private static Logger log = Logger.getLogger(QueriedXYDepth.class); |
31 | 34 |
32 private String queryID = "rasterQuery"; | 35 private static final String queryID = "rasterQuery"; |
33 | 36 |
34 private QueryExecutor queryExecutor = null; | 37 private QueryExecutor queryExecutor; |
35 | 38 |
36 private ArrayList<RasterObject> rasterData = new ArrayList<RasterObject>(); | 39 private ArrayList<SoftReference<RasterObject>> rasterData; |
37 | 40 |
38 /** | 41 /** |
39 * Constructor | 42 * Constructor |
40 */ | 43 */ |
41 public QueriedXYDepth() { | 44 public QueriedXYDepth() { |
42 this.queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor(); | 45 rasterData = new ArrayList<SoftReference<RasterObject>>(); |
46 queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor(); | |
43 } | 47 } |
44 | 48 |
45 /** | 49 /** |
46 * @see de.intevation.gnv.math.XYDepth#depth(com.vividsolutions.jts.geom.Coordinate) | 50 * @see de.intevation.gnv.math.XYDepth#depth(com.vividsolutions.jts.geom.Coordinate) |
47 */ | 51 */ |
48 public double depth(Coordinate coordinate) { | 52 public double depth(Coordinate coordinate) { |
49 log.debug("QueriedXYDepth.depth for " + coordinate.x+" "+ coordinate.y); | |
50 double resultValue = Double.NaN; | 53 double resultValue = Double.NaN; |
51 | 54 |
52 RasterObject ro = this.getRasterObject(coordinate); | 55 RasterObject ro = getRasterObject(coordinate); |
53 | 56 |
54 if (ro == null){ | 57 if (ro == null) { |
55 Collection<Result> result = null; | |
56 try { | 58 try { |
57 String[] filterValues = new String[]{"Point ("+coordinate.x+" "+coordinate.y+")"}; | 59 String[] filterValues = new String[] { WKTUtils.toWKT(coordinate) }; |
58 result = this.queryExecutor.executeQuery(this.queryID,filterValues); | 60 Collection<Result> result = queryExecutor.executeQuery(this.queryID,filterValues); |
61 for (Result row: result) { | |
62 if ((ro = (RasterObject)row.getObject(0)) != null) { | |
63 rasterData.add(new SoftReference<RasterObject>(ro)); | |
64 } | |
65 break; | |
66 } | |
59 } catch (QueryException e) { | 67 } catch (QueryException e) { |
60 log.error(e,e); | 68 log.error(e, e); |
61 } | |
62 | |
63 if (result != null){ | |
64 if (!result.isEmpty()){ | |
65 Result row = result.iterator().next(); | |
66 ro = (RasterObject)row.getObject(0); | |
67 synchronized (rasterData) { | |
68 rasterData.add(ro); | |
69 } | |
70 } | |
71 } | 69 } |
72 } | 70 } |
73 if (ro != null){ | 71 return ro != null |
74 resultValue = ro.getValue(coordinate); | 72 ? ro.getValue(coordinate) |
75 } | 73 : Double.NaN; |
76 return resultValue; | |
77 } | 74 } |
78 | 75 |
79 private RasterObject getRasterObject(Coordinate coordinate){ | 76 private RasterObject getRasterObject(Coordinate coordinate){ |
80 for (int i = 0; i < rasterData.size(); i++){ | 77 for (int i = rasterData.size()-1; i >= 0; --i) { |
81 RasterObject ro = rasterData.get(i); | 78 SoftReference<RasterObject> ref = rasterData.get(i); |
82 if (ro.getEnvelope().contains(coordinate)){ | 79 RasterObject ro = ref.get(); |
80 if (ro != null && ro.getEnvelope().contains(coordinate)) { | |
83 return ro; | 81 return ro; |
84 } | 82 } |
85 } | 83 } |
86 return null; | 84 return null; |
87 | |
88 } | 85 } |
89 | |
90 } | 86 } |