diff flys-artifacts/src/main/java/de/intevation/flys/wsplgen/FacetCreator.java @ 3786:4adc35aa655c

merged flys-artifacts/2.9.1
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:47 +0200
parents 453d2d0c4258
children 36147ddb2c32
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/wsplgen/FacetCreator.java	Fri Sep 28 12:14:47 2012 +0200
@@ -0,0 +1,186 @@
+package de.intevation.flys.wsplgen;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import com.vividsolutions.jts.geom.Envelope;
+
+import de.intevation.artifactdatabase.state.Facet;
+import de.intevation.artifacts.CallContext;
+import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.map.WMSLayerFacet;
+import de.intevation.flys.artifacts.model.map.WSPLGENLayerFacet;
+import de.intevation.flys.artifacts.resources.Resources;
+import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
+import de.intevation.flys.model.CrossSectionTrack;
+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";
+    public static final String I18N_USERSHAPE         = "floodmap.usershape";
+    public static final String I18N_USERSHAPE_DEFAULT = "floodmap.usershape";
+
+    protected FLYSArtifact artifact;
+
+    protected CallContext  cc;
+
+    protected List<Facet> facets;
+    protected List<Facet> tmpFacets;
+
+    protected String url;
+    protected String hash;
+    protected String stateId;
+
+
+    private static Logger logger = Logger.getLogger(FacetCreator.class);
+
+
+    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() {
+        return FLYSUtils.getUserWMSUrl(artifact.identifier());
+    }
+
+    protected String getSrid() {
+        return FLYSUtils.getRiverSrid(artifact);
+    }
+
+    protected Envelope getWSPLGENBounds() {
+        String river = getRiver();
+        double kms[] = FLYSUtils.getKmRange(artifact);
+
+        logger.debug("### getWSPLGENBounds");
+        logger.debug("###    from km: " + kms[0]);
+        logger.debug("###    to   km: " + kms[1]);
+
+        CrossSectionTrack a =
+            CrossSectionTrack.getCrossSectionTrack(river, kms[0]);
+
+        CrossSectionTrack b =
+            CrossSectionTrack.getCrossSectionTrack(river, kms[1]);
+
+        if (a == null || b == null) {
+            return null;
+        }
+
+        Envelope envA = a.getGeom().getEnvelopeInternal();
+        Envelope envB = b.getGeom().getEnvelopeInternal();
+
+        envA.expandToInclude(envB);
+
+        logger.debug("###    => " + envA);
+
+        return envA;
+    }
+
+    protected Envelope getBounds() {
+        return GeometryUtils.getRiverBoundary(getRiver());
+    }
+
+    public List<Facet> getFacets() {
+        return tmpFacets;
+    }
+
+    public void createWSPLGENFacet() {
+        WSPLGENLayerFacet wsplgen = new WSPLGENLayerFacet(
+            0,
+            FLOODMAP_WSPLGEN,
+            Resources.getMsg(
+                cc.getMeta(),
+                I18N_WSPLGEN_RESULT,
+                I18N_WSPLGEN_DEFAULT),
+            ComputeType.ADVANCE,
+            stateId,
+            hash,
+            getUrl());
+
+        Envelope bounds = getWSPLGENBounds();
+
+        if (bounds == null) {
+            bounds = getBounds();
+        }
+
+        wsplgen.addLayer(
+            MapfileGenerator.MS_WSPLGEN_PREFIX + artifact.identifier());
+        wsplgen.setSrid(getSrid());
+        wsplgen.setExtent(bounds);
+
+        tmpFacets.add(wsplgen);
+    }
+
+    public void createBarrierFacet() {
+        WMSLayerFacet barriers = new WMSLayerFacet(
+            1,
+            FLOODMAP_BARRIERS,
+            Resources.getMsg(
+                cc.getMeta(),
+                I18N_BARRIERS,
+                I18N_BARRIERS_DEFAULT),
+            ComputeType.ADVANCE,
+            stateId,
+            hash,
+            getUrl());
+
+        barriers.addLayer(
+            MapfileGenerator.MS_BARRIERS_PREFIX + artifact.identifier());
+        barriers.setSrid(getSrid());
+        barriers.setExtent(getBounds());
+
+        tmpFacets.add(barriers);
+    }
+
+
+    public void createUserShapeFacet() {
+        WMSLayerFacet shape = new WMSLayerFacet(
+            1,
+            FLOODMAP_USERSHAPE,
+            Resources.getMsg(
+                cc.getMeta(),
+                I18N_USERSHAPE,
+                I18N_USERSHAPE_DEFAULT),
+            ComputeType.ADVANCE,
+            stateId,
+            hash,
+            getUrl());
+
+        shape.addLayer(
+            MapfileGenerator.MS_USERSHAPE_PREFIX + artifact.identifier());
+        shape.setSrid(getSrid());
+        shape.setExtent(getBounds());
+
+        tmpFacets.add(shape);
+    }
+
+
+    public void finish() {
+        facets.addAll(getFacets());
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org