Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/parsers/DA66Parser.java @ 8200:9d2e69f971f5
sed -i src/**/*.java 's/logger/log/g'
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 05 Sep 2014 12:50:33 +0200 |
parents | 3bb1c62ad732 |
children | 3ecf1f76b2b8 |
comparison
equal
deleted
inserted
replaced
8199:42ac86ec19c7 | 8200:9d2e69f971f5 |
---|---|
33 * To create cross-sections, generate: Map<double,list<xy>> from files | 33 * To create cross-sections, generate: Map<double,list<xy>> from files |
34 * in da66 format. | 34 * in da66 format. |
35 */ | 35 */ |
36 public class DA66Parser extends LineParser implements CrossSectionParser | 36 public class DA66Parser extends LineParser implements CrossSectionParser |
37 { | 37 { |
38 /** Private logger. */ | 38 /** Private log. */ |
39 private static Logger logger = Logger.getLogger(DA66Parser.class); | 39 private static Logger log = Logger.getLogger(DA66Parser.class); |
40 | 40 |
41 private static String HEAD_HEAD = "00"; | 41 private static String HEAD_HEAD = "00"; |
42 private static String HEAD_GEOM = "66"; // "Values" | 42 private static String HEAD_GEOM = "66"; // "Values" |
43 private static String HEAD_ENDG = "88"; // Probably never used. | 43 private static String HEAD_ENDG = "88"; // Probably never used. |
44 | 44 |
222 && file.getName().toLowerCase().endsWith(".d66") | 222 && file.getName().toLowerCase().endsWith(".d66") |
223 && (callback == null || callback.accept(file))) { | 223 && (callback == null || callback.accept(file))) { |
224 reset(); | 224 reset(); |
225 try { | 225 try { |
226 parse(file); | 226 parse(file); |
227 logger.info("parsing done"); | 227 log.info("parsing done"); |
228 if (callback != null) { | 228 if (callback != null) { |
229 callback.parsed(DA66Parser.this); | 229 callback.parsed(DA66Parser.this); |
230 } | 230 } |
231 } | 231 } |
232 catch (IOException ioe) { | 232 catch (IOException ioe) { |
233 logger.error("IOException while parsing file"); | 233 log.error("IOException while parsing file"); |
234 return false; | 234 return false; |
235 } | 235 } |
236 } | 236 } |
237 return true; | 237 return true; |
238 } | 238 } |
309 * @return true if point could been added, false otherwise (e.g. not | 309 * @return true if point could been added, false otherwise (e.g. not |
310 * parsable y or z values. | 310 * parsable y or z values. |
311 */ | 311 */ |
312 private boolean addPoint(String y, String z, String idx) { | 312 private boolean addPoint(String y, String z, String idx) { |
313 if (z == null || y == null || idx == null) { | 313 if (z == null || y == null || idx == null) { |
314 logger.error("Incomplete point definition"); | 314 log.error("Incomplete point definition"); |
315 return false; | 315 return false; |
316 } | 316 } |
317 | 317 |
318 double iy; | 318 double iy; |
319 double iz; | 319 double iz; |
322 try { | 322 try { |
323 iy = Double.parseDouble(y) / 1000d; | 323 iy = Double.parseDouble(y) / 1000d; |
324 iz = Double.parseDouble(z) / 1000d; | 324 iz = Double.parseDouble(z) / 1000d; |
325 } | 325 } |
326 catch(java.lang.NumberFormatException nfe) { | 326 catch(java.lang.NumberFormatException nfe) { |
327 logger.error("Could not parse Number: " + nfe.getMessage()); | 327 log.error("Could not parse Number: " + nfe.getMessage()); |
328 return false; | 328 return false; |
329 } | 329 } |
330 | 330 |
331 // We ignore idx, and increment instead. | 331 // We ignore idx, and increment instead. |
332 int index; | 332 int index; |
354 */ | 354 */ |
355 @Override | 355 @Override |
356 protected void handleLine(int lineNum, String line) { | 356 protected void handleLine(int lineNum, String line) { |
357 String head = line.substring(0,2); | 357 String head = line.substring(0,2); |
358 if (HEAD_HEAD.equals(head)) { | 358 if (HEAD_HEAD.equals(head)) { |
359 //logger.debug("New station"); | 359 //log.debug("New station"); |
360 Matcher m = LINE_PATTERN.matcher(line); | 360 Matcher m = LINE_PATTERN.matcher(line); |
361 if (m.find()) { | 361 if (m.find()) { |
362 // Actually matches! | 362 // Actually matches! |
363 // TODO 'move' last line to match river axis | 363 // TODO 'move' last line to match river axis |
364 // TODO find river axis intersection | 364 // TODO find river axis intersection |
365 currentLine = new ArrayList<XY>(); | 365 currentLine = new ArrayList<XY>(); |
366 double station = stationInKm(Double.parseDouble(m.group(FIELD.STATION.getIdx()))); | 366 double station = stationInKm(Double.parseDouble(m.group(FIELD.STATION.getIdx()))); |
367 data.put(station, currentLine); | 367 data.put(station, currentLine); |
368 } | 368 } |
369 else { | 369 else { |
370 logger.error("HEAD line bad."); | 370 log.error("HEAD line bad."); |
371 } | 371 } |
372 } | 372 } |
373 else if (HEAD_GEOM.equals(head)) { | 373 else if (HEAD_GEOM.equals(head)) { |
374 Matcher m = LINE_PATTERN.matcher(line); | 374 Matcher m = LINE_PATTERN.matcher(line); |
375 if (m.find()) { | 375 if (m.find()) { |
376 //logger.info("Station: " + m.group(FIELD.STATION.getIdx())); | 376 //log.info("Station: " + m.group(FIELD.STATION.getIdx())); |
377 // TODO if last station differs, error and abort | 377 // TODO if last station differs, error and abort |
378 if (m.group(FIELD.POINT_1_ID.getIdx()) != null) { | 378 if (m.group(FIELD.POINT_1_ID.getIdx()) != null) { |
379 // Point 1 | 379 // Point 1 |
380 if(addPoint( | 380 if(addPoint( |
381 m.group(FIELD.POINT_1_Y.getIdx()), | 381 m.group(FIELD.POINT_1_Y.getIdx()), |
383 m.group(FIELD.POINT_1_ID.getIdx()))) { | 383 m.group(FIELD.POINT_1_ID.getIdx()))) { |
384 // Point added. | 384 // Point added. |
385 } | 385 } |
386 else { | 386 else { |
387 // Problematic point. | 387 // Problematic point. |
388 logger.error("A point could not be added"); | 388 log.error("A point could not be added"); |
389 } | 389 } |
390 } | 390 } |
391 if (m.group(FIELD.POINT_2_ID.getIdx()) != null) { | 391 if (m.group(FIELD.POINT_2_ID.getIdx()) != null) { |
392 // Point 2 | 392 // Point 2 |
393 if(addPoint( | 393 if(addPoint( |
396 m.group(FIELD.POINT_2_ID.getIdx()))) { | 396 m.group(FIELD.POINT_2_ID.getIdx()))) { |
397 // Point added. | 397 // Point added. |
398 } | 398 } |
399 else { | 399 else { |
400 // Problematic point. | 400 // Problematic point. |
401 logger.error("A point could not be added"); | 401 log.error("A point could not be added"); |
402 } | 402 } |
403 } | 403 } |
404 if (m.group(FIELD.POINT_3_ID.getIdx()) != null) { | 404 if (m.group(FIELD.POINT_3_ID.getIdx()) != null) { |
405 // Point 3 | 405 // Point 3 |
406 if(addPoint( | 406 if(addPoint( |
409 m.group(FIELD.POINT_3_ID.getIdx()))) { | 409 m.group(FIELD.POINT_3_ID.getIdx()))) { |
410 // Point added. | 410 // Point added. |
411 } | 411 } |
412 else { | 412 else { |
413 // Problematic point. | 413 // Problematic point. |
414 logger.error("A point could not be added"); | 414 log.error("A point could not be added"); |
415 } | 415 } |
416 } | 416 } |
417 if (m.group(FIELD.POINT_4_ID.getIdx()) != null) { | 417 if (m.group(FIELD.POINT_4_ID.getIdx()) != null) { |
418 // Point 4 | 418 // Point 4 |
419 if(addPoint( | 419 if(addPoint( |
422 m.group(FIELD.POINT_4_ID.getIdx()))) { | 422 m.group(FIELD.POINT_4_ID.getIdx()))) { |
423 // Point added. | 423 // Point added. |
424 } | 424 } |
425 else { | 425 else { |
426 // Problematic point. | 426 // Problematic point. |
427 logger.error("A point could not be added"); | 427 log.error("A point could not be added"); |
428 } | 428 } |
429 } | 429 } |
430 } | 430 } |
431 else { | 431 else { |
432 logger.warn("Line could not be parsed: "); | 432 log.warn("Line could not be parsed: "); |
433 logger.warn(line); | 433 log.warn(line); |
434 } | 434 } |
435 } | 435 } |
436 else if (HEAD_GEOM.equals(head)) { | 436 else if (HEAD_GEOM.equals(head)) { |
437 logger.debug("Hit a 88"); | 437 log.debug("Hit a 88"); |
438 } | 438 } |
439 else { | 439 else { |
440 logger.error("Do not know how to treat da66 line:"); | 440 log.error("Do not know how to treat da66 line:"); |
441 logger.error(line); | 441 log.error(line); |
442 } | 442 } |
443 } | 443 } |
444 | 444 |
445 | 445 |
446 /** Called when file is fully consumed. */ | 446 /** Called when file is fully consumed. */ |
447 @Override | 447 @Override |
448 protected void finish() { | 448 protected void finish() { |
449 // TODO 'move' last line to match river axis | 449 // TODO 'move' last line to match river axis |
450 logger.info("Parsed " + data.size() + " lines"); | 450 log.info("Parsed " + data.size() + " lines"); |
451 } | 451 } |
452 | 452 |
453 | 453 |
454 /** Parses files given as arguments. */ | 454 /** Parses files given as arguments. */ |
455 public static void main(String [] args) { | 455 public static void main(String [] args) { |
456 | 456 |
457 DA66Parser parser = new DA66Parser(); | 457 DA66Parser parser = new DA66Parser(); |
458 | 458 |
459 logger.warn("Start parsing files."); | 459 log.warn("Start parsing files."); |
460 for (String arg: args) { | 460 for (String arg: args) { |
461 parser.parseDA66s(new File(arg), null); | 461 parser.parseDA66s(new File(arg), null); |
462 logger.warn("Parsing a file."); | 462 log.warn("Parsing a file."); |
463 } | 463 } |
464 logger.error("Finished parsing files."); | 464 log.error("Finished parsing files."); |
465 } | 465 } |
466 } | 466 } |
467 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 467 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |