annotate gnv-artifacts/src/main/java/de/intevation/gnv/math/QueriedXYDepth.java @ 1116:2d393d79c097

Added author names. gnv-artifacts/trunk@1262 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 04 Nov 2010 21:46:58 +0000
parents f953c9a559d8
children
rev   line source
1115
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
1 /*
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
2 * Copyright (c) 2010 by Intevation GmbH
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
3 *
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
4 * This program is free software under the LGPL (>=v2.1)
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
5 * Read the file LGPL.txt coming with the software for details
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
7 */
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
8
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
9 package de.intevation.gnv.math;
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
10
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
11 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
12
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
13 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
14
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
15 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
16 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
17
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
18 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
19
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
20 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
21
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
22 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
23
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
24 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
25
457
47ad9721e692 Added RasterObject for caching the Rastertiles to get a better performance.
Tim Englich <tim.englich@intevation.de>
parents: 455
diff changeset
26 import java.util.ArrayList;
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
27 import java.util.Collection;
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 import org.apache.log4j.Logger;
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 /**
805
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
32 * 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
33 * 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
34 *
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
35 * @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
36 * @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
37 */
805
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
38 public class QueriedXYDepth
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
39 implements XYDepth
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
40 {
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
41 private static Logger log = Logger.getLogger(QueriedXYDepth.class);
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
42
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
43 private static final String queryID = "rasterQuery";
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
44
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
45 private QueryExecutor queryExecutor;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
46
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
47 private ArrayList<SoftReference<RasterObject>> rasterData;
462
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
48
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
49 private RasterObject last;
463
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 private int interpolation;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
52
805
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
53 /**
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
54 * Default construtor. Interpolation method is bilinear.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
55 */
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
56 public QueriedXYDepth() {
463
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
57 this(RasterObject.BILINEAR);
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
58 }
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
59
805
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
60 /**
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
61 * 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
62 * method.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
63 * @param interpolation The interpolation method.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
64 */
463
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
65 public QueriedXYDepth(int interpolation) {
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
66 this.interpolation = interpolation;
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
67 rasterData = new ArrayList<SoftReference<RasterObject>>();
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
68 queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor();
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
69 }
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
70
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
71 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
72 double resultValue = Double.NaN;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
73
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
74 RasterObject ro = getRasterObject(coordinate);
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
75
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
76 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
77 try {
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
78 String[] filterValues =
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
79 new String[] { WKTUtils.toWKT(coordinate) };
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
80 Collection<Result> result = queryExecutor.executeQuery(
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
81 queryID, filterValues);
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
82 for (Result row: result) {
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
83 if ((ro = (RasterObject)row.getObject(0)) != null) {
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
84 rasterData.add(
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
85 new SoftReference<RasterObject>(last = ro));
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
86 }
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
87 break;
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
88 }
457
47ad9721e692 Added RasterObject for caching the Rastertiles to get a better performance.
Tim Englich <tim.englich@intevation.de>
parents: 455
diff changeset
89 } catch (QueryException e) {
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
90 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
91 }
47ad9721e692 Added RasterObject for caching the Rastertiles to get a better performance.
Tim Englich <tim.englich@intevation.de>
parents: 455
diff changeset
92 }
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
93 return ro != null
463
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
94 ? ro.getValue(coordinate, interpolation)
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
95 : Double.NaN;
455
363236fc462d Added Rasterdatasupport to VerticalCrossSections
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
96 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
97
463
07672838fa5f Make ground interpolation for vertical cross section configurable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 462
diff changeset
98 private RasterObject getRasterObject(Coordinate coordinate) {
462
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
99 if (last != null && last.contains(coordinate)) {
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
100 return last;
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
101 }
458
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
102 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
103 SoftReference<RasterObject> ref = rasterData.get(i);
92d6cf448598 Improved raster tile based height evaluation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 457
diff changeset
104 RasterObject ro = ref.get();
462
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
105 if (ro != null && ro.contains(coordinate)) {
912797826099 Use new raster access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
106 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
107 }
47ad9721e692 Added RasterObject for caching the Rastertiles to get a better performance.
Tim Englich <tim.englich@intevation.de>
parents: 455
diff changeset
108 }
47ad9721e692 Added RasterObject for caching the Rastertiles to get a better performance.
Tim Englich <tim.englich@intevation.de>
parents: 455
diff changeset
109 return null;
47ad9721e692 Added RasterObject for caching the Rastertiles to get a better performance.
Tim Englich <tim.englich@intevation.de>
parents: 455
diff changeset
110 }
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 805
diff changeset
111 }

http://dive4elements.wald.intevation.org