Mercurial > dive4elements > river
annotate flys-backend/src/main/java/de/intevation/flys/importer/parsers/W80Parser.java @ 4804:e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 16 Jan 2013 11:22:59 +0100 |
parents | 94cb955234ab |
children |
rev | line source |
---|---|
4728
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.importer.parsers; |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
2 |
4735
94b39073f0f7
Moved EpsilonComparator to utils package becaus its not only useful for TIM parsing. Used EpsilonComparator in DA60 and DA66 case. Maybe TODO: Use in PRF, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4733
diff
changeset
|
3 import de.intevation.artifacts.common.utils.FileTools; |
94b39073f0f7
Moved EpsilonComparator to utils package becaus its not only useful for TIM parsing. Used EpsilonComparator in DA60 and DA66 case. Maybe TODO: Use in PRF, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4733
diff
changeset
|
4 |
94b39073f0f7
Moved EpsilonComparator to utils package becaus its not only useful for TIM parsing. Used EpsilonComparator in DA60 and DA66 case. Maybe TODO: Use in PRF, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4733
diff
changeset
|
5 import de.intevation.flys.importer.XY; |
94b39073f0f7
Moved EpsilonComparator to utils package becaus its not only useful for TIM parsing. Used EpsilonComparator in DA60 and DA66 case. Maybe TODO: Use in PRF, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4733
diff
changeset
|
6 |
4747
2a6d64a415e4
W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4735
diff
changeset
|
7 import de.intevation.flys.importer.parsers.tim.Coordinate; |
4735
94b39073f0f7
Moved EpsilonComparator to utils package becaus its not only useful for TIM parsing. Used EpsilonComparator in DA60 and DA66 case. Maybe TODO: Use in PRF, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4733
diff
changeset
|
8 |
4762
c6654a19b00f
W80Parser: Use DateGuesser to set a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4761
diff
changeset
|
9 import de.intevation.flys.utils.DateGuesser; |
4768
99f9e371371b
Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4762
diff
changeset
|
10 import de.intevation.flys.utils.EpsilonComparator; |
4762
c6654a19b00f
W80Parser: Use DateGuesser to set a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4761
diff
changeset
|
11 |
4735
94b39073f0f7
Moved EpsilonComparator to utils package becaus its not only useful for TIM parsing. Used EpsilonComparator in DA60 and DA66 case. Maybe TODO: Use in PRF, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4733
diff
changeset
|
12 import java.io.File; |
94b39073f0f7
Moved EpsilonComparator to utils package becaus its not only useful for TIM parsing. Used EpsilonComparator in DA60 and DA66 case. Maybe TODO: Use in PRF, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4733
diff
changeset
|
13 import java.io.IOException; |
94b39073f0f7
Moved EpsilonComparator to utils package becaus its not only useful for TIM parsing. Used EpsilonComparator in DA60 and DA66 case. Maybe TODO: Use in PRF, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4733
diff
changeset
|
14 |
4728
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
15 import java.util.ArrayList; |
4761
ab87408bb0d3
W80Parser: Added field to store a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4760
diff
changeset
|
16 import java.util.Calendar; |
ab87408bb0d3
W80Parser: Added field to store a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4760
diff
changeset
|
17 import java.util.Date; |
4735
94b39073f0f7
Moved EpsilonComparator to utils package becaus its not only useful for TIM parsing. Used EpsilonComparator in DA60 and DA66 case. Maybe TODO: Use in PRF, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4733
diff
changeset
|
18 import java.util.List; |
4728
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
19 import java.util.Map; |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
20 import java.util.TreeMap; |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
21 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
22 import org.apache.log4j.Logger; |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
23 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
24 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
25 /** |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
26 * To create cross-sections, generate: Map<double,list<xy>> from files |
4755
ba8c2147b4ff
W80Parser: Correct c&p stuff in comments (da66->w80).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4751
diff
changeset
|
27 * in w80 format. |
4728
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
28 */ |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
29 public class W80Parser extends LineParser implements CrossSectionParser |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
30 { |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
31 /** Private logger. */ |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
32 private static Logger logger = Logger.getLogger(W80Parser.class); |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
33 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
34 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
35 /** The current line to which add points. */ |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
36 private List<XY> currentLine; |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
37 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
38 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
39 /** Data collected so far, last element will be currentLine. */ |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
40 protected Map<Double, List<XY>> data; |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
41 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
42 |
4747
2a6d64a415e4
W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4735
diff
changeset
|
43 /** Anchor to project to. */ |
4768
99f9e371371b
Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4762
diff
changeset
|
44 private static class Anchor extends Coordinate { |
99f9e371371b
Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4762
diff
changeset
|
45 |
99f9e371371b
Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4762
diff
changeset
|
46 private static final double EPSILON = 1e-5; |
99f9e371371b
Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4762
diff
changeset
|
47 |
4747
2a6d64a415e4
W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4735
diff
changeset
|
48 private double station; |
4768
99f9e371371b
Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4762
diff
changeset
|
49 |
99f9e371371b
Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4762
diff
changeset
|
50 public Anchor(double x, double y, double z, double station) { |
99f9e371371b
Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4762
diff
changeset
|
51 super(x, y, z); |
4747
2a6d64a415e4
W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4735
diff
changeset
|
52 this.station = station; |
2a6d64a415e4
W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4735
diff
changeset
|
53 } |
4768
99f9e371371b
Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4762
diff
changeset
|
54 |
99f9e371371b
Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4762
diff
changeset
|
55 public boolean sameStation(double station) { |
99f9e371371b
Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4762
diff
changeset
|
56 return Math.abs(this.station - station) < EPSILON; |
4747
2a6d64a415e4
W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4735
diff
changeset
|
57 } |
2a6d64a415e4
W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4735
diff
changeset
|
58 } |
2a6d64a415e4
W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4735
diff
changeset
|
59 |
2a6d64a415e4
W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4735
diff
changeset
|
60 |
4760
69bb2996ed19
W80Parser: Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4759
diff
changeset
|
61 /** Reference point for simple projection. */ |
4747
2a6d64a415e4
W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4735
diff
changeset
|
62 private Anchor anchor; |
2a6d64a415e4
W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4735
diff
changeset
|
63 |
2a6d64a415e4
W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4735
diff
changeset
|
64 |
4804
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
65 /** |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
66 * Reference point for distance calculations, introduced to |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
67 * deal with bends in the lines. |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
68 * Array has two entrys: first is GK-Right, second GK-High. |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
69 */ |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
70 private double[] lastPointGK; |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
71 |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
72 |
4761
ab87408bb0d3
W80Parser: Added field to store a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4760
diff
changeset
|
73 /** Measurement date of anchor as listed in w80 file. */ |
ab87408bb0d3
W80Parser: Added field to store a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4760
diff
changeset
|
74 private Date anchorDate; |
ab87408bb0d3
W80Parser: Added field to store a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4760
diff
changeset
|
75 |
ab87408bb0d3
W80Parser: Added field to store a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4760
diff
changeset
|
76 |
4804
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
77 private double distanceToLastPoint(double gkr, double gkh) { |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
78 double dx = gkr - lastPointGK[0]; |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
79 double dy = gkh - lastPointGK[1]; |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
80 double d = dx*dx + dy*dy; |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
81 |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
82 return Math.sqrt(d); |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
83 } |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
84 |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
85 |
4728
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
86 /** Trivial constructor. */ |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
87 public W80Parser() { |
4735
94b39073f0f7
Moved EpsilonComparator to utils package becaus its not only useful for TIM parsing. Used EpsilonComparator in DA60 and DA66 case. Maybe TODO: Use in PRF, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4733
diff
changeset
|
88 data = new TreeMap<Double, List<XY>>(EpsilonComparator.CMP); |
4728
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
89 } |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
90 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
91 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
92 /** Get the description of the cross section parsed. */ |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
93 @Override |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
94 public String getDescription() { |
4729
0df1cac6c4b5
Removed removeExtension implementations, which have been moved to FileTools,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4728
diff
changeset
|
95 return FileTools.removeExtension(getFileName()); |
4728
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
96 } |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
97 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
98 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
99 /** Get the year of this cross sections measurement. */ |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
100 @Override |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
101 public Integer getYear() { |
4769
92a08725bc63
Do not die in W80 parser id invalid date is given.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4768
diff
changeset
|
102 if (anchorDate == null) { |
4777
34398f424cfd
W80Parser: Return null if no year set to behave like other parsers and avoid
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4769
diff
changeset
|
103 return null; |
4769
92a08725bc63
Do not die in W80 parser id invalid date is given.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4768
diff
changeset
|
104 } |
4762
c6654a19b00f
W80Parser: Use DateGuesser to set a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4761
diff
changeset
|
105 Calendar dateCalendar = Calendar.getInstance(); |
c6654a19b00f
W80Parser: Use DateGuesser to set a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4761
diff
changeset
|
106 dateCalendar.setTime(anchorDate); |
c6654a19b00f
W80Parser: Use DateGuesser to set a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4761
diff
changeset
|
107 return dateCalendar.get(Calendar.YEAR); |
4728
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
108 } |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
109 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
110 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
111 /** |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
112 * Return the data parsed. |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
113 * @return map of stations (km) to list of points. |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
114 */ |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
115 @Override |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
116 public Map<Double, List<XY>> getData() { |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
117 return data; |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
118 } |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
119 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
120 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
121 public void parseW80s(File root, final Callback callback) { |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
122 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
123 FileTools.walkTree(root, new FileTools.FileVisitor() { |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
124 @Override |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
125 public boolean visit(File file) { |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
126 if (file.isFile() && file.canRead() |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
127 && file.getName().toLowerCase().endsWith(".w80") |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
128 && (callback == null || callback.accept(file))) { |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
129 reset(); |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
130 try { |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
131 parse(file); |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
132 logger.info("parsing done"); |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
133 if (callback != null) { |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
134 callback.parsed(W80Parser.this); |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
135 } |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
136 } |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
137 catch (IOException ioe) { |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
138 logger.error("IOException while parsing file"); |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
139 return false; |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
140 } |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
141 } |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
142 return true; |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
143 } |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
144 }); |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
145 } |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
146 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
147 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
148 /** Called before consuming first line of file. */ |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
149 public void reset() { |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
150 data.clear(); |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
151 currentLine = new ArrayList<XY>(); |
4749
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
152 anchor = null; |
4761
ab87408bb0d3
W80Parser: Added field to store a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4760
diff
changeset
|
153 anchorDate = null; |
4804
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
154 lastPointGK = new double[] {0d,0d}; |
4749
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
155 } |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
156 |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
157 |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
158 /** |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
159 * Get the Index of the last cross-section lines point. |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
160 * @return last points index, -1 if not available. |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
161 */ |
4803
94cb955234ab
W80Parser: Renamed lastPointIdx() to getLastPointIdx().
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4802
diff
changeset
|
162 private int getLastPointIdx() { |
4749
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
163 if (currentLine == null || currentLine.isEmpty()) { |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
164 return -1; |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
165 } |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
166 XY lastPoint = this.currentLine.get(currentLine.size()-1); |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
167 return lastPoint.getIndex(); |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
168 } |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
169 |
4757
e965593eee57
W80Parser: Whitespace-cosmetics and comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4756
diff
changeset
|
170 |
4804
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
171 private double getLastPointX() { |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
172 if (currentLine == null || currentLine.isEmpty()) { |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
173 return 0d; |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
174 } |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
175 XY lastPoint = this.currentLine.get(currentLine.size()-1); |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
176 return lastPoint.getX(); |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
177 } |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
178 |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
179 |
4749
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
180 /** |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
181 * Add a Point (YZ,Index) to the current cross section line. |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
182 * @param y The y coordinate of new point. |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
183 * @param z The z coordinate of new point. |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
184 * @param idx Ignored, the parameter of new point. |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
185 * @return true if point could been added, false otherwise (e.g. not |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
186 * parsable y or z values. |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
187 */ |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
188 private boolean addPoint(double gkr, double gkh, double height, String idx) { |
4804
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
189 // Calculate distance between this and lst point (add distances). |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
190 double d = distanceToLastPoint(gkr, gkh); |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
191 double totalX = getLastPointX() + d; |
4751
ee6c0f246b28
W80Parser: Added TODO/comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4750
diff
changeset
|
192 |
4749
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
193 // We ignore idx, and increment instead. |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
194 int index; |
4803
94cb955234ab
W80Parser: Renamed lastPointIdx() to getLastPointIdx().
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4802
diff
changeset
|
195 int lastPointIdx = getLastPointIdx(); |
4749
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
196 if (lastPointIdx <= 0) { |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
197 index = 1; |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
198 } else { |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
199 index = lastPointIdx + 1; |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
200 } |
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
201 |
4804
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
202 this.lastPointGK[0] = gkr; |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
203 this.lastPointGK[1] = gkh; |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
204 currentLine.add(new XY(totalX, height/1000d, index)); |
4749
3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4747
diff
changeset
|
205 return true; |
4728
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
206 } |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
207 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
208 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
209 /** |
4755
ba8c2147b4ff
W80Parser: Correct c&p stuff in comments (da66->w80).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4751
diff
changeset
|
210 * Called for each line. Try to extract info from a w80 line. |
4728
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
211 */ |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
212 @Override |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
213 protected void handleLine(int lineNum, String line) { |
4757
e965593eee57
W80Parser: Whitespace-cosmetics and comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4756
diff
changeset
|
214 // The 'shore' field shows which side of the river the shore is measured. |
e965593eee57
W80Parser: Whitespace-cosmetics and comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4756
diff
changeset
|
215 // Therefore, the points have to be added in the correct order (also |
e965593eee57
W80Parser: Whitespace-cosmetics and comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4756
diff
changeset
|
216 // because later distances are calculated which cannot be |
e965593eee57
W80Parser: Whitespace-cosmetics and comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4756
diff
changeset
|
217 // negative. |
4728
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
218 String pointId = line.substring(0,20); |
4758
4db3a1509e90
W80Parser: Respect (ignore) 'shore' field of w80 files.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4757
diff
changeset
|
219 String station = line.substring(9,15); |
4804
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
220 String shore = line.substring(15,16); |
4751
ee6c0f246b28
W80Parser: Added TODO/comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4750
diff
changeset
|
221 // TODO: There is 'station' and a 'shore'-code behind. |
ee6c0f246b28
W80Parser: Added TODO/comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4750
diff
changeset
|
222 // 1 = left, 2 = right. none = middle |
4804
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
223 String pointIndex = line.substring(16,21); |
4750
60398ab6129a
W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4749
diff
changeset
|
224 // For GK, first seven digits are of interest. |
4728
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
225 String gkRight = line.substring(20,30); |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
226 String gkHigh = line.substring(30,40); |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
227 String date = line.substring(40,46); |
4759
35f4ece9562e
W80Parser: Comment code that is not (yet?) used by FLYS.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4758
diff
changeset
|
228 /* Fields not (yet?) of interest for FLYS |
4728
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
229 String locType = line.substring(46,47); |
4759
35f4ece9562e
W80Parser: Comment code that is not (yet?) used by FLYS.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4758
diff
changeset
|
230 */ |
4728
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
231 String height = line.substring(47,54); |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
232 String dateH = line.substring(54,60); |
4759
35f4ece9562e
W80Parser: Comment code that is not (yet?) used by FLYS.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4758
diff
changeset
|
233 /* Fields not (yet?) of interest for FLYS |
4728
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
234 String typeH = line.substring(60,61); |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
235 String kindH = line.substring(61,64); |
4759
35f4ece9562e
W80Parser: Comment code that is not (yet?) used by FLYS.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4758
diff
changeset
|
236 */ |
4728
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
237 String dateDec = line.substring(64,70); |
4759
35f4ece9562e
W80Parser: Comment code that is not (yet?) used by FLYS.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4758
diff
changeset
|
238 /* Fields not (yet?) of interest for FLYS |
4728
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
239 String note = line.substring(70,78); |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
240 String actual = line.substring(78); |
4759
35f4ece9562e
W80Parser: Comment code that is not (yet?) used by FLYS.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4758
diff
changeset
|
241 */ |
35f4ece9562e
W80Parser: Comment code that is not (yet?) used by FLYS.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4758
diff
changeset
|
242 |
4750
60398ab6129a
W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4749
diff
changeset
|
243 double stationKm = Double.parseDouble(station) / 1000d; |
60398ab6129a
W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4749
diff
changeset
|
244 double gkRightKm = Double.parseDouble(gkRight.substring(0,7)); |
60398ab6129a
W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4749
diff
changeset
|
245 double gkHighKm = Double.parseDouble(gkHigh.substring(0,7)); |
60398ab6129a
W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4749
diff
changeset
|
246 double heightM = Double.parseDouble(height); |
60398ab6129a
W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4749
diff
changeset
|
247 |
60398ab6129a
W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4749
diff
changeset
|
248 // New (or first) line. |
4768
99f9e371371b
Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4762
diff
changeset
|
249 if (anchor == null || !anchor.sameStation(stationKm)) { |
99f9e371371b
Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4762
diff
changeset
|
250 anchor = new Anchor(gkRightKm, gkHighKm, heightM, stationKm); |
4804
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
251 lastPointGK[0] = gkRightKm; |
e9566109bd5b
W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4803
diff
changeset
|
252 lastPointGK[1] = gkHighKm; |
4750
60398ab6129a
W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4749
diff
changeset
|
253 currentLine = new ArrayList<XY>(); |
60398ab6129a
W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4749
diff
changeset
|
254 data.put(stationKm, currentLine); |
4802
7dd5baca4f53
W80Parser: Cosmetics, whitespace, TODO resolved, logging improved.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4777
diff
changeset
|
255 currentLine.add(new XY(0d, heightM, 0)); |
4769
92a08725bc63
Do not die in W80 parser id invalid date is given.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4768
diff
changeset
|
256 try { |
92a08725bc63
Do not die in W80 parser id invalid date is given.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4768
diff
changeset
|
257 anchorDate = DateGuesser.guessDate(date); |
92a08725bc63
Do not die in W80 parser id invalid date is given.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4768
diff
changeset
|
258 } |
92a08725bc63
Do not die in W80 parser id invalid date is given.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4768
diff
changeset
|
259 catch (IllegalArgumentException iae) { |
92a08725bc63
Do not die in W80 parser id invalid date is given.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4768
diff
changeset
|
260 logger.warn("W80: Invalid date '" + date + "'."); |
92a08725bc63
Do not die in W80 parser id invalid date is given.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4768
diff
changeset
|
261 } |
4750
60398ab6129a
W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4749
diff
changeset
|
262 } |
60398ab6129a
W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4749
diff
changeset
|
263 else { |
60398ab6129a
W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4749
diff
changeset
|
264 addPoint(gkRightKm, gkHighKm, heightM, pointIndex); |
60398ab6129a
W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4749
diff
changeset
|
265 } |
4728
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
266 } |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
267 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
268 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
269 /** Called when file is fully consumed. */ |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
270 @Override |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
271 protected void finish() { |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
272 logger.info("Parsed " + data.size() + " lines"); |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
273 } |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
274 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
275 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
276 /** Parses files given as arguments. */ |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
277 public static void main(String [] args) { |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
278 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
279 W80Parser parser = new W80Parser(); |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
280 |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
281 logger.warn("Start parsing files."); |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
282 for (String arg: args) { |
4802
7dd5baca4f53
W80Parser: Cosmetics, whitespace, TODO resolved, logging improved.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4777
diff
changeset
|
283 logger.warn("Parsing a file."); |
4728
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
284 parser.parseW80s(new File(arg), null); |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
285 } |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
286 logger.error("Finished parsing files."); |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
287 } |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
288 } |
ccae8b43e527
Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
289 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |