annotate gnv-artifacts/src/main/java/de/intevation/gnv/math/QueriedXYDepth.java @ 745:d194939ecbaf

Improvement: Values of Type Geometry which are Points will be prepared as Regions for DB-Query. gnv-artifacts/trunk@785 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 16 Mar 2010 12:53:37 +0000
parents f7038820df2e
children 9a828e5a2390
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;
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
8
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
9 import java.lang.ref.SoftReference;
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
10
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
11 import org.apache.log4j.Logger;
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
12
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
13 import com.vividsolutions.jts.geom.Coordinate;
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
14
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
15 import de.intevation.gnv.geobackend.base.Result;
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
16 import de.intevation.gnv.geobackend.base.query.QueryExecutor;
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
17 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory;
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
18 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
19 import de.intevation.gnv.geobackend.sde.datasources.RasterObject;
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
20
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
21 import de.intevation.gnv.utils.WKTUtils;
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
22
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
23 /**
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
24 * @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
25 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
26 */
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
27 public class QueriedXYDepth implements XYDepth {
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
28
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 * the logger, used to log exceptions and additonaly information
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
31 */
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
32 private static Logger log = Logger.getLogger(QueriedXYDepth.class);
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
33
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
34 private static final String queryID = "rasterQuery";
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
35
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
36 private QueryExecutor queryExecutor;
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
37
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
38 private ArrayList<SoftReference<RasterObject>> rasterData;
462
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
39
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
40 private RasterObject last;
463
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
41
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
42 private int interpolation;
457
47ad9721e692 Added RasterObject for caching the Rastertiles to get a better performance.
Tim Englich <tim.englich@intevation.de>
parents: 455
diff changeset
43
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
44 public QueriedXYDepth() {
463
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
45 this(RasterObject.BILINEAR);
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
46 }
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
47
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
48 public QueriedXYDepth(int interpolation) {
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
49 this.interpolation = interpolation;
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
50 rasterData = new ArrayList<SoftReference<RasterObject>>();
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
51 queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor();
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
52 }
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
53
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
54 /**
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
55 * @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
56 */
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
57 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
58 double resultValue = Double.NaN;
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
59
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
60 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
61
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
62 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
63 try {
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
64 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
65 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
66 for (Result row: result) {
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
67 if ((ro = (RasterObject)row.getObject(0)) != null) {
462
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
68 rasterData.add(new SoftReference<RasterObject>(last = ro));
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
69 }
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
70 break;
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
71 }
457
47ad9721e692 Added RasterObject for caching the Rastertiles to get a better performance.
Tim Englich <tim.englich@intevation.de>
parents: 455
diff changeset
72 } catch (QueryException e) {
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
73 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
74 }
47ad9721e692 Added RasterObject for caching the Rastertiles to get a better performance.
Tim Englich <tim.englich@intevation.de>
parents: 455
diff changeset
75 }
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
76 return ro != null
463
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
77 ? ro.getValue(coordinate, interpolation)
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
78 : Double.NaN;
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
79 }
457
47ad9721e692 Added RasterObject for caching the Rastertiles to get a better performance.
Tim Englich <tim.englich@intevation.de>
parents: 455
diff changeset
80
463
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
81 private RasterObject getRasterObject(Coordinate coordinate) {
462
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
82 if (last != null && last.contains(coordinate)) {
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
83 return last;
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
84 }
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
85 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
86 SoftReference<RasterObject> ref = rasterData.get(i);
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
87 RasterObject ro = ref.get();
462
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
88 if (ro != null && ro.contains(coordinate)) {
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
89 return last = ro;
457
47ad9721e692 Added RasterObject for caching the Rastertiles to get a better performance.
Tim Englich <tim.englich@intevation.de>
parents: 455
diff changeset
90 }
47ad9721e692 Added RasterObject for caching the Rastertiles to get a better performance.
Tim Englich <tim.englich@intevation.de>
parents: 455
diff changeset
91 }
47ad9721e692 Added RasterObject for caching the Rastertiles to get a better performance.
Tim Englich <tim.englich@intevation.de>
parents: 455
diff changeset
92 return null;
47ad9721e692 Added RasterObject for caching the Rastertiles to get a better performance.
Tim Englich <tim.englich@intevation.de>
parents: 455
diff changeset
93 }
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
94 }

http://dive4elements.wald.intevation.org