Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/FloodMapState.java @ 8856:5e38e2924c07 3.2.x
Fix code style.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 18 Jan 2018 20:12:01 +0100 |
parents | e9d912c97fa8 |
children | 3f49835a00c3 0a5239a1e46e |
comparison
equal
deleted
inserted
replaced
8855:d7c005e12af0 | 8856:5e38e2924c07 |
---|---|
102 | 102 |
103 public static final int WSPLGEN_DEFAULT_OUTPUT = 0; | 103 public static final int WSPLGEN_DEFAULT_OUTPUT = 0; |
104 | 104 |
105 private static final String HWS_LINES_SHAPE = "hws-lines.shp"; | 105 private static final String HWS_LINES_SHAPE = "hws-lines.shp"; |
106 | 106 |
107 private static final String I18N_HWS_POINTS_OFFICIAL = "floodmap.hws.points.official"; | 107 private static final String I18N_HWS_POINTS_OFFICIAL = |
108 private static final String I18N_HWS_LINES_OFFICIAL = "floodmap.hws.lines.official"; | 108 "floodmap.hws.points.official"; |
109 private static final String I18N_HWS_LINES_OFFICIAL = | |
110 "floodmap.hws.lines.official"; | |
109 private static final String HWS_LINES = "hws-lines"; | 111 private static final String HWS_LINES = "hws-lines"; |
110 private static final String HWS_POINT_SHAPE = "hws-points.shp"; | 112 private static final String HWS_POINT_SHAPE = "hws-points.shp"; |
111 private static final String HWS_POINTS = "hws-points"; | 113 private static final String HWS_POINTS = "hws-points"; |
112 | 114 |
113 | 115 |
114 /* List of possible map files this state handles . */ | 116 /* List of possible map files this state handles . */ |
115 private static final String[] POSSIBLE_ADDITIONAL_MAPFILES = {HWS_LINES, | 117 private static final String[] POSSIBLE_ADDITIONAL_MAPFILES = { |
116 HWS_POINTS, | 118 HWS_LINES, |
117 WSPLGEN_USER_RGD, | 119 HWS_POINTS, |
118 "barriers-lines", | 120 WSPLGEN_USER_RGD, |
119 "barriers-poly"}; | 121 "barriers-lines", |
122 "barriers-poly"}; | |
120 | 123 |
121 | 124 |
122 | 125 |
123 /** | 126 /** |
124 * @param orig | 127 * @param orig |
156 File thisDir = getDirectory((D4EArtifact) owner); | 159 File thisDir = getDirectory((D4EArtifact) owner); |
157 | 160 |
158 FileTools.copyDirectory(origDir, thisDir); | 161 FileTools.copyDirectory(origDir, thisDir); |
159 | 162 |
160 for (String candidate: POSSIBLE_ADDITIONAL_MAPFILES) { | 163 for (String candidate: POSSIBLE_ADDITIONAL_MAPFILES) { |
161 File f = new File(thisDir, MapfileGenerator.MS_LAYER_PREFIX + candidate); | 164 File f = new File( |
165 thisDir, MapfileGenerator.MS_LAYER_PREFIX + candidate); | |
162 if (f.exists()) { | 166 if (f.exists()) { |
163 log.debug("Fixing artifiact id's in: " + f); | 167 log.debug("Fixing artifiact id's in: " + f); |
164 try { | 168 try { |
165 String content = FileUtils.readFileToString(f); | 169 String content = FileUtils.readFileToString(f); |
166 FileUtils.writeStringToFile(f, | 170 FileUtils.writeStringToFile(f, |
167 content.replaceAll(orig.identifier(), owner.identifier())); | 171 content.replaceAll( |
172 orig.identifier(), owner.identifier())); | |
168 } catch (IOException e) { | 173 } catch (IOException e) { |
169 log.error("Failed to rewrite file: " + f + " Error: " + e.getMessage()); | 174 log.error("Failed to rewrite file: " + f |
175 + " Error: " + e.getMessage()); | |
170 } | 176 } |
171 } | 177 } |
172 } | 178 } |
173 } | 179 } |
174 | 180 |
195 for (String layer: layers) { | 201 for (String layer: layers) { |
196 log.debug("Have layer: " + layer); | 202 log.debug("Have layer: " + layer); |
197 if (layer.contains(orig.identifier())) { | 203 if (layer.contains(orig.identifier())) { |
198 wms.removeLayer(layer); | 204 wms.removeLayer(layer); |
199 | 205 |
200 String newLayer = layer.replace(orig.identifier(), owner.identifier()); | 206 String newLayer = layer.replace( |
207 orig.identifier(), owner.identifier()); | |
201 | 208 |
202 wms.addLayer(newLayer); | 209 wms.addLayer(newLayer); |
203 | 210 |
204 log.debug( | 211 log.debug( |
205 "Replaced layer: " + layer + " with " + newLayer); | 212 "Replaced layer: " + layer + " with " + newLayer); |
296 return artifactDir; | 303 return artifactDir; |
297 } | 304 } |
298 | 305 |
299 | 306 |
300 /** | 307 /** |
301 * Removes the directory and all its content where the required data and the | 308 * Removes directory and all its content where the required data and the |
302 * results of WSPLGEN are stored. Should be called in endOfLife(). | 309 * results of WSPLGEN are stored. Should be called in endOfLife(). |
303 */ | 310 */ |
304 protected void removeDirectory(D4EArtifact artifact) { | 311 protected void removeDirectory(D4EArtifact artifact) { |
305 String shapePath = RiverUtils.getXPathString( | 312 String shapePath = RiverUtils.getXPathString( |
306 RiverUtils.XPATH_FLOODMAP_SHAPEFILE_DIR); | 313 RiverUtils.XPATH_FLOODMAP_SHAPEFILE_DIR); |
441 artifact, | 448 artifact, |
442 artifactDir, | 449 artifactDir, |
443 MapfileGenerator.MS_LAYER_PREFIX + HWS_LINES, | 450 MapfileGenerator.MS_LAYER_PREFIX + HWS_LINES, |
444 HWS_LINES_SHAPE, | 451 HWS_LINES_SHAPE, |
445 "LINE", | 452 "LINE", |
446 "31467", // XXX: This should be dynamically fetched from database. | 453 "31467", // XXX: should be dynamically fetched from database. |
447 "hws"); | 454 "hws"); |
448 job.addLin(artifactDir + "/" + HWS_LINES_SHAPE); | 455 job.addLin(artifactDir + "/" + HWS_LINES_SHAPE); |
449 facetCreator.createShapeFacet(I18N_HWS_LINES_OFFICIAL, | 456 facetCreator.createShapeFacet(I18N_HWS_LINES_OFFICIAL, |
450 MapfileGenerator.MS_LAYER_PREFIX + HWS_LINES, | 457 MapfileGenerator.MS_LAYER_PREFIX + HWS_LINES, |
451 FLOODMAP_HWS_LINES,2); | 458 FLOODMAP_HWS_LINES,2); |
471 info.setData(hwsShapefile); | 478 info.setData(hwsShapefile); |
472 info.setSrid(srid); | 479 info.setSrid(srid); |
473 info.setGroupTitle(group); | 480 info.setGroupTitle(group); |
474 info.setGroup(group + artifact.identifier()); | 481 info.setGroup(group + artifact.identifier()); |
475 MapfileGenerator generator = new ArtifactMapfileGenerator(); | 482 MapfileGenerator generator = new ArtifactMapfileGenerator(); |
476 Template tpl = generator.getTemplateByName(MapfileGenerator.SHP_LAYER_TEMPLATE); | 483 Template tpl = generator.getTemplateByName( |
484 MapfileGenerator.SHP_LAYER_TEMPLATE); | |
477 try { | 485 try { |
478 File layer = new File(artifactDir.getCanonicalPath() + "/" + name); | 486 File layer = new File(artifactDir.getCanonicalPath() + "/" + name); |
479 generator.writeLayer(info, layer, tpl); | 487 generator.writeLayer(info, layer, tpl); |
480 List<String> layers = new ArrayList<String>(); | 488 List<String> layers = new ArrayList<String>(); |
481 layers.add(layer.getAbsolutePath()); | 489 layers.add(layer.getAbsolutePath()); |
600 | 608 |
601 String scenario = job.getGel(); | 609 String scenario = job.getGel(); |
602 | 610 |
603 boolean l = GeometryUtils.writeShapefile( | 611 boolean l = GeometryUtils.writeShapefile( |
604 shapeLines, | 612 shapeLines, |
605 GeometryUtils.buildFeatureType("lines", srs, LineString.class, obj), | 613 GeometryUtils.buildFeatureType( |
614 "lines", srs, LineString.class, obj), | |
606 fcs[0]); | 615 fcs[0]); |
607 | 616 |
608 if (l) { | 617 if (l) { |
609 log.debug( | 618 log.debug( |
610 "Successfully created barrier line shapefile. " + | 619 "Successfully created barrier line shapefile. " + |
626 } | 635 } |
627 } | 636 } |
628 | 637 |
629 boolean p = GeometryUtils.writeShapefile( | 638 boolean p = GeometryUtils.writeShapefile( |
630 shapePolys, | 639 shapePolys, |
631 GeometryUtils.buildFeatureType("polygons", srs, Polygon.class, obj), | 640 GeometryUtils.buildFeatureType( |
641 "polygons", srs, Polygon.class, obj), | |
632 fcs[1]); | 642 fcs[1]); |
633 | 643 |
634 | 644 |
635 if (p) { | 645 if (p) { |
636 log.debug( | 646 log.debug( |
689 | 699 |
690 return GeometryUtils.buildFeatureType(name, srs, type, attrs); | 700 return GeometryUtils.buildFeatureType(name, srs, type, attrs); |
691 } | 701 } |
692 | 702 |
693 | 703 |
694 protected FeatureCollection[] splitLinesAndPolygons(List<SimpleFeature> f) { | 704 protected FeatureCollection[] splitLinesAndPolygons( |
705 List<SimpleFeature> f | |
706 ) { | |
695 FeatureCollection lines = FeatureCollections.newCollection(); | 707 FeatureCollection lines = FeatureCollections.newCollection(); |
696 FeatureCollection polygons = FeatureCollections.newCollection(); | 708 FeatureCollection polygons = FeatureCollections.newCollection(); |
697 | 709 |
698 for (SimpleFeature feature: f) { | 710 for (SimpleFeature feature: f) { |
699 Geometry geom = (Geometry) feature.getDefaultGeometry(); | 711 Geometry geom = (Geometry) feature.getDefaultGeometry(); |
855 | 867 |
856 File qpsShape = new File(dir, WSPLGEN_QPS); | 868 File qpsShape = new File(dir, WSPLGEN_QPS); |
857 | 869 |
858 boolean q = GeometryUtils.writeShapefile( | 870 boolean q = GeometryUtils.writeShapefile( |
859 qpsShape, | 871 qpsShape, |
860 GeometryUtils.buildFeatureType("qps", srs, LineString.class, attrs), | 872 GeometryUtils.buildFeatureType( |
873 "qps", srs, LineString.class, attrs), | |
861 collection); | 874 collection); |
862 | 875 |
863 if (q) { | 876 if (q) { |
864 job.setPro(qpsShape.getAbsolutePath()); | 877 job.setPro(qpsShape.getAbsolutePath()); |
865 } | 878 } |
964 ? RiverUtils.getArtifact(otherArtifact, cc) | 977 ? RiverUtils.getArtifact(otherArtifact, cc) |
965 : flys; | 978 : flys; |
966 | 979 |
967 log.debug("Use waterlevel provided by Artifact: " + src.identifier()); | 980 log.debug("Use waterlevel provided by Artifact: " + src.identifier()); |
968 | 981 |
969 // The state actually depends on the kind of artifact. E.g. StaticWQKmsArtifact needs other state | 982 // The state actually depends on the kind of artifact. |
983 // E.g. StaticWQKmsArtifact needs other state | |
970 Object computed = src.compute( | 984 Object computed = src.compute( |
971 cc, | 985 cc, |
972 //null, | 986 //null, |
973 //WINFO_WSP_STATE_ID, | 987 //WINFO_WSP_STATE_ID, |
974 ComputeType.ADVANCE, | 988 ComputeType.ADVANCE, |
981 // Regular WSP calculation | 995 // Regular WSP calculation |
982 if (computed instanceof CalculationResult) { | 996 if (computed instanceof CalculationResult) { |
983 CalculationResult rawData = (CalculationResult) computed; | 997 CalculationResult rawData = (CalculationResult) computed; |
984 WQKms[] wqkms; | 998 WQKms[] wqkms; |
985 if (rawData.getData() instanceof FixRealizingResult) { | 999 if (rawData.getData() instanceof FixRealizingResult) { |
986 wqkms = (WQKms[]) ((FixRealizingResult) rawData.getData()).getWQKms(); | 1000 wqkms = (WQKms[])((FixRealizingResult)rawData.getData()) |
1001 .getWQKms(); | |
987 } | 1002 } |
988 else { | 1003 else { |
989 wqkms = (WQKms[]) rawData.getData(); | 1004 wqkms = (WQKms[]) rawData.getData(); |
990 } | 1005 } |
991 return wqkms == null || idx == -1 || idx >= wqkms.length | 1006 return wqkms == null || idx == -1 || idx >= wqkms.length |
997 WQKms wqkms = (WQKms) computed; | 1012 WQKms wqkms = (WQKms) computed; |
998 return (WQKms) computed; | 1013 return (WQKms) computed; |
999 } | 1014 } |
1000 else if (computed == null && src instanceof StaticWKmsArtifact) { | 1015 else if (computed == null && src instanceof StaticWKmsArtifact) { |
1001 // Floodmarks and protection. | 1016 // Floodmarks and protection. |
1002 WQKms wqkms = WQKms.fromWKms(((StaticWKmsArtifact) src).getWKms(0), 1d); | 1017 WQKms wqkms = WQKms.fromWKms( |
1018 ((StaticWKmsArtifact)src).getWKms(0), 1d); | |
1003 return wqkms; | 1019 return wqkms; |
1004 } | 1020 } |
1005 | 1021 |
1006 log.warn("getWQKms cannot handle " + computed.getClass() + " " + src.getClass()); | 1022 log.warn("getWQKms cannot handle " + computed.getClass() |
1023 + " " + src.getClass()); | |
1007 return null; | 1024 return null; |
1008 } | 1025 } |
1009 | 1026 |
1010 | 1027 |
1011 protected void setWsp( | 1028 protected void setWsp( |