Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/CrossSectionKMService.java @ 2013:9d5f339d83a3
#380 Validate the user selected DEM in the server.
flys-artifacts/trunk@3462 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 19 Dec 2011 10:01:17 +0000 |
parents | e0b081105a82 |
children | f021080cb409 |
rev | line source |
---|---|
1749
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.services; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import de.intevation.artifacts.CallMeta; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 import de.intevation.artifacts.GlobalContext; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 import de.intevation.artifacts.common.utils.XMLUtils; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 import de.intevation.flys.artifacts.cache.CacheFactory; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 import de.intevation.flys.backend.SessionHolder; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 import de.intevation.flys.model.CrossSection; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 import de.intevation.flys.model.CrossSectionLine; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
1961
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
15 import java.util.AbstractMap; |
1749
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import java.util.ArrayDeque; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import java.util.Deque; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 import java.util.List; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 import java.util.Map; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 import java.util.NavigableMap; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 import java.util.concurrent.ConcurrentSkipListMap; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 import net.sf.ehcache.Cache; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 import org.apache.log4j.Logger; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 import org.hibernate.Query; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 import org.hibernate.Session; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 import org.w3c.dom.Document; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 import org.w3c.dom.Element; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 import org.w3c.dom.NodeList; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 |
1961
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
35 |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
36 /** |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
37 * Service to find the next/previous km (measurement) of cross sections. |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
38 * Looking at the query for a single cross-section id at a single km, the |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
39 * service does the following: |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
40 * |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
41 * It returns the km itself if a measurement at that km was found and |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
42 * the N nearest other measurement points in both directions. |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
43 * |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
44 * That means, you can pass N=0 to find out whether a measurement at given km |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
45 * exists. |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
46 * |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
47 * If less than N neighbours exist in one direction, less are delivered |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
48 * (e.g. given measurements at [0,2,3,4,5,7,8,9] a query for km=8, N=3 will |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
49 * result in [4,5,7,8,9]). |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
50 */ |
1749
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 public class CrossSectionKMService |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 extends FLYSService |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 private static Logger logger = |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 Logger.getLogger(CrossSectionKMService.class); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 public static final String CACHE_NAME = "cross-section-kms"; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 |
1961
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
59 |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
60 /** Trivial constructor. */ |
1749
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 public CrossSectionKMService() { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 |
1961
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
64 |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
65 /** |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
66 * @param data |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
67 */ |
1749
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 @Override |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 public Document doProcess( |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 Document data, |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 GlobalContext globalContext, |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 CallMeta callMeta |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 ) { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 logger.debug("CrossSectionKMService.doProcess"); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 NodeList crossSectionNodes = |
1961
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
77 data.getElementsByTagName("art:cross-section"); |
1749
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 Cache cache = CacheFactory.getCache(CACHE_NAME); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 Document document = XMLUtils.newDocument(); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 Element all = document.createElement("cross-sections"); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 for (int i = 0, CS = crossSectionNodes.getLength(); i < CS; ++i) { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 Element crossSectionElement = (Element)crossSectionNodes.item(i); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 String idString = crossSectionElement.getAttribute("id"); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 String kmString = crossSectionElement.getAttribute("km"); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 String neighborsString = crossSectionElement.getAttribute("n"); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 if (idString.length() == 0 || kmString.length() == 0) { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 logger.debug("missing attributes in cross-section element"); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 continue; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 double km; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 Integer crossSectionId; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 int N = 2; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 try { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 km = Double.parseDouble(kmString); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 crossSectionId = Integer.valueOf(idString); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 if (neighborsString.length() > 0) { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 N = Integer.parseInt(neighborsString); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 catch (NumberFormatException nfe) { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 logger.debug("converting number failed", nfe); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 continue; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 NavigableMap<Double, Integer> map; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 if (cache == null) { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 map = getUncached(crossSectionId); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 else { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 net.sf.ehcache.Element element = cache.get(crossSectionId); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 if (element == null) { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 map = getUncached(crossSectionId); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 if (map != null) { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 element = new net.sf.ehcache.Element( |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 crossSectionId, map); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 cache.put(element); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 else { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 map = (NavigableMap<Double, Integer>)element.getValue(); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 if (map == null) { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 logger.debug("cannot find cross section " + crossSectionId); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 continue; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 Deque<Map.Entry<Double, Integer>> result = |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 nearestNeighbors(map, km, N); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 if (!result.isEmpty()) { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 Element csE = document.createElement("cross-section"); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 csE.setAttribute("id", idString); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 for (Map.Entry<Double, Integer> entry: result) { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 Element lineE = document.createElement("line"); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 lineE.setAttribute( |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 "line-id", String.valueOf(entry.getValue())); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 lineE.setAttribute( |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 "km", String.valueOf(entry.getKey())); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 csE.appendChild(lineE); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 all.appendChild(csE); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 document.appendChild(all); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 return document; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 |
1961
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
162 |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
163 /** |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
164 * @param km the kilometer from which to start searching for other |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
165 * measurements |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
166 * @param N number of neighboring measurements to find. |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
167 */ |
1749
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 public static Deque<Map.Entry<Double, Integer>> nearestNeighbors( |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 NavigableMap<Double, Integer> map, |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 double km, |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 int N |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 ) { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 Deque<Map.Entry<Double, Integer>> result = |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 new ArrayDeque<Map.Entry<Double, Integer>>(2*N); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 |
1961
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
176 if(map.get(km) != null) { |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
177 result.add(new AbstractMap.SimpleEntry<Double, Integer>(km,map.get(km))); |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
178 |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
179 } |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
180 |
1749
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 int i = 0; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 for (Map.Entry<Double, Integer> entry: |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 map.headMap(km, false).descendingMap().entrySet()) { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 if (i++ >= N) { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 break; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 result.addFirst(entry); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 i = 0; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
191 for (Map.Entry<Double, Integer> entry: |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 map.tailMap(km, false).entrySet()) { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
193 if (i++ >= N) { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 break; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 result.addLast(entry); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 return result; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
200 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 |
1961
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
202 |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
203 /** |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
204 * @param crossSectionId id of queried cross-section (in db). |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
205 * @return Mapping from kilometer to db-id. |
4781096f31f8
Mainly documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1749
diff
changeset
|
206 */ |
1749
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
207 public static NavigableMap<Double, Integer> getUncached( |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
208 Integer crossSectionId |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
209 ) { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
210 NavigableMap<Double, Integer> result = |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
211 new ConcurrentSkipListMap<Double, Integer>(); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
212 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
213 Session session = SessionHolder.HOLDER.get(); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
214 Query query = session.createQuery( |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
215 "from CrossSection where id=:id"); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
216 query.setParameter("id", crossSectionId); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
217 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
218 List<CrossSection> crossSections = query.list(); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
219 if (crossSections.isEmpty()) { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
220 return null; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
221 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
222 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
223 CrossSection crossSection = crossSections.get(0); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
224 List<CrossSectionLine> lines = crossSection.getLines(); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
225 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
226 for (CrossSectionLine line: lines) { |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
227 Double km = line.getKm().doubleValue(); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
228 Integer id = line.getId(); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
229 result.put(km, id); |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
230 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
231 |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
232 return result; |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
233 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
234 } |
f7d890f4855f
Added Service Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
235 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |