annotate gnv-artifacts/src/main/java/de/intevation/gnv/math/QueriedXYDepth.java @ 779:b1f5f2a8840f

Ordered imports. Removed needless imports. Removed empty headers. gnv-artifacts/trunk@854 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 29 Mar 2010 08:51:20 +0000
parents 9a828e5a2390
children c4156275c1e1
rev   line source
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.math;
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
2
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
3 import com.vividsolutions.jts.geom.Coordinate;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
4
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
5 import de.intevation.gnv.geobackend.base.Result;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
6
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
7 import de.intevation.gnv.geobackend.base.query.QueryExecutor;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
8 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
9
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
10 import de.intevation.gnv.geobackend.base.query.exception.QueryException;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
11
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
12 import de.intevation.gnv.geobackend.sde.datasources.RasterObject;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
13
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
14 import de.intevation.gnv.utils.WKTUtils;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
15
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
16 import java.lang.ref.SoftReference;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
17
457
47ad9721e692 Added RasterObject for caching the Rastertiles to get a better performance.
Tim Englich <tim.englich@intevation.de>
parents: 455
diff changeset
18 import java.util.ArrayList;
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
19 import java.util.Collection;
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
20
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
21 import org.apache.log4j.Logger;
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);
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
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";
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
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;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
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;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
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;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
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);
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
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)
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
78 : Double.NaN;
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
79 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
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