Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java @ 1650:aaf8d32f85bd
Improved Facet creation for floodmaps - WSPLGEN and barriers Facets are only created if the calculation was successful.
flys-artifacts/trunk@2837 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 27 Sep 2011 12:40:42 +0000 |
parents | 74142aa5d938 |
children | 3bf464ec436f |
comparison
equal
deleted
inserted
replaced
1649:74142aa5d938 | 1650:aaf8d32f85bd |
---|---|
37 import de.intevation.flys.artifacts.FLYSArtifact; | 37 import de.intevation.flys.artifacts.FLYSArtifact; |
38 import de.intevation.flys.artifacts.model.CalculationMessage; | 38 import de.intevation.flys.artifacts.model.CalculationMessage; |
39 import de.intevation.flys.artifacts.model.CalculationResult; | 39 import de.intevation.flys.artifacts.model.CalculationResult; |
40 import de.intevation.flys.artifacts.model.FacetTypes; | 40 import de.intevation.flys.artifacts.model.FacetTypes; |
41 import de.intevation.flys.artifacts.model.WQKms; | 41 import de.intevation.flys.artifacts.model.WQKms; |
42 import de.intevation.flys.artifacts.model.WMSLayerFacet; | |
43 import de.intevation.flys.artifacts.model.WSPLGENCalculation; | 42 import de.intevation.flys.artifacts.model.WSPLGENCalculation; |
44 import de.intevation.flys.artifacts.model.WSPLGENJob; | 43 import de.intevation.flys.artifacts.model.WSPLGENJob; |
45 import de.intevation.flys.artifacts.model.WSPLGENReportFacet; | 44 import de.intevation.flys.artifacts.model.WSPLGENReportFacet; |
46 import de.intevation.flys.artifacts.resources.Resources; | 45 import de.intevation.flys.artifacts.resources.Resources; |
47 import de.intevation.flys.artifacts.states.DefaultState.ComputeType; | 46 import de.intevation.flys.artifacts.states.DefaultState.ComputeType; |
48 import de.intevation.flys.exports.WstWriter; | 47 import de.intevation.flys.exports.WstWriter; |
49 import de.intevation.flys.utils.FLYSUtils; | 48 import de.intevation.flys.utils.FLYSUtils; |
50 import de.intevation.flys.utils.GeometryUtils; | 49 import de.intevation.flys.utils.GeometryUtils; |
51 import de.intevation.flys.utils.MapfileGenerator; | 50 import de.intevation.flys.wsplgen.FacetCreator; |
52 import de.intevation.flys.wsplgen.JobObserver; | 51 import de.intevation.flys.wsplgen.JobObserver; |
53 import de.intevation.flys.wsplgen.Scheduler; | 52 import de.intevation.flys.wsplgen.Scheduler; |
54 | 53 |
55 | 54 |
56 public class FloodMapState | 55 public class FloodMapState |
76 public static final String WSPLGEN_QPS = "qps.shp"; | 75 public static final String WSPLGEN_QPS = "qps.shp"; |
77 public static final String WSPLGEN_FLOODPLAIN = "talaue.shp"; | 76 public static final String WSPLGEN_FLOODPLAIN = "talaue.shp"; |
78 public static final String WSPLGEN_WSP_FILE = "waterlevel.wst"; | 77 public static final String WSPLGEN_WSP_FILE = "waterlevel.wst"; |
79 public static final String WSPLGEN_OUTPUT_FILE = "wsplgen.shp"; | 78 public static final String WSPLGEN_OUTPUT_FILE = "wsplgen.shp"; |
80 | 79 |
81 public static final String I18N_WSPLGEN_RESULT = "floodmap.uesk"; | |
82 public static final String I18N_WSPLGEN_DEFAULT = "floodmap.uesk"; | |
83 public static final String I18N_BARRIERS = "floodmap.barriers"; | |
84 public static final String I18N_BARRIERS_DEFAULT = "floodmap.barriers"; | |
85 | |
86 public static final int WSPLGEN_DEFAULT_OUTPUT = 0; | 80 public static final int WSPLGEN_DEFAULT_OUTPUT = 0; |
87 | |
88 | |
89 | |
90 /** | |
91 * Inner class that is used to create facets. An instance of this class is | |
92 * used while packaging the data for the WSPLGEN calculation. | |
93 */ | |
94 private static class FacetCreator { | |
95 protected FLYSArtifact artifact; | |
96 protected CallContext cc; | |
97 protected List<Facet> facets; | |
98 protected String url; | |
99 protected String hash; | |
100 protected String stateId; | |
101 | |
102 public FacetCreator( | |
103 FLYSArtifact artifact, | |
104 CallContext cc, | |
105 String hash, | |
106 String sId | |
107 ) { | |
108 this.facets = new ArrayList<Facet>(2); | |
109 this.artifact = artifact; | |
110 this.cc = cc; | |
111 this.hash = hash; | |
112 this.stateId = sId; | |
113 } | |
114 | |
115 protected String getRiver() { | |
116 return artifact.getDataAsString("river"); | |
117 } | |
118 | |
119 protected String getUrl() { | |
120 String url = FLYSUtils.getXPathString(FLYSUtils.XPATH_MAPSERVER_URL); | |
121 url = url + "user-wms"; | |
122 return url; | |
123 } | |
124 | |
125 protected String getSrid() { | |
126 return FLYSUtils.getRiverSrid(artifact); | |
127 } | |
128 | |
129 protected String getWSPLGENBounds() { | |
130 String river = getRiver(); | |
131 double kms[] = FLYSUtils.getKmRange(artifact); | |
132 | |
133 CrossSectionTrack a = | |
134 CrossSectionTrack.getCrossSectionTrack(river, kms[0]); | |
135 | |
136 CrossSectionTrack b = | |
137 CrossSectionTrack.getCrossSectionTrack(river, kms[1]); | |
138 | |
139 if (a == null || b == null) { | |
140 return null; | |
141 } | |
142 | |
143 return GeometryUtils.createOLBounds(a.getGeom(), b.getGeom()); | |
144 } | |
145 | |
146 protected String getBounds() { | |
147 return GeometryUtils.getRiverBounds(getRiver()); | |
148 } | |
149 | |
150 public List<Facet> getFacets() { | |
151 return facets; | |
152 } | |
153 | |
154 public void createWSPLGENFacet() { | |
155 WMSLayerFacet wsplgen = new WMSLayerFacet( | |
156 0, | |
157 FLOODMAP_WSPLGEN, | |
158 Resources.getMsg( | |
159 cc.getMeta(), | |
160 I18N_WSPLGEN_RESULT, | |
161 I18N_WSPLGEN_DEFAULT), | |
162 ComputeType.ADVANCE, | |
163 stateId, | |
164 hash, | |
165 getUrl()); | |
166 | |
167 String bounds = getWSPLGENBounds(); | |
168 | |
169 if (bounds == null || bounds.length() == 0) { | |
170 bounds = getBounds(); | |
171 } | |
172 | |
173 wsplgen.addLayer( | |
174 artifact.identifier() + MapfileGenerator.MS_WSPLGEN_POSTFIX); | |
175 wsplgen.setSrid(getSrid()); | |
176 wsplgen.setExtent(bounds); | |
177 | |
178 facets.add(wsplgen); | |
179 } | |
180 | |
181 public void createBarrierFacet() { | |
182 WMSLayerFacet barriers = new WMSLayerFacet( | |
183 1, | |
184 FLOODMAP_WSPLGEN, | |
185 Resources.getMsg( | |
186 cc.getMeta(), | |
187 I18N_BARRIERS, | |
188 I18N_BARRIERS_DEFAULT), | |
189 ComputeType.ADVANCE, | |
190 stateId, | |
191 hash, | |
192 getUrl()); | |
193 | |
194 barriers.addLayer( | |
195 artifact.identifier() + MapfileGenerator.MS_BARRIERS_POSTFIX); | |
196 barriers.setSrid(getSrid()); | |
197 barriers.setExtent(getBounds()); | |
198 | |
199 facets.add(barriers); | |
200 } | |
201 } // end of FacetCreator | |
202 | 81 |
203 | 82 |
204 | 83 |
205 @Override | 84 @Override |
206 public Object computeAdvance( | 85 public Object computeAdvance( |
220 } | 99 } |
221 | 100 |
222 WSPLGENCalculation calculation = new WSPLGENCalculation(); | 101 WSPLGENCalculation calculation = new WSPLGENCalculation(); |
223 | 102 |
224 FacetCreator facetCreator = new FacetCreator( | 103 FacetCreator facetCreator = new FacetCreator( |
225 artifact, context, hash, getID()); | 104 artifact, context, hash, getID(), facets); |
226 | 105 |
227 WSPLGENJob job = prepareWSPLGENJob( | 106 WSPLGENJob job = prepareWSPLGENJob( |
228 artifact, | 107 artifact, |
229 facetCreator, | 108 facetCreator, |
230 artifactDir, | 109 artifactDir, |
249 | 128 |
250 logger.error("No WSPLGEN processing has been started!"); | 129 logger.error("No WSPLGEN processing has been started!"); |
251 | 130 |
252 return null; | 131 return null; |
253 } | 132 } |
254 | |
255 facetCreator.createWSPLGENFacet(); | |
256 | |
257 facets.addAll(facetCreator.getFacets()); | |
258 | 133 |
259 context.afterCall(CallContext.BACKGROUND); | 134 context.afterCall(CallContext.BACKGROUND); |
260 context.addBackgroundMessage(new CalculationMessage( | 135 context.addBackgroundMessage(new CalculationMessage( |
261 JobObserver.STEPS.length, | 136 JobObserver.STEPS.length, |
262 0, | 137 0, |
331 logger.debug("FloodMapState.prepareWSPLGENJob"); | 206 logger.debug("FloodMapState.prepareWSPLGENJob"); |
332 | 207 |
333 WSPLGENJob job = new WSPLGENJob( | 208 WSPLGENJob job = new WSPLGENJob( |
334 artifact, | 209 artifact, |
335 artifactDir, | 210 artifactDir, |
211 facetCreator, | |
336 context, | 212 context, |
337 calculation); | 213 calculation); |
338 | 214 |
339 File paraFile = new File(artifactDir, WSPLGEN_PARAMETER_FILE); | 215 File paraFile = new File(artifactDir, WSPLGEN_PARAMETER_FILE); |
340 | 216 |