annotate gnv-artifacts/src/main/java/de/intevation/gnv/math/QueriedXYDepth.java @ 867:35c3e82f7eaa

Changed the default directory of the artifact database. gnv-artifacts/trunk@1006 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 27 Apr 2010 15:11:16 +0000
parents 05bf8534a35a
children f953c9a559d8
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 /**
805
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
24 * This implementation uses the geo backend to query a depth via
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
25 * a raster layer stored in the database.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
26 *
780
c4156275c1e1 Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 779
diff changeset
27 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
c4156275c1e1 Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 779
diff changeset
28 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
29 */
805
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
30 public class QueriedXYDepth
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
31 implements XYDepth
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
32 {
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
33 private static Logger log = Logger.getLogger(QueriedXYDepth.class);
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
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";
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
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;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
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;
462
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
40
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
41 private RasterObject last;
463
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
42
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
43 private int interpolation;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
44
805
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
45 /**
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
46 * Default construtor. Interpolation method is bilinear.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
47 */
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
48 public QueriedXYDepth() {
463
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
49 this(RasterObject.BILINEAR);
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
50 }
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
51
805
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
52 /**
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
53 * Constructor to create a QueriedXYDepth with a given interpolation
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
54 * method.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
55 * @param interpolation The interpolation method.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
56 */
463
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
57 public QueriedXYDepth(int interpolation) {
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
58 this.interpolation = interpolation;
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
59 rasterData = new ArrayList<SoftReference<RasterObject>>();
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
60 queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor();
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
61 }
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
62
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
63 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
64 double resultValue = Double.NaN;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
65
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
66 RasterObject ro = getRasterObject(coordinate);
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
67
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
68 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
69 try {
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
70 String[] filterValues =
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
71 new String[] { WKTUtils.toWKT(coordinate) };
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
72 Collection<Result> result = queryExecutor.executeQuery(
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
73 queryID, filterValues);
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
74 for (Result row: result) {
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
75 if ((ro = (RasterObject)row.getObject(0)) != null) {
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
76 rasterData.add(
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
77 new SoftReference<RasterObject>(last = ro));
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
78 }
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
79 break;
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
80 }
457
47ad9721e692 Added RasterObject for caching the Rastertiles to get a better performance.
Tim Englich <tim.englich@intevation.de>
parents: 455
diff changeset
81 } catch (QueryException e) {
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
82 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
83 }
47ad9721e692 Added RasterObject for caching the Rastertiles to get a better performance.
Tim Englich <tim.englich@intevation.de>
parents: 455
diff changeset
84 }
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
85 return ro != null
463
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
86 ? ro.getValue(coordinate, interpolation)
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
87 : Double.NaN;
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
88 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
89
463
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
90 private RasterObject getRasterObject(Coordinate coordinate) {
462
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
91 if (last != null && last.contains(coordinate)) {
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
92 return last;
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
93 }
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
94 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
95 SoftReference<RasterObject> ref = rasterData.get(i);
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
96 RasterObject ro = ref.get();
462
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
97 if (ro != null && ro.contains(coordinate)) {
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
98 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
99 }
47ad9721e692 Added RasterObject for caching the Rastertiles to get a better performance.
Tim Englich <tim.englich@intevation.de>
parents: 455
diff changeset
100 }
47ad9721e692 Added RasterObject for caching the Rastertiles to get a better performance.
Tim Englich <tim.englich@intevation.de>
parents: 455
diff changeset
101 return null;
47ad9721e692 Added RasterObject for caching the Rastertiles to get a better performance.
Tim Englich <tim.englich@intevation.de>
parents: 455
diff changeset
102 }
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 805
diff changeset
103 }

http://dive4elements.wald.intevation.org