Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
4803:94cb955234ab | 4804:e9566109bd5b |
---|---|
60 | 60 |
61 /** Reference point for simple projection. */ | 61 /** Reference point for simple projection. */ |
62 private Anchor anchor; | 62 private Anchor anchor; |
63 | 63 |
64 | 64 |
65 /** | |
66 * Reference point for distance calculations, introduced to | |
67 * deal with bends in the lines. | |
68 * Array has two entrys: first is GK-Right, second GK-High. | |
69 */ | |
70 private double[] lastPointGK; | |
71 | |
72 | |
65 /** Measurement date of anchor as listed in w80 file. */ | 73 /** Measurement date of anchor as listed in w80 file. */ |
66 private Date anchorDate; | 74 private Date anchorDate; |
75 | |
76 | |
77 private double distanceToLastPoint(double gkr, double gkh) { | |
78 double dx = gkr - lastPointGK[0]; | |
79 double dy = gkh - lastPointGK[1]; | |
80 double d = dx*dx + dy*dy; | |
81 | |
82 return Math.sqrt(d); | |
83 } | |
67 | 84 |
68 | 85 |
69 /** Trivial constructor. */ | 86 /** Trivial constructor. */ |
70 public W80Parser() { | 87 public W80Parser() { |
71 data = new TreeMap<Double, List<XY>>(EpsilonComparator.CMP); | 88 data = new TreeMap<Double, List<XY>>(EpsilonComparator.CMP); |
132 public void reset() { | 149 public void reset() { |
133 data.clear(); | 150 data.clear(); |
134 currentLine = new ArrayList<XY>(); | 151 currentLine = new ArrayList<XY>(); |
135 anchor = null; | 152 anchor = null; |
136 anchorDate = null; | 153 anchorDate = null; |
154 lastPointGK = new double[] {0d,0d}; | |
137 } | 155 } |
138 | 156 |
139 | 157 |
140 /** | 158 /** |
141 * Get the Index of the last cross-section lines point. | 159 * Get the Index of the last cross-section lines point. |
145 if (currentLine == null || currentLine.isEmpty()) { | 163 if (currentLine == null || currentLine.isEmpty()) { |
146 return -1; | 164 return -1; |
147 } | 165 } |
148 XY lastPoint = this.currentLine.get(currentLine.size()-1); | 166 XY lastPoint = this.currentLine.get(currentLine.size()-1); |
149 return lastPoint.getIndex(); | 167 return lastPoint.getIndex(); |
168 } | |
169 | |
170 | |
171 private double getLastPointX() { | |
172 if (currentLine == null || currentLine.isEmpty()) { | |
173 return 0d; | |
174 } | |
175 XY lastPoint = this.currentLine.get(currentLine.size()-1); | |
176 return lastPoint.getX(); | |
150 } | 177 } |
151 | 178 |
152 | 179 |
153 /** | 180 /** |
154 * Add a Point (YZ,Index) to the current cross section line. | 181 * Add a Point (YZ,Index) to the current cross section line. |
157 * @param idx Ignored, the parameter of new point. | 184 * @param idx Ignored, the parameter of new point. |
158 * @return true if point could been added, false otherwise (e.g. not | 185 * @return true if point could been added, false otherwise (e.g. not |
159 * parsable y or z values. | 186 * parsable y or z values. |
160 */ | 187 */ |
161 private boolean addPoint(double gkr, double gkh, double height, String idx) { | 188 private boolean addPoint(double gkr, double gkh, double height, String idx) { |
162 // Calculate distance between this and anchor-point. | 189 // Calculate distance between this and lst point (add distances). |
163 double d = anchor.distance(gkr, gkh); | 190 double d = distanceToLastPoint(gkr, gkh); |
164 | 191 double totalX = getLastPointX() + d; |
165 // TODO: Scale to have "x==0" e.g. at axis of river. | |
166 // TODO: Handle "not straight lines." | |
167 | 192 |
168 // We ignore idx, and increment instead. | 193 // We ignore idx, and increment instead. |
169 int index; | 194 int index; |
170 int lastPointIdx = getLastPointIdx(); | 195 int lastPointIdx = getLastPointIdx(); |
171 if (lastPointIdx <= 0) { | 196 if (lastPointIdx <= 0) { |
172 index = 1; | 197 index = 1; |
173 } else { | 198 } else { |
174 index = lastPointIdx + 1; | 199 index = lastPointIdx + 1; |
175 } | 200 } |
176 | 201 |
177 currentLine.add(new XY(d, height/1000d, index)); | 202 this.lastPointGK[0] = gkr; |
203 this.lastPointGK[1] = gkh; | |
204 currentLine.add(new XY(totalX, height/1000d, index)); | |
178 return true; | 205 return true; |
179 } | 206 } |
180 | 207 |
181 | 208 |
182 /** | 209 /** |
188 // Therefore, the points have to be added in the correct order (also | 215 // Therefore, the points have to be added in the correct order (also |
189 // because later distances are calculated which cannot be | 216 // because later distances are calculated which cannot be |
190 // negative. | 217 // negative. |
191 String pointId = line.substring(0,20); | 218 String pointId = line.substring(0,20); |
192 String station = line.substring(9,15); | 219 String station = line.substring(9,15); |
193 String shore = line.substring(15,17); | 220 String shore = line.substring(15,16); |
194 // TODO: There is 'station' and a 'shore'-code behind. | 221 // TODO: There is 'station' and a 'shore'-code behind. |
195 // 1 = left, 2 = right. none = middle | 222 // 1 = left, 2 = right. none = middle |
196 String pointIndex = line.substring(17,21); | 223 String pointIndex = line.substring(16,21); |
197 // For GK, first seven digits are of interest. | 224 // For GK, first seven digits are of interest. |
198 String gkRight = line.substring(20,30); | 225 String gkRight = line.substring(20,30); |
199 String gkHigh = line.substring(30,40); | 226 String gkHigh = line.substring(30,40); |
200 String date = line.substring(40,46); | 227 String date = line.substring(40,46); |
201 /* Fields not (yet?) of interest for FLYS | 228 /* Fields not (yet?) of interest for FLYS |
219 double heightM = Double.parseDouble(height); | 246 double heightM = Double.parseDouble(height); |
220 | 247 |
221 // New (or first) line. | 248 // New (or first) line. |
222 if (anchor == null || !anchor.sameStation(stationKm)) { | 249 if (anchor == null || !anchor.sameStation(stationKm)) { |
223 anchor = new Anchor(gkRightKm, gkHighKm, heightM, stationKm); | 250 anchor = new Anchor(gkRightKm, gkHighKm, heightM, stationKm); |
251 lastPointGK[0] = gkRightKm; | |
252 lastPointGK[1] = gkHighKm; | |
224 currentLine = new ArrayList<XY>(); | 253 currentLine = new ArrayList<XY>(); |
225 data.put(stationKm, currentLine); | 254 data.put(stationKm, currentLine); |
226 currentLine.add(new XY(0d, heightM, 0)); | 255 currentLine.add(new XY(0d, heightM, 0)); |
227 try { | 256 try { |
228 anchorDate = DateGuesser.guessDate(date); | 257 anchorDate = DateGuesser.guessDate(date); |