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