annotate backend/src/main/java/org/dive4elements/river/importer/parsers/W80Parser.java @ 8187:3bb1c62ad732

Moved package org.dive4elements.river.utils to org.dive4elements.river.backend.utils.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 04 Sep 2014 15:03:25 +0200
parents 4c3ccf2b0304
children 9d2e69f971f5
rev   line source
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5992
4c3ccf2b0304 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5992
4c3ccf2b0304 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
6 * documentation coming with Dive4Elements River for details.
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
9 package org.dive4elements.river.importer.parsers;
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
10
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
11 import org.dive4elements.artifacts.common.utils.FileTools;
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
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
13 import org.dive4elements.river.importer.XY;
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
14
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
15 import org.dive4elements.river.importer.parsers.tim.Coordinate;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
16
8187
3bb1c62ad732 Moved package org.dive4elements.river.utils to org.dive4elements.river.backend.utils.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
17 import org.dive4elements.river.backend.utils.DateGuesser;
3bb1c62ad732 Moved package org.dive4elements.river.utils to org.dive4elements.river.backend.utils.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
18 import org.dive4elements.river.backend.utils.EpsilonComparator;
4762
c6654a19b00f W80Parser: Use DateGuesser to set a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4761
diff changeset
19
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
20 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
21 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
22
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
23 import java.util.ArrayList;
4761
ab87408bb0d3 W80Parser: Added field to store a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4760
diff changeset
24 import java.util.Calendar;
ab87408bb0d3 W80Parser: Added field to store a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4760
diff changeset
25 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
26 import java.util.List;
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
27 import java.util.Map;
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
28 import java.util.TreeMap;
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
29
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
30 import org.apache.log4j.Logger;
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
31
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
32
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 * 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
35 * in w80 format.
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
36 */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
37 public class W80Parser extends LineParser implements CrossSectionParser
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 /** Private logger. */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
40 private static Logger logger = Logger.getLogger(W80Parser.class);
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
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
43 /** The current line to which add points. */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
44 private List<XY> currentLine;
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
45
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
46
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
47 /** Data collected so far, last element will be currentLine. */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
48 protected Map<Double, List<XY>> data;
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
49
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
50
4747
2a6d64a415e4 W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4735
diff changeset
51 /** 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
52 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
53
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 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
55
4747
2a6d64a415e4 W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4735
diff changeset
56 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
57
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
58 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
59 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
60 this.station = station;
2a6d64a415e4 W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4735
diff changeset
61 }
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
62
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
63 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
64 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
65 }
2a6d64a415e4 W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4735
diff changeset
66 }
2a6d64a415e4 W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4735
diff changeset
67
2a6d64a415e4 W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4735
diff changeset
68
4760
69bb2996ed19 W80Parser: Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4759
diff changeset
69 /** 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
70 private Anchor anchor;
2a6d64a415e4 W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4735
diff changeset
71
2a6d64a415e4 W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4735
diff changeset
72
4804
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
73 /**
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
74 * Reference point for distance calculations, introduced to
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
75 * deal with bends in the lines.
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
76 * 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
77 */
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
78 private double[] lastPointGK;
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
79
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
80
4761
ab87408bb0d3 W80Parser: Added field to store a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4760
diff changeset
81 /** 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
82 private Date anchorDate;
ab87408bb0d3 W80Parser: Added field to store a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4760
diff changeset
83
ab87408bb0d3 W80Parser: Added field to store a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4760
diff changeset
84
4804
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
85 private double distanceToLastPoint(double gkr, double gkh) {
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
86 double dx = gkr - lastPointGK[0];
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
87 double dy = gkh - lastPointGK[1];
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
88 double d = dx*dx + dy*dy;
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
89
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
90 return Math.sqrt(d);
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
91 }
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
92
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
93
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
94 /** Trivial constructor. */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
95 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
96 data = new TreeMap<Double, List<XY>>(EpsilonComparator.CMP);
4728
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
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
100 /** Get the description of the cross section parsed. */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
101 @Override
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
102 public String getDescription() {
4729
0df1cac6c4b5 Removed removeExtension implementations, which have been moved to FileTools,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4728
diff changeset
103 return FileTools.removeExtension(getFileName());
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
104 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
105
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
106
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
107 /** Get the year of this cross sections measurement. */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
108 @Override
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
109 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
110 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
111 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
112 }
4762
c6654a19b00f W80Parser: Use DateGuesser to set a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4761
diff changeset
113 Calendar dateCalendar = Calendar.getInstance();
c6654a19b00f W80Parser: Use DateGuesser to set a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4761
diff changeset
114 dateCalendar.setTime(anchorDate);
c6654a19b00f W80Parser: Use DateGuesser to set a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4761
diff changeset
115 return dateCalendar.get(Calendar.YEAR);
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
116 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
117
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 * Return the data parsed.
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
121 * @return map of stations (km) to list of points.
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 @Override
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
124 public Map<Double, List<XY>> getData() {
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
125 return data;
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
126 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
127
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
128
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
129 public void parseW80s(File root, final Callback callback) {
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
130
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
131 FileTools.walkTree(root, new FileTools.FileVisitor() {
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
132 @Override
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
133 public boolean visit(File file) {
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
134 if (file.isFile() && file.canRead()
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
135 && file.getName().toLowerCase().endsWith(".w80")
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
136 && (callback == null || callback.accept(file))) {
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
137 reset();
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
138 try {
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
139 parse(file);
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
140 logger.info("parsing done");
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
141 if (callback != null) {
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
142 callback.parsed(W80Parser.this);
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 catch (IOException ioe) {
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
146 logger.error("IOException while parsing file");
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
147 return false;
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
148 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
149 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
150 return true;
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
151 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
152 });
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
153 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
154
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
155
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
156 /** Called before consuming first line of file. */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
157 public void reset() {
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
158 data.clear();
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
159 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
160 anchor = null;
4761
ab87408bb0d3 W80Parser: Added field to store a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4760
diff changeset
161 anchorDate = null;
4804
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
162 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
163 }
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
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 /**
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 * 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
168 * @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
169 */
4803
94cb955234ab W80Parser: Renamed lastPointIdx() to getLastPointIdx().
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4802
diff changeset
170 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
171 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
172 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
173 }
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
174 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
175 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
176 }
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
177
4757
e965593eee57 W80Parser: Whitespace-cosmetics and comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4756
diff changeset
178
4804
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
179 private double getLastPointX() {
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
180 if (currentLine == null || currentLine.isEmpty()) {
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
181 return 0d;
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
182 }
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
183 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
184 return lastPoint.getX();
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
185 }
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
186
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
187
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
188 /**
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
189 * 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
190 * @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
191 * @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
192 * @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
193 * @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
194 * 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
195 */
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 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
197 // 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
198 double d = distanceToLastPoint(gkr, gkh);
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
199 double totalX = getLastPointX() + d;
4751
ee6c0f246b28 W80Parser: Added TODO/comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4750
diff changeset
200
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
201 // 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
202 int index;
4803
94cb955234ab W80Parser: Renamed lastPointIdx() to getLastPointIdx().
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4802
diff changeset
203 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
204 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
205 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
206 } 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
207 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
208 }
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
209
4804
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
210 this.lastPointGK[0] = gkr;
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
211 this.lastPointGK[1] = gkh;
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
212 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
213 return true;
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
214 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
215
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
216
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
217 /**
4755
ba8c2147b4ff W80Parser: Correct c&p stuff in comments (da66->w80).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4751
diff changeset
218 * 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
219 */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
220 @Override
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
221 protected void handleLine(int lineNum, String line) {
4757
e965593eee57 W80Parser: Whitespace-cosmetics and comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4756
diff changeset
222 // 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
223 // 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
224 // because later distances are calculated which cannot be
e965593eee57 W80Parser: Whitespace-cosmetics and comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4756
diff changeset
225 // negative.
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
226 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
227 String station = line.substring(9,15);
4804
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
228 String shore = line.substring(15,16);
4751
ee6c0f246b28 W80Parser: Added TODO/comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4750
diff changeset
229 // TODO: There is 'station' and a 'shore'-code behind.
ee6c0f246b28 W80Parser: Added TODO/comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4750
diff changeset
230 // 1 = left, 2 = right. none = middle
4804
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
231 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
232 // For GK, first seven digits are of interest.
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
233 String gkRight = line.substring(20,30);
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
234 String gkHigh = line.substring(30,40);
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
235 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
236 /* Fields not (yet?) of interest for FLYS
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
237 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
238 */
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
239 String height = line.substring(47,54);
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
240 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
241 /* Fields not (yet?) of interest for FLYS
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
242 String typeH = line.substring(60,61);
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
243 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
244 */
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
245 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
246 /* Fields not (yet?) of interest for FLYS
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
247 String note = line.substring(70,78);
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
248 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
249 */
35f4ece9562e W80Parser: Comment code that is not (yet?) used by FLYS.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4758
diff changeset
250
4750
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
251 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
252 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
253 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
254 double heightM = Double.parseDouble(height);
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
255
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
256 // 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
257 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
258 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
259 lastPointGK[0] = gkRightKm;
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
260 lastPointGK[1] = gkHighKm;
4750
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
261 currentLine = new ArrayList<XY>();
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
262 data.put(stationKm, currentLine);
4802
7dd5baca4f53 W80Parser: Cosmetics, whitespace, TODO resolved, logging improved.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4777
diff changeset
263 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
264 try {
92a08725bc63 Do not die in W80 parser id invalid date is given.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4768
diff changeset
265 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
266 }
92a08725bc63 Do not die in W80 parser id invalid date is given.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4768
diff changeset
267 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
268 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
269 }
4750
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
270 }
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
271 else {
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
272 addPoint(gkRightKm, gkHighKm, heightM, pointIndex);
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
273 }
4728
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
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
277 /** Called when file is fully consumed. */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
278 @Override
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
279 protected void finish() {
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
280 logger.info("Parsed " + data.size() + " lines");
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
281 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
282
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
283
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
284 /** Parses files given as arguments. */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
285 public static void main(String [] args) {
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
286
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
287 W80Parser parser = new W80Parser();
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 logger.warn("Start parsing files.");
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
290 for (String arg: args) {
4802
7dd5baca4f53 W80Parser: Cosmetics, whitespace, TODO resolved, logging improved.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4777
diff changeset
291 logger.warn("Parsing a file.");
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
292 parser.parseW80s(new File(arg), null);
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
293 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
294 logger.error("Finished parsing files.");
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
295 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
296 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
297 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org