Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/FastCrossSectionChunk.java @ 7494:4de4b19b6be6
Fixed half broken interpolation code for lines to 'Dauerlinie'.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 01 Nov 2013 13:25:54 +0100 |
parents | 5f4893db41e4 |
children | 0a5239a1e46e |
rev | line source |
---|---|
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
9 package org.dive4elements.river.artifacts.model; |
2119
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import java.util.List; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 import java.util.Collections; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 import java.io.Serializable; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
16 import org.dive4elements.river.model.CrossSection; |
2119
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
18 import org.dive4elements.river.model.FastCrossSectionLine; |
2126
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
19 |
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
20 import org.apache.log4j.Logger; |
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
21 |
6515 | 22 /** |
23 * Number of FastCrossSectionLines, e.g. to store in cache and retrieve | |
24 * a single contain CrossSectionLine by its km. | |
25 */ | |
2119
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 public class FastCrossSectionChunk |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 implements Serializable |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 { |
2126
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
29 private static Logger log = Logger.getLogger(FastCrossSectionChunk.class); |
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
30 |
2119
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 public static final String PREFIX = "FCSC:"; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 public static final double KM_RANGE = 1.0; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 protected double startKm; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 protected int crossSectionId; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 protected List<FastCrossSectionLine> crossSectionLines; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 public FastCrossSectionChunk() { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 public FastCrossSectionChunk(CrossSection cs, double km) { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 crossSectionId = cs.getId(); |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 startKm = Math.floor(km); |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 double stopKm = startKm + KM_RANGE; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 |
2126
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
48 long startTime = System.currentTimeMillis(); |
2119
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 |
2126
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
50 crossSectionLines = cs.getFastLines(startKm, stopKm); |
2119
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 |
2126
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
52 long stopTime = System.currentTimeMillis(); |
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
53 |
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
54 if (log.isDebugEnabled()) { |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2126
diff
changeset
|
55 log.debug("Fetching cross section lines took " + |
2126
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
56 (float)(stopTime-startTime)/1000f + " secs."); |
2119
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 |
6265 | 60 /** Finds the FastCrossSectionLine at km (null if not found). */ |
2119
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 public FastCrossSectionLine getCrossSectionLine(double km) { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 FastCrossSectionLine key = new FastCrossSectionLine(km); |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 int pos = Collections.binarySearch( |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 crossSectionLines, key, FastCrossSectionLine.KM_CMP); |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 return pos < 0 ? null : crossSectionLines.get(pos); |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 public static String createHashKey(CrossSection cs, double km) { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 return PREFIX + cs.getId() + ":" + (int)Math.floor(km); |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 public String getHashKey() { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 return PREFIX + crossSectionId + ":" + (int)Math.floor(startKm); |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 public double getStartKm() { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 return startKm; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 public void setStartKm(double startKm) { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 this.startKm = startKm; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 public double getStopKm() { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 return startKm + KM_RANGE; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 public int getCrossSectionId() { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 return crossSectionId; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 public void setCrossSectionId(int crossSectionId) { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 this.crossSectionId = crossSectionId; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |