diff flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java @ 1774:092e1e5020bc

Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress). flys-artifacts/trunk@3095 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 28 Oct 2011 05:54:25 +0000
parents eb3ab28d1c21
children cbeeaaad1056
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java	Thu Oct 27 14:04:04 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java	Fri Oct 28 05:54:25 2011 +0000
@@ -12,6 +12,7 @@
 import org.apache.log4j.Logger;
 
 import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.Envelope;
 import com.vividsolutions.jts.geom.Geometry;
 
 import org.opengis.feature.simple.SimpleFeature;
@@ -44,13 +45,23 @@
     }
 
 
-    public static String getRiverBounds(String rivername) {
+    public static Envelope getRiverBoundary(String rivername) {
         RiverAxis axis = RiverAxis.getRiverAxis(rivername);
         if (axis != null) {
             // TODO Take the correct EPSG into account. Maybe, we need to
             // reproject the geometry.
-            Geometry geom   = axis.getGeom().getBoundary();
-            return jtsBoundsToOLBounds(geom);
+            return axis.getGeom().getEnvelopeInternal();
+        }
+
+        return null;
+    }
+
+
+    public static String getRiverBounds(String rivername) {
+        Envelope env = getRiverBoundary(rivername);
+
+        if (env == null) {
+            return jtsBoundsToOLBounds(env);
         }
 
         return null;
@@ -58,21 +69,19 @@
 
 
     /**
-     * Returns the boundary of Geometry <i>geom</i> in OpenLayers
+     * Returns the boundary of Envelope <i>env</i> in OpenLayers
      * representation.
      *
-     * @param geom The geometry.
+     * @param env The envelope of a geometry.
      *
-     * @return the OpenLayers boundary of <i>geom</i>.
+     * @return the OpenLayers boundary of <i>env</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;
+    public static String jtsBoundsToOLBounds(Envelope env) {
+        return "" +
+            env.getMinX() + " " +
+            env.getMinY() + " " +
+            env.getMaxX() + " " +
+            env.getMaxY();
     }
 
 

http://dive4elements.wald.intevation.org