Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java @ 1178:1b432c260e97
Enabled the FloodMapState to fetch waterlevel data from external Artifact.
flys-artifacts/trunk@2764 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 15 Sep 2011 15:36:05 +0000 |
parents | ace192d3283d |
children | be8b5c06a1f8 |
comparison
equal
deleted
inserted
replaced
1177:70b8ac64404b | 1178:1b432c260e97 |
---|---|
63 | 63 |
64 public static final String KEEP_ARTIFACT_DIR = | 64 public static final String KEEP_ARTIFACT_DIR = |
65 System.getProperty("flys.uesk.keep.artifactsdir", "false"); | 65 System.getProperty("flys.uesk.keep.artifactsdir", "false"); |
66 | 66 |
67 | 67 |
68 public static final String WSP_ARTIFACT_UUID = "uesk.wsp.artifact"; | 68 public static final String WSP_ARTIFACT = "wsp"; |
69 | 69 |
70 public static final String WINFO_WSP_STATE_ID = "state.winfo.waterlevel"; | 70 public static final String WINFO_WSP_STATE_ID = "state.winfo.waterlevel"; |
71 | 71 |
72 public static final String WSPLGEN_PARAMETER_FILE = "wsplgen.par"; | 72 public static final String WSPLGEN_PARAMETER_FILE = "wsplgen.par"; |
73 public static final String WSPLGEN_BARRIERS_LINES = "barrier_lines.shp"; | 73 public static final String WSPLGEN_BARRIERS_LINES = "barrier_lines.shp"; |
688 protected void setOutFile(FLYSArtifact artifact, WSPLGENJob job) { | 688 protected void setOutFile(FLYSArtifact artifact, WSPLGENJob job) { |
689 job.setOutFile(WSPLGEN_OUTPUT_FILE); | 689 job.setOutFile(WSPLGEN_OUTPUT_FILE); |
690 } | 690 } |
691 | 691 |
692 | 692 |
693 protected WQKms getWQKms(FLYSArtifact flys, CallContext cc) { | |
694 String wspString = flys.getDataAsString(WSP_ARTIFACT); | |
695 String[] parts = wspString.split(";"); | |
696 | |
697 String otherArtifact = parts[0]; | |
698 | |
699 int idx = -1; | |
700 try { | |
701 idx = Integer.parseInt(parts[2]); | |
702 } | |
703 catch (NumberFormatException nfe) { /* do nothing */ } | |
704 | |
705 FLYSArtifact src = otherArtifact != null | |
706 ? FLYSUtils.getArtifact(otherArtifact, cc) | |
707 : flys; | |
708 | |
709 logger.debug("Use waterlevel provided by Artifact: " + src.identifier()); | |
710 | |
711 CalculationResult rawData = (CalculationResult) src.compute( | |
712 cc, | |
713 null, | |
714 WINFO_WSP_STATE_ID, | |
715 ComputeType.ADVANCE, | |
716 false); | |
717 | |
718 WQKms[] wqkms = (WQKms[]) rawData.getData(); | |
719 | |
720 return wqkms == null || idx == -1 || idx >= wqkms.length | |
721 ? null | |
722 : wqkms[idx]; | |
723 } | |
724 | |
725 | |
693 protected void setWsp( | 726 protected void setWsp( |
694 FLYSArtifact artifact, | 727 FLYSArtifact artifact, |
695 CallContext context, | 728 CallContext context, |
696 File dir, | 729 File dir, |
697 WSPLGENJob job) | 730 WSPLGENJob job) |
698 { | 731 { |
699 logger.debug("FloodMapState.setWsp"); | 732 logger.debug("FloodMapState.setWsp"); |
700 | 733 |
701 String otherArtifact = artifact.getDataAsString(WSP_ARTIFACT_UUID); | 734 WQKms data = getWQKms(artifact, context); |
702 FLYSArtifact src = otherArtifact != null | 735 |
703 ? FLYSUtils.getArtifact(otherArtifact, context) | 736 if (data == null) { |
704 : artifact; | |
705 | |
706 CalculationResult rawData = (CalculationResult) src.compute( | |
707 context, | |
708 null, | |
709 WINFO_WSP_STATE_ID, | |
710 ComputeType.ADVANCE, | |
711 false); | |
712 | |
713 if (rawData == null) { | |
714 logger.warn("No WST data found!"); | 737 logger.warn("No WST data found!"); |
715 return; | 738 return; |
716 } | 739 } |
717 | 740 |
718 WQKms[] data = (WQKms[]) rawData.getData(); | 741 WstWriter writer = new WstWriter(1); |
719 WstWriter writer = new WstWriter(data.length); | |
720 | 742 |
721 // TODO REMOVE job.setWspTag(...) This is only used until the user is | 743 // TODO REMOVE job.setWspTag(...) This is only used until the user is |
722 // able to select the WSP column himself! | 744 // able to select the WSP column himself! |
723 boolean writeWspTag = true; | 745 boolean writeWspTag = true; |
724 | 746 |
725 double[] buf = new double[4]; | 747 double[] buf = new double[4]; |
726 for (WQKms wqkms: data) { | 748 logger.debug("Add WST column: " + data.getName()); |
727 logger.debug("Add WST column: " + wqkms.getName()); | 749 writer.addColumn(data.getName()); |
728 writer.addColumn(wqkms.getName()); | 750 |
729 | 751 if (writeWspTag) { |
730 if (writeWspTag) { | 752 job.setWspTag(data.getName()); |
731 job.setWspTag(wqkms.getName()); | 753 writeWspTag = false; |
732 writeWspTag = false; | 754 } |
733 } | 755 |
734 | 756 for (int i = 0, num = data.size(); i < num; i++) { |
735 for (int i = 0, num = wqkms.size(); i < num; i++) { | 757 data.get(i, buf); |
736 wqkms.get(i, buf); | 758 writer.add(buf); |
737 writer.add(buf); | |
738 } | |
739 } | 759 } |
740 | 760 |
741 FileOutputStream fout = null; | 761 FileOutputStream fout = null; |
742 | 762 |
743 try { | 763 try { |