changeset 1052:eeebf8514c7f

The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet. flys-artifacts/trunk@2514 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 19 Aug 2011 15:52:03 +0000
parents 9a77a9adbb36
children bfc2ed20b87c
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/conf.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WMSLayerFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java
diffstat 5 files changed, 86 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Aug 19 14:13:51 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Aug 19 15:52:03 2011 +0000
@@ -1,3 +1,20 @@
+2011-08-19  Ingo Weinzierl <ingo@intevation.de>
+
+	* doc/conf/conf.xml: Each river requires a SRID definition. This
+	  definition is used to transform the river's geometries into the desired
+	  projection.
+
+	* src/main/java/de/intevation/flys/artifacts/model/WMSLayerFacet.java:
+	  This facets are able to save a SRID.
+
+	* src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java:
+	  The extent that is written into the WMSLayerFacet is determined by the
+	  boundary of the geometry.
+
+	* src/main/java/de/intevation/flys/utils/GeometryUtils.java: New. A
+	  utility class that provides helper functions for geometries. Currently,
+	  one function is defined, that creates a boundary string for OpenLayers.
+
 2011-08-19  Sascha L. Teichmann <sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java,
--- a/flys-artifacts/doc/conf/conf.xml	Fri Aug 19 14:13:51 2011 +0000
+++ b/flys-artifacts/doc/conf/conf.xml	Fri Aug 19 15:52:03 2011 +0000
@@ -109,9 +109,9 @@
     <!-- The WMS layer that is displayed as background layer in floodmaps. -->
     <floodmap>
         <background-layer url="http://vmap0.tiles.osgeo.org/wms/vmap0" layer="basic"/>
-        <river-wms river="Saar" url="http://flys-devel.intevation.de/cgi-bin/saar-wms"/>
-        <river-wms river="Mosel" url="http://flys-devel.intevation.de/cgi-bin/mosel-wms"/>
-        <river-wms river="Elbe" url="http://flys-devel.intevation.de/cgi-bin/elbe-wms"/>
+        <river-wms river="Saar" srid="31466" url="http://flys-devel.intevation.de/cgi-bin/saar-wms"/>
+        <river-wms river="Mosel" srid="31466" url="http://flys-devel.intevation.de/cgi-bin/mosel-wms"/>
+        <river-wms river="Elbe" srid="31466" url="http://flys-devel.intevation.de/cgi-bin/elbe-wms"/>
     </floodmap>
 
     <rest-server>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WMSLayerFacet.java	Fri Aug 19 14:13:51 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WMSLayerFacet.java	Fri Aug 19 15:52:03 2011 +0000
@@ -29,6 +29,7 @@
     protected String       hash;
     protected String       url;
     protected String       extent;
+    protected String       srid;
 
 
     private static final Logger logger = Logger.getLogger(WMSLayerFacet.class);
@@ -84,6 +85,13 @@
     }
 
 
+    public void setSrid(String srid) {
+        if (srid != null) {
+            this.srid = srid;
+        }
+    }
+
+
     public Object getData(Artifact artifact, CallContext context) {
         return null;
     }
@@ -103,6 +111,7 @@
         ec.addAttr(facet, "url", url, true);
         ec.addAttr(facet, "layers", layers.get(0), true);
         ec.addAttr(facet, "extent", extent != null ? extent : "", true);
+        ec.addAttr(facet, "srid", srid != null ? srid : "", true);
 
         return facet;
     }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java	Fri Aug 19 14:13:51 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java	Fri Aug 19 15:52:03 2011 +0000
@@ -3,18 +3,25 @@
 import java.util.List;
 import java.util.Map;
 
+import com.vividsolutions.jts.geom.Geometry;
+
 import org.apache.log4j.Logger;
 
 import de.intevation.artifacts.CallContext;
 import de.intevation.artifacts.CallMeta;
 
+import de.intevation.artifacts.common.utils.Config;
+
 import de.intevation.artifactdatabase.state.Facet;
 
+import de.intevation.flys.model.RiverAxis;
+
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.context.FLYSContext;
 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.GeometryUtils;
 
 
 public class RiverAxisState extends OutputState {
@@ -23,6 +30,9 @@
 
     public static final String WMS_LAYER_NAME = "riveraxis";
 
+    public static final String XPATH_RIVER_PROJECTION =
+        "/artifact-database/floodmap/river-wms[@river='%RIVER%']/@srid";
+
 
     private static final Logger logger = Logger.getLogger(RiverAxisState.class);
 
@@ -69,8 +79,21 @@
 
         facet.addLayer(WMS_LAYER_NAME);
 
-        // TODO determine extent based on the given geometry
-        facet.setExtent("6.5 49.1 7.0 49.7");
+        RiverAxis axis = RiverAxis.getRiverAxis(river);
+        if (axis != null) {
+            // TODO Take the correct EPSG into account. Maybe, we need to
+            // reproject the geometry.
+            Geometry geom   = axis.getGeom().getBoundary();
+            String   bounds = GeometryUtils.jtsBoundsToOLBounds(geom);
+
+            logger.debug("River '" + river + "' bounds: " + bounds);
+
+            facet.setExtent(bounds);
+        }
+
+        String xpath = XPATH_RIVER_PROJECTION.replace("%RIVER%", river);
+        String srid  = Config.getStringXPath(xpath);
+        facet.setSrid(srid);
 
         facets.add(facet);
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java	Fri Aug 19 15:52:03 2011 +0000
@@ -0,0 +1,32 @@
+package de.intevation.flys.utils;
+
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.Geometry;
+
+
+
+public class GeometryUtils {
+
+    private GeometryUtils() {
+    }
+
+
+    /**
+     * Returns the boundary of Geometry <i>geom</i> in OpenLayers
+     * representation.
+     *
+     * @param geom The geometry.
+     *
+     * @return the OpenLayers boundary of <i>geom</i>.
+     */
+    public static String jtsBoundsToOLBounds(Geometry geom) {
+        Coordinate[] c = geom != null ? geom.getCoordinates() : null;
+
+        if (c == null || c.length < 2) {
+            return null;
+        }
+
+        return "" + c[0].x + " " + c[1].y + " " + c[1].x + " " + c[0].y;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org