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