changeset 1058:c37084f31c84

Implemented a MapInfo service that returns some basic information to create maps for specific rivers. flys-artifacts/trunk@2528 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 23 Aug 2011 07:53:41 +0000
parents d4a5d3941cc0
children fdb0f4ef96f0
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/conf.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MapInfoService.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java
diffstat 4 files changed, 167 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Aug 22 16:37:12 2011 +0000
+++ b/flys-artifacts/ChangeLog	Tue Aug 23 07:53:41 2011 +0000
@@ -1,3 +1,18 @@
+2011-08-23  Ingo Weinzierl <ingo@intevation.de>
+
+	* doc/conf/conf.xml: Added the MapInfoService and adapted the floodmap
+	  configuration. Now, each river can have its own background wms layer
+	  defined.
+
+	* src/main/java/de/intevation/flys/artifacts/services/MapInfoService.java:
+	  New. This service returns some basic information used to create maps for
+	  a specific river. The name of the desired river needs to be defined at
+	  "/mapinfo/river/text()".
+
+	* src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java:
+	  Adapted an xpath expression that points to the srid of a river in the
+	  floodmap configuration (which changed).
+
 2011-08-22  Sascha L. Teichmann <sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java:
--- a/flys-artifacts/doc/conf/conf.xml	Mon Aug 22 16:37:12 2011 +0000
+++ b/flys-artifacts/doc/conf/conf.xml	Tue Aug 23 07:53:41 2011 +0000
@@ -44,6 +44,10 @@
                 name="metadata"
                 service="de.intevation.flys.artifacts.services.MetaDataService"
                 description="The service provides some introspection into the database content.">de.intevation.artifactdatabase.DefaultServiceFactory</service-factory>
+            <service-factory
+                name="mapinfo"
+                service="de.intevation.flys.artifacts.services.MapInfoService"
+                description="The service provides some basic information to create a WMS for a specific river.">de.intevation.artifactdatabase.DefaultServiceFactory</service-factory>
         </service-factories>
 
     </factories>
@@ -106,12 +110,25 @@
         <template>${artifacts.config.dir}/meta-data.xml</template>
     </metadata>
 
-    <!-- The WMS layer that is displayed as background layer in floodmaps. -->
+    <!-- The floodmap configuration for each supported river. Each element
+         requires a srid, wms and background-wms. Those information are used for
+         creating a Map view.-->
     <floodmap>
-        <background-layer url="http://vmap0.tiles.osgeo.org/wms/vmap0" layer="basic"/>
-        <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"/>
+        <river name="Saar">
+            <srid value="31466"/>
+            <river-wms url="http://flys-devel.intevation.de/cgi-bin/saar-wms"/>
+            <background-wms url="http://vmap0.tiles.osgeo.org/wms/vmap0" layers="basic"/>
+        </river>
+        <river name="Mosel">
+            <srid value="31466"/>
+            <river-wms url="http://flys-devel.intevation.de/cgi-bin/mosel-wms"/>
+            <background-wms url="http://vmap0.tiles.osgeo.org/wms/vmap0" layers="basic"/>
+        </river>
+        <river name="Elbe">
+            <srid value="31466"/>
+            <river-wms url="http://flys-devel.intevation.de/cgi-bin/elbe-wms"/>
+            <background-wms url="http://vmap0.tiles.osgeo.org/wms/vmap0" layers="basic"/>
+        </river>
     </floodmap>
 
     <rest-server>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MapInfoService.java	Tue Aug 23 07:53:41 2011 +0000
