# HG changeset patch # User Ingo Weinzierl # Date 1315827604 0 # Node ID 0398c2b8dbaf8cecd078e26622edf569ffbe96f3 # Parent 2e073985380798989ca1399a70351fa628cfd009 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 diff -r 2e0739853807 -r 0398c2b8dbaf flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Mon Sep 12 11:30:19 2011 +0000 +++ b/flys-artifacts/ChangeLog Mon Sep 12 11:40:04 2011 +0000 @@ -1,3 +1,14 @@ +2011-09-12 Ingo Weinzierl + + * src/main/java/de/intevation/flys/utils/GeometryUtils.java: Write + shapefiles only if there are features for it existing. + + * src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java: + A WSPLGEN facet is only created, if the calculation was successfully + added to the Scheduler. A barrier facet is only created if the WSPLGEN + calculation has been added to the scheduler AND if there are digitized + geometries existing. + 2011-09-12 Felix Wolfsteller Copied and slightly modified implementation of guessWaterIncreasing from diff -r 2e0739853807 -r 0398c2b8dbaf flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java Mon Sep 12 11:30:19 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java Mon Sep 12 11:40:04 2011 +0000 @@ -79,6 +79,85 @@ + /** + * 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 List facets; + protected String url; + protected String hash; + protected String stateId; + + public FacetCreator(FLYSArtifact artifact, String hash, String sId) { + this.facets = new ArrayList(2); + this.artifact = artifact; + 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 getBounds() { + return GeometryUtils.getRiverBounds(getRiver()); + } + + public List getFacets() { + return facets; + } + + public void createWSPLGENFacet() { + WMSLayerFacet wsplgen = new WMSLayerFacet( + 0, + FLOODMAP_WSPLGEN, + "Ergebnis der WSPLGEN Berechnung", + ComputeType.ADVANCE, + stateId, + hash, + getUrl()); + + wsplgen.addLayer( + artifact.identifier() + MapfileGenerator.MS_WSPLGEN_POSTFIX); + wsplgen.setSrid(getSrid()); + wsplgen.setExtent(getBounds()); + + facets.add(wsplgen); + } + + public void createBarrierFacet() { + WMSLayerFacet barriers = new WMSLayerFacet( + 1, + FLOODMAP_WSPLGEN, + "Rohre/Graeben/Daemme", + 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, @@ -98,8 +177,11 @@ WSPLGENCalculation calculation = new WSPLGENCalculation(); + FacetCreator facetCreator = new FacetCreator(artifact, hash, getID()); + WSPLGENJob job = prepareWSPLGENJob( artifact, + facetCreator, artifactDir, context, calculation); @@ -117,47 +199,14 @@ Scheduler scheduler = Scheduler.getInstance(); scheduler.addJob(job); - String url = FLYSUtils.getXPathString(FLYSUtils.XPATH_MAPSERVER_URL); - url = url + "user-wms"; - - WMSLayerFacet wsplgen = new WMSLayerFacet( - 0, - FLOODMAP_WSPLGEN, - "Ergebnis der WSPLGEN Berechnung", - ComputeType.ADVANCE, - getID(), - hash, - url); - - String srid = FLYSUtils.getRiverSrid(artifact); - String river = artifact.getDataAsString("river"); - - wsplgen.addLayer( - artifact.identifier() + MapfileGenerator.MS_WSPLGEN_POSTFIX); - wsplgen.setSrid(srid); - wsplgen.setExtent(GeometryUtils.getRiverBounds(river)); - - WMSLayerFacet barriers = new WMSLayerFacet( - 1, - FLOODMAP_WSPLGEN, - "Rohre/Graeben/Daemme", - ComputeType.ADVANCE, - getID(), - hash, - url); - - barriers.addLayer( - artifact.identifier() + MapfileGenerator.MS_BARRIERS_POSTFIX); - barriers.setSrid(srid); - barriers.setExtent(GeometryUtils.getRiverBounds(river)); + facetCreator.createWSPLGENFacet(); CalculationResult res = new CalculationResult(null, calculation); WSPLGENReportFacet report= new WSPLGENReportFacet( ComputeType.ADVANCE, hash, getID(), res); - facets.add(wsplgen); - facets.add(barriers); facets.add(report); + facets.addAll(facetCreator.getFacets()); context.afterCall(CallContext.BACKGROUND); @@ -215,6 +264,7 @@ protected WSPLGENJob prepareWSPLGENJob( FLYSArtifact artifact, + FacetCreator facetCreator, File artifactDir, CallContext context, WSPLGENCalculation calculation @@ -234,7 +284,7 @@ setDelta(artifact, job); setGel(artifact, job); setDist(artifact, job); - setLine(artifact, artifactDir, job); + setLine(artifact, facetCreator, artifactDir, job); setAxis(artifact, artifactDir, job); setPro(artifact, artifactDir, job); setDgm(artifact, job); @@ -327,11 +377,21 @@ } - protected void setLine(FLYSArtifact artifact, File dir, WSPLGENJob job) { + protected void setLine( + FLYSArtifact artifact, + FacetCreator facetCreator, + File dir, + WSPLGENJob job + ) { String geoJSON = artifact.getDataAsString("uesk.barriers"); String srid = FLYSUtils.getRiverSrid(artifact); String srs = "EPSG:" + srid; + if (geoJSON == null || geoJSON.length() == 0) { + logger.debug("No barrier features in parameterization existing."); + return; + } + SimpleFeatureType ft = getBarriersFeatureType( "barriers", srs, Geometry.class); @@ -373,6 +433,10 @@ "Write shapefile path into WSPLGEN job."); job.addLin(shapePolys.getAbsolutePath()); } + + if (p || l) { + facetCreator.createBarrierFacet(); + } } diff -r 2e0739853807 -r 0398c2b8dbaf flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java --- a/flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java Mon Sep 12 11:30:19 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java Mon Sep 12 11:40:04 2011 +0000 @@ -155,6 +155,11 @@ SimpleFeatureType featureType, FeatureCollection collection ) { + if (collection.isEmpty()) { + logger.warn("Shapefile is not written - no features given!"); + return false; + } + Transaction transaction = null; try {