changeset 1070:7096a2e13676

Added functionality to publish the the mbr of the generated layer to the client. gnv-artifacts/trunk@1166 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Mon, 07 Jun 2010 14:42:42 +0000
parents 0d15e515f88d
children 9bb1979aabbe
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/utils/MetaWriter.java
diffstat 4 files changed, 73 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Mon Jun 07 12:22:00 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Mon Jun 07 14:42:42 2010 +0000
@@ -1,3 +1,16 @@
+2010-06-07  Tim Englich  <tim.englich@intevation.de>
+
+	  Added functionality to publish the the mbr of the generated layer to
+	  the client.
+	* src/main/java/de/intevation/gnv/utils/MetaWriter.java (insertMbr): 
+	  Added function to add an box-element to the mapserver-fragmet of the 
+	  Metafile
+	* src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java, 
+	  src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java:
+	  Calculate the box and write it into the metafile using the insertMbr-method 
+	  of MetaWriter to publish the mbr of the data which was fetched during the 
+	  request to the client.
+
 2010-06-07  Tim Englich  <tim.englich@intevation.de>
 
 	* doc/conf/conf.xml: 
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java	Mon Jun 07 12:22:00 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java	Mon Jun 07 14:42:42 2010 +0000
@@ -11,6 +11,7 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 
+import com.vividsolutions.jts.geom.Envelope;
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.io.ParseException;
 import com.vividsolutions.jts.io.WKTReader;
@@ -235,7 +236,7 @@
      *
      * @return the resultdata.
      */
