Mercurial > dive4elements > river
changeset 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 | a7def20539fb |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WSPLGENJob.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java flys-artifacts/src/main/java/de/intevation/flys/wsplgen/FacetCreator.java flys-artifacts/src/main/java/de/intevation/flys/wsplgen/JobExecutor.java |
diffstat | 5 files changed, 191 insertions(+), 134 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Tue Sep 27 11:33:45 2011 +0000 +++ b/flys-artifacts/ChangeLog Tue Sep 27 12:40:42 2011 +0000 @@ -1,3 +1,22 @@ +2011-09-27 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/wsplgen/FacetCreator.java: New. Code + from FloodMapState moved to its own class with the intent, to use it in + classes different from FloodMapState. + + * src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java: + Removed the inner class FacetCreator. + + * src/main/java/de/intevation/flys/artifacts/model/WSPLGENJob.java: Stores + an instance of FacetCreator. + NOTE: Maybe we should move the WSPLGEN parameters into an own class + which might be serializable. + + * src/main/java/de/intevation/flys/wsplgen/JobExecutor.java: Use the + FacetCreator instance stored in the WSPLGENJob to create a new WSPLGEN + facet if the calculation was successfully (without errors). Finally, the + facets of FacetCreator are added to the Facet list of the FLYSArtifacts. + 2011-09-27 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WSPLGENJob.java Tue Sep 27 11:33:45 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WSPLGENJob.java Tue Sep 27 12:40:42 2011 +0000 @@ -11,6 +11,7 @@ import de.intevation.artifacts.CallContext; import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.wsplgen.FacetCreator; public class WSPLGENJob { @@ -25,6 +26,8 @@ protected WSPLGENCalculation calculation; + protected FacetCreator facetCreator; + protected File workingDir; protected String dgm; @@ -52,13 +55,15 @@ public WSPLGENJob( FLYSArtifact flys, File workingDir, + FacetCreator facetCreator, CallContext context, WSPLGENCalculation calculation) { - this.artifact = flys; - this.workingDir = workingDir; - this.callContext = context; - this.calculation = calculation; + this.artifact = flys; + this.workingDir = workingDir; + this.facetCreator = facetCreator; + this.callContext = context; + this.calculation = calculation; out = -1; start = Double.NaN; @@ -81,6 +86,11 @@ } + public FacetCreator getFacetCreator() { + return facetCreator; + } + + public WSPLGENCalculation getCalculation() { return calculation; }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java Tue Sep 27 11:33:45 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java Tue Sep 27 12:40:42 2011 +0000 @@ -39,7 +39,6 @@ import de.intevation.flys.artifacts.model.CalculationResult; import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.model.WQKms; -import de.intevation.flys.artifacts.model.WMSLayerFacet; import de.intevation.flys.artifacts.model.WSPLGENCalculation; import de.intevation.flys.artifacts.model.WSPLGENJob; import de.intevation.flys.artifacts.model.WSPLGENReportFacet; @@ -48,7 +47,7 @@ import de.intevation.flys.exports.WstWriter; import de.intevation.flys.utils.FLYSUtils; import de.intevation.flys.utils.GeometryUtils; -import de.intevation.flys.utils.MapfileGenerator; +import de.intevation.flys.wsplgen.FacetCreator; import de.intevation.flys.wsplgen.JobObserver; import de.intevation.flys.wsplgen.Scheduler; @@ -78,130 +77,10 @@ public static final String WSPLGEN_WSP_FILE = "waterlevel.wst"; public static final String WSPLGEN_OUTPUT_FILE = "wsplgen.shp"; - public static final String I18N_WSPLGEN_RESULT = "floodmap.uesk"; - public static final String I18N_WSPLGEN_DEFAULT = "floodmap.uesk"; - public static final String I18N_BARRIERS = "floodmap.barriers"; - public static final String I18N_BARRIERS_DEFAULT = "floodmap.barriers"; - public static final int WSPLGEN_DEFAULT_OUTPUT = 0; - /** - * Inner class that is used to create facets. An instance of this class is - * used while packaging the data for the WSPLGEN calculation. - */ - private static class FacetCreator { - protected FLYSArtifact artifact; - protected CallContext cc; - protected List<Facet> facets; - protected String url; - protected String hash; - protected String stateId; - - public FacetCreator( - FLYSArtifact artifact, - CallContext cc, - String hash, - String sId - ) { - this.facets = new ArrayList<Facet>(2); - this.artifact = artifact; - this.cc = cc; - this.hash = hash; - this.stateId = sId; - } - - protected String getRiver() { - return artifact.getDataAsString("river"); - } - - protected String getUrl() { - String url = FLYSUtils.getXPathString(FLYSUtils.XPATH_MAPSERVER_URL); - url = url + "user-wms"; - return url; - } - - protected String getSrid() { - return FLYSUtils.getRiverSrid(artifact); - } - - protected String getWSPLGENBounds() { - String river = getRiver(); - double kms[] = FLYSUtils.getKmRange(artifact); - - CrossSectionTrack a = - CrossSectionTrack.getCrossSectionTrack(river, kms[0]); - - CrossSectionTrack b = - CrossSectionTrack.getCrossSectionTrack(river, kms[1]); - - if (a == null || b == null) { - return null; - } - - return GeometryUtils.createOLBounds(a.getGeom(), b.getGeom()); - } - - protected String getBounds() { - return GeometryUtils.getRiverBounds(getRiver()); - } - - public List<Facet> getFacets() { - return facets; - } - - public void createWSPLGENFacet() { - WMSLayerFacet wsplgen = new WMSLayerFacet( - 0, - FLOODMAP_WSPLGEN, - Resources.getMsg( - cc.getMeta(), - I18N_WSPLGEN_RESULT, - I18N_WSPLGEN_DEFAULT), - ComputeType.ADVANCE, - stateId, - hash, - getUrl()); - - String bounds = getWSPLGENBounds(); - - if (bounds == null || bounds.length() == 0) { - bounds = getBounds(); - } - - wsplgen.addLayer( - artifact.identifier() + MapfileGenerator.MS_WSPLGEN_POSTFIX); - wsplgen.setSrid(getSrid()); - wsplgen.setExtent(bounds); - - facets.add(wsplgen); - } - - public void createBarrierFacet() { - WMSLayerFacet barriers = new WMSLayerFacet( - 1, - FLOODMAP_WSPLGEN, - Resources.getMsg( - cc.getMeta(), - I18N_BARRIERS, - I18N_BARRIERS_DEFAULT), - ComputeType.ADVANCE, - stateId, - hash, - getUrl()); - - barriers.addLayer( - artifact.identifier() + MapfileGenerator.MS_BARRIERS_POSTFIX); - barriers.setSrid(getSrid()); - barriers.setExtent(getBounds()); - - facets.add(barriers); - } - } // end of FacetCreator - - - @Override public Object computeAdvance( FLYSArtifact artifact, @@ -222,7 +101,7 @@ WSPLGENCalculation calculation = new WSPLGENCalculation(); FacetCreator facetCreator = new FacetCreator( - artifact, context, hash, getID()); + artifact, context, hash, getID(), facets); WSPLGENJob job = prepareWSPLGENJob( artifact, @@ -252,10 +131,6 @@ return null; } - facetCreator.createWSPLGENFacet(); - - facets.addAll(facetCreator.getFacets()); - context.afterCall(CallContext.BACKGROUND); context.addBackgroundMessage(new CalculationMessage( JobObserver.STEPS.length, @@ -333,6 +208,7 @@ WSPLGENJob job = new WSPLGENJob( artifact, artifactDir, + facetCreator, context, calculation);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/wsplgen/FacetCreator.java Tue Sep 27 12:40:42 2011 +0000 @@ -0,0 +1,146 @@ +package de.intevation.flys.wsplgen; + +import java.util.ArrayList; +import java.util.List; + +import de.intevation.artifacts.CallContext; + +import de.intevation.artifactdatabase.state.Facet; + +import de.intevation.flys.model.CrossSectionTrack; + +import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.model.FacetTypes; +import de.intevation.flys.artifacts.model.WMSLayerFacet; +import de.intevation.flys.artifacts.resources.Resources; +import de.intevation.flys.artifacts.states.DefaultState.ComputeType; +import de.intevation.flys.utils.FLYSUtils; +import de.intevation.flys.utils.GeometryUtils; +import de.intevation.flys.utils.MapfileGenerator; + + +public class FacetCreator implements FacetTypes { + + public static final String I18N_WSPLGEN_RESULT = "floodmap.uesk"; + public static final String I18N_WSPLGEN_DEFAULT = "floodmap.uesk"; + public static final String I18N_BARRIERS = "floodmap.barriers"; + public static final String I18N_BARRIERS_DEFAULT = "floodmap.barriers"; + + protected FLYSArtifact artifact; + + protected CallContext cc; + + protected List<Facet> facets; + protected List<Facet> tmpFacets; + + protected String url; + protected String hash; + protected String stateId; + + public FacetCreator( + FLYSArtifact artifact, + CallContext cc, + String hash, + String sId, + List<Facet> facets + ) { + this.tmpFacets = new ArrayList<Facet>(2); + this.facets = facets; + this.artifact = artifact; + this.cc = cc; + this.hash = hash; + this.stateId = sId; + } + + protected String getRiver() { + return artifact.getDataAsString("river"); + } + + protected String getUrl() { + String url = FLYSUtils.getXPathString(FLYSUtils.XPATH_MAPSERVER_URL); + url = url + "user-wms"; + return url; + } + + protected String getSrid() { + return FLYSUtils.getRiverSrid(artifact); + } + + protected String getWSPLGENBounds() { + String river = getRiver(); + double kms[] = FLYSUtils.getKmRange(artifact); + + CrossSectionTrack a = + CrossSectionTrack.getCrossSectionTrack(river, kms[0]); + + CrossSectionTrack b = + CrossSectionTrack.getCrossSectionTrack(river, kms[1]); + + if (a == null || b == null) { + return null; + } + + return GeometryUtils.createOLBounds(a.getGeom(), b.getGeom()); + } + + protected String getBounds() { + return GeometryUtils.getRiverBounds(getRiver()); + } + + public List<Facet> getFacets() { + return tmpFacets; + } + + public void createWSPLGENFacet() { + WMSLayerFacet wsplgen = new WMSLayerFacet( + 0, + FLOODMAP_WSPLGEN, + Resources.getMsg( + cc.getMeta(), + I18N_WSPLGEN_RESULT, + I18N_WSPLGEN_DEFAULT), + ComputeType.ADVANCE, + stateId, + hash, + getUrl()); + + String bounds = getWSPLGENBounds(); + + if (bounds == null || bounds.length() == 0) { + bounds = getBounds(); + } + + wsplgen.addLayer( + artifact.identifier() + MapfileGenerator.MS_WSPLGEN_POSTFIX); + wsplgen.setSrid(getSrid()); + wsplgen.setExtent(bounds); + + tmpFacets.add(wsplgen); + } + + public void createBarrierFacet() { + WMSLayerFacet barriers = new WMSLayerFacet( + 1, + FLOODMAP_WSPLGEN, + Resources.getMsg( + cc.getMeta(), + I18N_BARRIERS, + I18N_BARRIERS_DEFAULT), + ComputeType.ADVANCE, + stateId, + hash, + getUrl()); + + barriers.addLayer( + artifact.identifier() + MapfileGenerator.MS_BARRIERS_POSTFIX); + barriers.setSrid(getSrid()); + barriers.setExtent(getBounds()); + + tmpFacets.add(barriers); + } + + + public void finish() { + facets.addAll(getFacets()); + } +} // end of FacetCreator
--- a/flys-artifacts/src/main/java/de/intevation/flys/wsplgen/JobExecutor.java Tue Sep 27 11:33:45 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/wsplgen/JobExecutor.java Tue Sep 27 12:40:42 2011 +0000 @@ -79,8 +79,6 @@ } catch (InterruptedException iee) { /* do nothing */ } - job.getCallContext().afterBackground(CallContext.STORE); - logger.info("WSPLGEN exit value: " + process.exitValue()); logger.info( "WSPLGEN throw " + @@ -89,7 +87,15 @@ "WSPLGEN throw " + errorObserver.numWarnings() + " warnings."); - MapfileGenerator.getInstance().update(); + if (process.exitValue() < 2 && errorObserver.numErrors() == 0) { + FacetCreator fc = job.getFacetCreator(); + fc.createWSPLGENFacet(); + fc.finish(); + + MapfileGenerator.getInstance().update(); + } + + job.getCallContext().afterBackground(CallContext.STORE); return; }