Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/parsers/W80Parser.java @ 4749:3028037c6293
W80Parser: addPoint and lastIdx functions to add a point and find last points index.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 03 Jan 2013 09:59:41 +0100 |
parents | 2a6d64a415e4 |
children | 60398ab6129a |
comparison
equal
deleted
inserted
replaced
4748:ea8c3e6c9614 | 4749:3028037c6293 |
---|---|
136 | 136 |
137 /** Called before consuming first line of file. */ | 137 /** Called before consuming first line of file. */ |
138 public void reset() { | 138 public void reset() { |
139 data.clear(); | 139 data.clear(); |
140 currentLine = new ArrayList<XY>(); | 140 currentLine = new ArrayList<XY>(); |
141 anchor = null; | |
142 } | |
143 | |
144 | |
145 /** | |
146 * Get the Index of the last cross-section lines point. | |
147 * @return last points index, -1 if not available. | |
148 */ | |
149 private int lastPointIdx() { | |
150 if (currentLine == null || currentLine.isEmpty()) { | |
151 return -1; | |
152 } | |
153 XY lastPoint = this.currentLine.get(currentLine.size()-1); | |
154 return lastPoint.getIndex(); | |
155 } | |
156 | |
157 /** | |
158 * Add a Point (YZ,Index) to the current cross section line. | |
159 * @param y The y coordinate of new point. | |
160 * @param z The z coordinate of new point. | |
161 * @param idx Ignored, the parameter of new point. | |
162 * @return true if point could been added, false otherwise (e.g. not | |
163 * parsable y or z values. | |
164 */ | |
165 private boolean addPoint(double gkr, double gkh, double height, String idx) { | |
166 // Calculate distance between this and anchor-point. | |
167 double dx = gkr - anchor.getCoordinate().getX(); | |
168 double dy = gkh - anchor.getCoordinate().getY(); | |
169 double d = Math.sqrt(dx * dx + dy * dy); | |
170 | |
171 // We ignore idx, and increment instead. | |
172 int index; | |
173 int lastPointIdx = lastPointIdx(); | |
174 if (lastPointIdx <= 0) { | |
175 index = 1; | |
176 } else { | |
177 index = lastPointIdx + 1; | |
178 } | |
179 | |
180 currentLine.add(new XY(d, height/1000d, index)); | |
181 return true; | |
141 } | 182 } |
142 | 183 |
143 | 184 |
144 /** | 185 /** |
145 * Called for each line. Try to extract info from a da66 line. | 186 * Called for each line. Try to extract info from a da66 line. |