@@ -0,0 +1,129 @@
+package de.intevation.flys.artifacts.services;
+
+import org.apache.log4j.Logger;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import com.vividsolutions.jts.geom.Geometry;
+
+import de.intevation.artifacts.CallMeta;
+import de.intevation.artifacts.GlobalContext;
+
+import de.intevation.artifacts.common.ArtifactNamespaceContext;
+import de.intevation.artifacts.common.utils.Config;
+import de.intevation.artifacts.common.utils.XMLUtils;
+import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
+
+import de.intevation.artifactdatabase.DefaultService;
+
+import de.intevation.flys.backend.SessionHolder;
+import de.intevation.flys.model.River;
+
+import de.intevation.flys.model.RiverAxis;
+import de.intevation.flys.artifacts.model.RiverFactory;
+import de.intevation.flys.utils.GeometryUtils;
+
+import org.hibernate.Session;
+
+/**
+ * This service provides information about the supported rivers by this
+ * application.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class MapInfoService extends DefaultService {
+
+    /** XPath that points to the river.*/
+    public static final String XPATH_RIVER = "/mapinfo/river/text()";
+
+    public static final String XPATH_RIVER_PROJECTION =
+        "/artifact-database/floodmap/river[@name='%RIVER%']/srid/@value";
+
+    public static final String XPATH_RIVER_BACKGROUND =
+        "/artifact-database/floodmap/river[@name='%RIVER%']/background-wms";
+
+    public static final String XPATH_RIVER_WMS =
+        "/artifact-database/floodmap/river[@name='%RIVER%']/river-wms/@url";
+
+
+    /** The logger used in this service.*/
+    private static Logger logger = Logger.getLogger(MapInfoService.class);
+
+
+    /**
+     * The default constructor.
+     */
+    public MapInfoService() {
+    }
+
+
+    public Document process(
+        Document      data,
+        GlobalContext globalContext,
+        CallMeta      callMeta
+    ) {
+        logger.debug("MapInfoService.process");
+
+        Document result   = XMLUtils.newDocument();
+        ElementCreator cr = new ElementCreator(result, null, null);
+
+        Element mapinfo = cr.create("mapinfo");
+        result.appendChild(mapinfo);
+
+        String river = extractRiver(data);
+        if (river == null || river.length() == 0) {
+            logger.warn("Cannot generate information: river is empty!");
+            return result;
+        }
+
+        Element root = cr.create("river");
+        cr.addAttr(root, "name", river);
+        mapinfo.appendChild(root);
+
+        RiverAxis axis = RiverAxis.getRiverAxis(river);
+        if (axis != null) {
+            Geometry geom   = axis.getGeom().getBoundary();
+            String   bounds = GeometryUtils.jtsBoundsToOLBounds(geom);
+
+            logger.debug("River '" + river + "' bounds: " + bounds);
+            Element bbox = cr.create("bbox");
+            cr.addAttr(bbox, "value", bounds);
+            root.appendChild(bbox);
+        }
+
+        String xpathS  = XPATH_RIVER_PROJECTION.replace("%RIVER%", river);
+        String sridStr = Config.getStringXPath(xpathS);
+        if (sridStr != null && sridStr.length() > 0) {
+            Element srid = cr.create("srid");
+            cr.addAttr(srid, "value", sridStr);
+            root.appendChild(srid);
+        }
+
+        String xpathB = XPATH_RIVER_BACKGROUND.replace("%RIVER%", river);
+        Element back  = (Element) Config.getNodeXPath(xpathB);
+        if (back != null) {
+            Element background = cr.create("background-wms");
+            cr.addAttr(background, "url", back.getAttribute("url"));
+            cr.addAttr(background, "layers", back.getAttribute("layers"));
+            root.appendChild(background);
+        }
+
+        String xpathWMS = XPATH_RIVER_WMS.replace("%RIVER%", river);
+        String wmsStr   = Config.getStringXPath(xpathWMS);
+        if (wmsStr != null && wmsStr.length() > 0) {
+            Element wms = cr.create("river-wms");
+            cr.addAttr(wms, "url", wmsStr);
+            root.appendChild(wms);
+        }
+
+        return result;
+    }
+
+
+    protected String extractRiver(Document data) {
+        return XMLUtils.xpathString(
+            data, XPATH_RIVER, ArtifactNamespaceContext.INSTANCE);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java	Mon Aug 22 16:37:12 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java	Tue Aug 23 07:53:41 2011 +0000
@@ -31,7 +31,7 @@
     public static final String WMS_LAYER_NAME = "riveraxis";
 
     public static final String XPATH_RIVER_PROJECTION =
-        "/artifact-database/floodmap/river-wms[@river='%RIVER%']/@srid";
+        "/artifact-database/floodmap/river[@name='%RIVER%']/srid/@value";
 
 
     private static final Logger logger = Logger.getLogger(RiverAxisState.class);

http://dive4elements.wald.intevation.org