-    protected Collection<Result> fetchData(LayerMetaData layerMetaData){
+    protected Collection<Result> fetchData(LayerMetaData layerMetaData, Envelope mbr){
         log.debug("LayerOutputState.fetchData");
         Collection<Result> data = null;
         QueryExecutor queryExecutor = QueryExecutorFactory.getInstance()
@@ -243,9 +244,12 @@
         try {
             data  = queryExecutor.executeQuery(dataQueryID,
                                                layerMetaData.getQueryValues());
-            if (data != null && layerMetaData.getGeometryWKT() != null){
+            if (data != null){
                 WKTReader wktReader = new WKTReader();
-                Geometry border = wktReader.read(layerMetaData.getGeometryWKT());
+                Geometry border = null;
+                if (layerMetaData.getGeometryWKT() != null){
+                    border = wktReader.read(layerMetaData.getGeometryWKT());
+                }
                 Iterator<Result> dataIt = data.iterator();
                 while (dataIt.hasNext()){
                     // Trim the Geometries using the
@@ -260,8 +264,15 @@
                         log.error(e,e);
                     }
                     if (currentGeometry != null){
-                        Geometry newGeometry = currentGeometry.intersection(border);
-                        current.addColumnValue(0, newGeometry.toText());
+                        if (border != null){
+                            currentGeometry = currentGeometry.intersection(border);
+                            current.addColumnValue(0, currentGeometry.toText());
+                        }
+                        if (mbr.isNull()){
+                            mbr.init(currentGeometry.getEnvelopeInternal());
+                        }else{
+                            mbr.expandToInclude(currentGeometry.getEnvelopeInternal());
+                        }
                     }
                 }
             }
@@ -475,9 +486,10 @@
                     }
                     Iterator<LayerMetaData> it = layerMetaData.iterator();
                     int i = 1;
+                    Envelope mbr = new Envelope();
                     while(it.hasNext()){
                         LayerMetaData lmd = it.next();
-                        Collection<Result> data = this.fetchData(lmd);
+                        Collection<Result> data = this.fetchData(lmd, mbr);
                         p = writeToShapeFile(uuid, data, callContext,lmd.getGeometryType(),i++);
                     }
                     if (p != null) {
@@ -631,6 +643,7 @@
             }
 
             int layerNumber = 0;
+            Envelope mbr = new Envelope();
             while (it.hasNext()){
                 LayerMetaData lmd = it.next();
                 layerNumber ++;
@@ -640,7 +653,7 @@
 
                 ExclusiveExec.UniqueKey key = ExclusiveExec.INSTANCE.acquire(uuid);
                 try{
-                    Collection<Result> results = this.fetchData(lmd);
+                    Collection<Result> results = this.fetchData(lmd,mbr);
                     if (results != null && writeToShapeFile(uuid, results,
                                                          callContext,
                                                          geometryType,
@@ -663,6 +676,7 @@
                     success = true;
 
                     if (meta != null && !it.hasNext()) {
+                        MetaWriter.insertMbr(mbr, "EPSG:4326",meta);
                         MetaWriter.writeMetaFile(path, meta);
                         MapfileGenerator.getInstance().update();
                         return meta;
@@ -671,6 +685,7 @@
                     ExclusiveExec.INSTANCE.release(key);
                 }
             }
+          
             return document;
         }
         finally {
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java	Mon Jun 07 12:22:00 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java	Mon Jun 07 14:42:42 2010 +0000
@@ -94,6 +94,8 @@
     private Boolean shapeFileLock = new Boolean(true);
 
     private String shapeFilePath;
+    
+    private Envelope  bbox = null;
 
     /**
      * Constructor
@@ -334,6 +336,7 @@
                 callContext, meta, name, title, data, model, type, status);
 
             if (meta != null) {
+                MetaWriter.insertMbr(this.bbox, "EPSG:4326", meta);
                 MetaWriter.writeMetaFile(path, meta);
                 MapfileGenerator.getInstance().update();
                 return meta;
@@ -615,6 +618,7 @@
         try {
             Envelope env  = p.getEnvelopeInternal();
 
+            this.bbox = env;
             String additionWhere;
 
             if (USE_INDEX_BUFFER) {
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MetaWriter.java	Mon Jun 07 12:22:00 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MetaWriter.java	Mon Jun 07 14:42:42 2010 +0000
@@ -5,16 +5,18 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.text.DecimalFormat;
 import java.util.Date;
 
 import javax.xml.xpath.XPathConstants;
 
 import org.apache.log4j.Logger;
-
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
+import com.vividsolutions.jts.geom.Envelope;
+
 import de.intevation.artifactdatabase.XMLUtils;
 import de.intevation.artifacts.ArtifactNamespaceContext;
 import de.intevation.artifacts.CallContext;
@@ -39,6 +41,7 @@
     public static final String META_FILE_NAME = "meta.xml";
 
     public static final String XPATH_META = "/art:meta";
+    public static final String XPATH_MAPSERVER = "art:meta/art:"+NODE_MAPSERVER;
 
     /**
      * Constructor.
@@ -133,7 +136,37 @@
         return true;
     }
 
+    /**
+     * Method to write the <i>meta</i> document down to a file.
+     *
+     * @param path The destination of the file.
+     * @param meta The xml document storing the meta information.
+     */
+    public static boolean insertMbr(Envelope mbr, String srs, Document meta) {
+        Node mapserverNode = (Node) XMLUtils.xpath(
+                meta,
+                XPATH_MAPSERVER,
+                XPathConstants.NODE,
+                ArtifactNamespaceContext.INSTANCE);
+        if (mapserverNode != null){
+            XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
+                    meta,
+                    ArtifactNamespaceContext.NAMESPACE_URI,
+                    ArtifactNamespaceContext.NAMESPACE_PREFIX);
+            Element bboxNode = creator.create("Box");
+            bboxNode.setAttribute("srsName", srs);
+            Element coordinateNode = creator.create("coordinates");
 
+            DecimalFormat formatter = new DecimalFormat("###.############");
+            coordinateNode.setTextContent(formatter.format(mbr.getMinX()).replace(',', '.') +","+ 
+                                          formatter.format(mbr.getMinY()).replace(',', '.')+" "+
+                                          formatter.format(mbr.getMaxX()).replace(',', '.') +","+ 
+                                          formatter.format(mbr.getMaxY()).replace(',', '.'));
+            mapserverNode.appendChild(bboxNode);
+            bboxNode.appendChild(coordinateNode);
+        }
+        return true;
+    }
     /**
      * Method to write the <i>meta</i> document down to a file.
      *

http://dive4elements.wald.intevation.org