Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/math/QueriedXYDepth.java @ 875:5e9efdda6894
merged gnv-artifacts/1.0
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:56 +0200 |
parents | 05bf8534a35a |
children | f953c9a559d8 |
comparison
equal
deleted
inserted
replaced
722:bb3ffe7d719e | 875:5e9efdda6894 |
---|---|
1 package de.intevation.gnv.math; | |
2 | |
3 import com.vividsolutions.jts.geom.Coordinate; | |
4 | |
5 import de.intevation.gnv.geobackend.base.Result; | |
6 | |
7 import de.intevation.gnv.geobackend.base.query.QueryExecutor; | |
8 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; | |
9 | |
10 import de.intevation.gnv.geobackend.base.query.exception.QueryException; | |
11 | |
12 import de.intevation.gnv.geobackend.sde.datasources.RasterObject; | |
13 | |
14 import de.intevation.gnv.utils.WKTUtils; | |
15 | |
16 import java.lang.ref.SoftReference; | |
17 | |
18 import java.util.ArrayList; | |
19 import java.util.Collection; | |
20 | |
21 import org.apache.log4j.Logger; | |
22 | |
23 /** | |
24 * This implementation uses the geo backend to query a depth via | |
25 * a raster layer stored in the database. | |
26 * | |
27 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> | |
28 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> | |
29 */ | |
30 public class QueriedXYDepth | |
31 implements XYDepth | |
32 { | |
33 private static Logger log = Logger.getLogger(QueriedXYDepth.class); | |
34 | |
35 private static final String queryID = "rasterQuery"; | |
36 | |
37 private QueryExecutor queryExecutor; | |
38 | |
39 private ArrayList<SoftReference<RasterObject>> rasterData; | |
40 | |
41 private RasterObject last; | |
42 | |
43 private int interpolation; | |
44 | |
45 /** | |
46 * Default construtor. Interpolation method is bilinear. | |
47 */ | |
48 public QueriedXYDepth() { | |
49 this(RasterObject.BILINEAR); | |
50 } | |
51 | |
52 /** | |
53 * Constructor to create a QueriedXYDepth with a given interpolation | |
54 * method. | |
55 * @param interpolation The interpolation method. | |
56 */ | |
57 public QueriedXYDepth(int interpolation) { | |
58 this.interpolation = interpolation; | |
59 rasterData = new ArrayList<SoftReference<RasterObject>>(); | |
60 queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor(); | |
61 } | |
62 | |
63 public double depth(Coordinate coordinate) { | |
64 double resultValue = Double.NaN; | |
65 | |
66 RasterObject ro = getRasterObject(coordinate); | |
67 | |
68 if (ro == null) { | |
69 try { | |
70 String[] filterValues = | |
71 new String[] { WKTUtils.toWKT(coordinate) }; | |
72 Collection<Result> result = queryExecutor.executeQuery( | |
73 queryID, filterValues); | |
74 for (Result row: result) { | |
75 if ((ro = (RasterObject)row.getObject(0)) != null) { | |
76 rasterData.add( | |
77 new SoftReference<RasterObject>(last = ro)); | |
78 } | |
79 break; | |
80 } | |
81 } catch (QueryException e) { | |
82 log.error(e, e); | |
83 } | |
84 } | |
85 return ro != null | |
86 ? ro.getValue(coordinate, interpolation) | |
87 : Double.NaN; | |
88 } | |
89 | |
90 private RasterObject getRasterObject(Coordinate coordinate) { | |
91 if (last != null && last.contains(coordinate)) { | |
92 return last; | |
93 } | |
94 for (int i = rasterData.size()-1; i >= 0; --i) { | |
95 SoftReference<RasterObject> ref = rasterData.get(i); | |
96 RasterObject ro = ref.get(); | |
97 if (ro != null && ro.contains(coordinate)) { | |
98 return last = ro; | |
99 } | |
100 } | |
101 return null; | |
102 } | |
103 } |