comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 402:eb22ffe4d74c

Implemented methods to retrieve and compute the data used to create discharge longitudinal sections. flys-artifacts/trunk@1843 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 06 May 2011 14:19:27 +0000
parents 53cc794fee07
children 6ab62e5b05b5
comparison
equal deleted inserted replaced
401:34de11dcf355 402:eb22ffe4d74c
29 import de.intevation.artifactdatabase.state.State; 29 import de.intevation.artifactdatabase.state.State;
30 import de.intevation.artifactdatabase.state.StateEngine; 30 import de.intevation.artifactdatabase.state.StateEngine;
31 import de.intevation.artifactdatabase.transition.TransitionEngine; 31 import de.intevation.artifactdatabase.transition.TransitionEngine;
32 32
33 import de.intevation.flys.model.Gauge; 33 import de.intevation.flys.model.Gauge;
34 import de.intevation.flys.model.Range;
34 import de.intevation.flys.model.River; 35 import de.intevation.flys.model.River;
35 36
36 import de.intevation.flys.artifacts.context.FLYSContext; 37 import de.intevation.flys.artifacts.context.FLYSContext;
37 import de.intevation.flys.artifacts.model.DischargeTables; 38 import de.intevation.flys.artifacts.model.DischargeTables;
38 import de.intevation.flys.artifacts.model.RiverFactory; 39 import de.intevation.flys.artifacts.model.RiverFactory;
490 return null; 491 return null;
491 } 492 }
492 493
493 494
494 /** 495 /**
496 * This method returns the given distance
497 *
498 * @return an array with lower and upper kilometer range for each
499 * intersected gauge.
500 */
501 public double[][] getSplittedDistance() {
502 double[] dist = getDistance();
503 List<Gauge> gauges = getGauges();
504
505 int num = gauges != null ? gauges.size() : 0;
506
507 double[][] res = new double[num][2];
508
509 for (int i = 0; i < num; i++) {
510 Range range = gauges.get(i).getRange();
511
512 double lower = range.getA().doubleValue();
513 double upper = range.getB().doubleValue();
514
515 res[i][0] = dist[0] < lower ? lower : dist[0];
516 res[i][1] = dist[1] > upper ? upper : dist[1];
517 }
518
519 return res;
520 }
521
522
523 /**
495 * Returns the selected locations based on a given array of locations. 524 * Returns the selected locations based on a given array of locations.
496 * 525 *
497 * @param locations The StateData that contains the locations. 526 * @param locations The StateData that contains the locations.
498 * 527 *
499 * @return the selected locations. 528 * @return the selected locations.
544 573
545 574
546 /** 575 /**
547 * Returns the selected Kms. 576 * Returns the selected Kms.
548 * 577 *
578 * @param distance An 2dim array with [lower, upper] values.
579 *
549 * @return the selected Kms. 580 * @return the selected Kms.
550 */ 581 */
551 public double[] getKms() { 582 public double[] getKms(double[] distance) {
552 StateData dStep = getData("ld_step"); 583 StateData dStep = getData("ld_step");
553 584
554 if (dStep == null) { 585 if (dStep == null) {
555 logger.warn("No step width given. Cannot compute Kms."); 586 logger.warn("No step width given. Cannot compute Kms.");
556 return null; 587 return null;
557 } 588 }
558 589
559 double step = Double.parseDouble((String) dStep.getValue()); 590 double step = Double.parseDouble((String) dStep.getValue());
560 double[] distance = getDistance();
561 double lower = distance[0];
562 591
563 // transform step from 'm' into 'km' 592 // transform step from 'm' into 'km'
564 step = step / 1000; 593 step = step / 1000;
565 594
566 if (step == 0d) { 595 if (step == 0d) {
567 step = DEFAULT_KM_STEPS; 596 step = DEFAULT_KM_STEPS;
568 } 597 }
569 598
570 return getExplodedValues(distance[0], distance[1], step); 599 return getExplodedValues(distance[0], distance[1], step);
600 }
601
602
603 /**
604 * Returns the selected Kms.
605 *
606 * @return the selected kms.
607 */
608 public double[] getKms() {
609 double[] distance = getDistance();
610 return getKms(distance);
571 } 611 }
572 612
573 613
574 /** 614 /**
575 * Returns the gauge based on the current distance and river. 615 * Returns the gauge based on the current distance and river.
633 } 673 }
634 } 674 }
635 675
636 676
637 /** 677 /**
678 * Returns the Q values based on a specified kilometer range.
679 *
680 * @param range A 2dim array with lower and upper kilometer range.
681 *
682 * @return an array of Q values.
683 */
684 public double[] getQs(double[] range) {
685 StateData dMode = getData("wq_mode");
686 StateData dValues = getData("wq_values");
687
688 String mode = dMode != null ? (String) dMode.getValue() : "";
689
690 // TODO REMOVE THIS HARD CODED MODE VALUE!
691 mode = "Q";
692
693 if (mode.equals("Q")) {
694 return getWQForDist(range);
695 }
696
697 logger.warn("You try to get Qs, but Ws has been inserted.");
698 return null;
699 }
700
701
702 /**
703 * Returns the W values based on a specified kilometer range.
704 *
705 * @param range A 2dim array with lower and upper kilometer range.
706 *
707 * @return an array of W values.
708 */
709 public double[] getWs(double[] range) {
710 StateData dMode = getData("wq_mode");
711 StateData dValues = getData("wq_values");
712
713 String mode = dMode != null ? (String) dMode.getValue() : "";
714
715 // TODO REMOVE THIS HARD CODED MODE VALUE!
716 mode = "W";
717
718 if (mode.equals("W")) {
719 return getWQForDist(range);
720 }
721
722 logger.warn("You try to get Ws, but Qs has been inserted.");
723 return null;
724 }
725
726
727 /**
638 * This method returns the W values. 728 * This method returns the W values.
639 * 729 *
640 * @return the selected W values or null, if no W values are selected. 730 * @return the selected W values or null, if no W values are selected.
641 */ 731 */
642 public double[] getWs() { 732 public double[] getWs() {
680 double[][] values = tmp.get(g.getName()); 770 double[][] values = tmp.get(g.getName());
681 double[] qs = new double[ws.length]; 771 double[] qs = new double[ws.length];
682 772
683 for (int i = 0; i < ws.length; i++) { 773 for (int i = 0; i < ws.length; i++) {
684 qs[i] = dt.getQForW(values, ws[i]); 774 qs[i] = dt.getQForW(values, ws[i]);
685 logger.debug("Q for " + ws[i] + " = " + qs[i]);
686 } 775 }
687 776
688 return qs; 777 return qs;
778 }
779
780
781 /**
782 * This method returns the given W or Q values for a specific range
783 * (inserted in the WQ input panel for discharge longitudinal sections).
784 *
785 * @param dist A 2dim array with lower und upper kilometer values.
786 *
787 * @return an array of W or Q values.
788 */
789 protected double[] getWQForDist(double[] dist) {
790 logger.debug("Search wq values for range: " + dist[0] + " - " + dist[1]);
791 StateData data = getData("wq_values");
792
793 if (data == null) {
794 logger.warn("Missing wq values!");
795 return null;
796 }
797
798 String dataString = (String) data.getValue();
799 String[] ranges = dataString.split(":");
800
801 for (String range: ranges) {
802 String[] parts = range.split(";");
803
804 double lower = Double.parseDouble(parts[0]);
805 double upper = Double.parseDouble(parts[1]);
806
807 if (lower <= dist[0] && upper >= dist[1]) {
808 String[] values = parts[2].split(",");
809
810 int num = values.length;
811 double[] res = new double[num];
812
813 for (int i = 0; i < num; i++) {
814 try {
815 res[i] = Double.parseDouble(values[i]);
816 }
817 catch (NumberFormatException nfe) {
818 logger.warn(nfe, nfe);
819 }
820 }
821
822 return res;
823 }
824 }
825
826 logger.warn("Specified range for WQ not found!");
827
828 return null;
689 } 829 }
690 830
691 831
692 /** 832 /**
693 * This method returns an array of inserted WQ triples that consist of from, 833 * This method returns an array of inserted WQ triples that consist of from,

http://dive4elements.wald.intevation.org