Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java @ 1164:0398c2b8dbaf
Do only create WSPLGEN and barrier facets if the WSPLGEN job has been added to the Scheduler and if there are digitized geometries existing.
flys-artifacts/trunk@2701 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 12 Sep 2011 11:40:04 +0000 |
parents | efe1b8545f5c |
children | 3b034bb5fce7 |
comparison
equal
deleted
inserted
replaced
1163:2e0739853807 | 1164:0398c2b8dbaf |
---|---|
77 | 77 |
78 public static final int WSPLGEN_DEFAULT_OUTPUT = 0; | 78 public static final int WSPLGEN_DEFAULT_OUTPUT = 0; |
79 | 79 |
80 | 80 |
81 | 81 |
82 /** | |
83 * Inner class that is used to create facets. An instance of this class is | |
84 * used while packaging the data for the WSPLGEN calculation. | |
85 */ | |
86 private static class FacetCreator { | |
87 protected FLYSArtifact artifact; | |
88 protected List<Facet> facets; | |
89 protected String url; | |
90 protected String hash; | |
91 protected String stateId; | |
92 | |
93 public FacetCreator(FLYSArtifact artifact, String hash, String sId) { | |
94 this.facets = new ArrayList<Facet>(2); | |
95 this.artifact = artifact; | |
96 this.hash = hash; | |
97 this.stateId = sId; | |
98 } | |
99 | |
100 protected String getRiver() { | |
101 return artifact.getDataAsString("river"); | |
102 } | |
103 | |
104 protected String getUrl() { | |
105 String url = FLYSUtils.getXPathString(FLYSUtils.XPATH_MAPSERVER_URL); | |
106 url = url + "user-wms"; | |
107 return url; | |
108 } | |
109 | |
110 protected String getSrid() { | |
111 return FLYSUtils.getRiverSrid(artifact); | |
112 } | |
113 | |
114 protected String getBounds() { | |
115 return GeometryUtils.getRiverBounds(getRiver()); | |
116 } | |
117 | |
118 public List<Facet> getFacets() { | |
119 return facets; | |
120 } | |
121 | |
122 public void createWSPLGENFacet() { | |
123 WMSLayerFacet wsplgen = new WMSLayerFacet( | |
124 0, | |
125 FLOODMAP_WSPLGEN, | |
126 "Ergebnis der WSPLGEN Berechnung", | |
127 ComputeType.ADVANCE, | |
128 stateId, | |
129 hash, | |
130 getUrl()); | |
131 | |
132 wsplgen.addLayer( | |
133 artifact.identifier() + MapfileGenerator.MS_WSPLGEN_POSTFIX); | |
134 wsplgen.setSrid(getSrid()); | |
135 wsplgen.setExtent(getBounds()); | |
136 | |
137 facets.add(wsplgen); | |
138 } | |
139 | |
140 public void createBarrierFacet() { | |
141 WMSLayerFacet barriers = new WMSLayerFacet( | |
142 1, | |
143 FLOODMAP_WSPLGEN, | |
144 "Rohre/Graeben/Daemme", | |
145 ComputeType.ADVANCE, | |
146 stateId, | |
147 hash, | |
148 getUrl()); | |
149 | |
150 barriers.addLayer( | |
151 artifact.identifier() + MapfileGenerator.MS_BARRIERS_POSTFIX); | |
152 barriers.setSrid(getSrid()); | |
153 barriers.setExtent(getBounds()); | |
154 | |
155 facets.add(barriers); | |
156 } | |
157 } // end of FacetCreator | |
158 | |
159 | |
160 | |
82 @Override | 161 @Override |
83 public Object computeAdvance( | 162 public Object computeAdvance( |
84 FLYSArtifact artifact, | 163 FLYSArtifact artifact, |
85 String hash, | 164 String hash, |
86 CallContext context, | 165 CallContext context, |
96 return null; | 175 return null; |
97 } | 176 } |
98 | 177 |
99 WSPLGENCalculation calculation = new WSPLGENCalculation(); | 178 WSPLGENCalculation calculation = new WSPLGENCalculation(); |
100 | 179 |
180 FacetCreator facetCreator = new FacetCreator(artifact, hash, getID()); | |
181 | |
101 WSPLGENJob job = prepareWSPLGENJob( | 182 WSPLGENJob job = prepareWSPLGENJob( |
102 artifact, | 183 artifact, |
184 facetCreator, | |
103 artifactDir, | 185 artifactDir, |
104 context, | 186 context, |
105 calculation); | 187 calculation); |
106 | 188 |
107 if (job == null) { | 189 if (job == null) { |
115 } | 197 } |
116 | 198 |
117 Scheduler scheduler = Scheduler.getInstance(); | 199 Scheduler scheduler = Scheduler.getInstance(); |
118 scheduler.addJob(job); | 200 scheduler.addJob(job); |
119 | 201 |
120 String url = FLYSUtils.getXPathString(FLYSUtils.XPATH_MAPSERVER_URL); | 202 facetCreator.createWSPLGENFacet(); |
121 url = url + "user-wms"; | |
122 | |
123 WMSLayerFacet wsplgen = new WMSLayerFacet( | |
124 0, | |
125 FLOODMAP_WSPLGEN, | |
126 "Ergebnis der WSPLGEN Berechnung", | |
127 ComputeType.ADVANCE, | |
128 getID(), | |
129 hash, | |
130 url); | |
131 | |
132 String srid = FLYSUtils.getRiverSrid(artifact); | |
133 String river = artifact.getDataAsString("river"); | |
134 | |
135 wsplgen.addLayer( | |
136 artifact.identifier() + MapfileGenerator.MS_WSPLGEN_POSTFIX); | |
137 wsplgen.setSrid(srid); | |
138 wsplgen.setExtent(GeometryUtils.getRiverBounds(river)); | |
139 | |
140 WMSLayerFacet barriers = new WMSLayerFacet( | |
141 1, | |
142 FLOODMAP_WSPLGEN, | |
143 "Rohre/Graeben/Daemme", | |
144 ComputeType.ADVANCE, | |
145 getID(), | |
146 hash, | |
147 url); | |
148 | |
149 barriers.addLayer( | |
150 artifact.identifier() + MapfileGenerator.MS_BARRIERS_POSTFIX); | |
151 barriers.setSrid(srid); | |
152 barriers.setExtent(GeometryUtils.getRiverBounds(river)); | |
153 | 203 |
154 CalculationResult res = new CalculationResult(null, calculation); | 204 CalculationResult res = new CalculationResult(null, calculation); |
155 WSPLGENReportFacet report= new WSPLGENReportFacet( | 205 WSPLGENReportFacet report= new WSPLGENReportFacet( |
156 ComputeType.ADVANCE, hash, getID(), res); | 206 ComputeType.ADVANCE, hash, getID(), res); |
157 | 207 |
158 facets.add(wsplgen); | |
159 facets.add(barriers); | |
160 facets.add(report); | 208 facets.add(report); |
209 facets.addAll(facetCreator.getFacets()); | |
161 | 210 |
162 context.afterCall(CallContext.BACKGROUND); | 211 context.afterCall(CallContext.BACKGROUND); |
163 | 212 |
164 return null; | 213 return null; |
165 } | 214 } |
213 } | 262 } |
214 | 263 |
215 | 264 |
216 protected WSPLGENJob prepareWSPLGENJob( | 265 protected WSPLGENJob prepareWSPLGENJob( |
217 FLYSArtifact artifact, | 266 FLYSArtifact artifact, |
267 FacetCreator facetCreator, | |
218 File artifactDir, | 268 File artifactDir, |
219 CallContext context, | 269 CallContext context, |
220 WSPLGENCalculation calculation | 270 WSPLGENCalculation calculation |
221 ) { | 271 ) { |
222 logger.debug("FloodMapState.prepareWSPLGENJob"); | 272 logger.debug("FloodMapState.prepareWSPLGENJob"); |
232 setOut(artifact, job); | 282 setOut(artifact, job); |
233 setRange(artifact, job); | 283 setRange(artifact, job); |
234 setDelta(artifact, job); | 284 setDelta(artifact, job); |
235 setGel(artifact, job); | 285 setGel(artifact, job); |
236 setDist(artifact, job); | 286 setDist(artifact, job); |
237 setLine(artifact, artifactDir, job); | 287 setLine(artifact, facetCreator, artifactDir, job); |
238 setAxis(artifact, artifactDir, job); | 288 setAxis(artifact, artifactDir, job); |
239 setPro(artifact, artifactDir, job); | 289 setPro(artifact, artifactDir, job); |
240 setDgm(artifact, job); | 290 setDgm(artifact, job); |
241 setArea(artifact, artifactDir, job); | 291 setArea(artifact, artifactDir, job); |
242 setOutFile(artifact, job); | 292 setOutFile(artifact, job); |
325 // nothing to do here | 375 // nothing to do here |
326 } | 376 } |
327 } | 377 } |
328 | 378 |
329 | 379 |
330 protected void setLine(FLYSArtifact artifact, File dir, WSPLGENJob job) { | 380 protected void setLine( |
381 FLYSArtifact artifact, | |
382 FacetCreator facetCreator, | |
383 File dir, | |
384 WSPLGENJob job | |
385 ) { | |
331 String geoJSON = artifact.getDataAsString("uesk.barriers"); | 386 String geoJSON = artifact.getDataAsString("uesk.barriers"); |
332 String srid = FLYSUtils.getRiverSrid(artifact); | 387 String srid = FLYSUtils.getRiverSrid(artifact); |
333 String srs = "EPSG:" + srid; | 388 String srs = "EPSG:" + srid; |
389 | |
390 if (geoJSON == null || geoJSON.length() == 0) { | |
391 logger.debug("No barrier features in parameterization existing."); | |
392 return; | |
393 } | |
334 | 394 |
335 SimpleFeatureType ft = getBarriersFeatureType( | 395 SimpleFeatureType ft = getBarriersFeatureType( |
336 "barriers", srs, Geometry.class); | 396 "barriers", srs, Geometry.class); |
337 | 397 |
338 List<SimpleFeature> features = GeometryUtils.parseGeoJSON(geoJSON, ft); | 398 List<SimpleFeature> features = GeometryUtils.parseGeoJSON(geoJSON, ft); |
370 if (p) { | 430 if (p) { |
371 logger.debug( | 431 logger.debug( |
372 "Successfully created barrier polygon shapefile. " + | 432 "Successfully created barrier polygon shapefile. " + |
373 "Write shapefile path into WSPLGEN job."); | 433 "Write shapefile path into WSPLGEN job."); |
374 job.addLin(shapePolys.getAbsolutePath()); | 434 job.addLin(shapePolys.getAbsolutePath()); |
435 } | |
436 | |
437 if (p || l) { | |
438 facetCreator.createBarrierFacet(); | |
375 } | 439 } |
376 } | 440 } |
377 | 441 |
378 | 442 |
379 protected SimpleFeatureType getBarriersFeatureType( | 443 protected SimpleFeatureType getBarriersFeatureType( |