changeset 746:b81f6f896668

Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring. gnv-artifacts/trunk@786 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 16 Mar 2010 12:55:58 +0000
parents d194939ecbaf
children a5e860f17a52
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java
diffstat 2 files changed, 50 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Tue Mar 16 12:53:37 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Tue Mar 16 12:55:58 2010 +0000
@@ -1,3 +1,9 @@
+2010-03-16  Tim Englich  <tim.englich@intevation.de>
+
+	* src/main/java/de/intevation/gnv/utils/InputValidator.java (getPointValue):
+	  Integrated handling of WKT-Strings for Points to extract Points from
+	  a given Inputstring.
+
 2010-03-16  Tim Englich  <tim.englich@intevation.de>
 
 	* src/main/java/de/intevation/gnv/state/StateBase.java (generateFilterValuesFromInputData): 
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java	Tue Mar 16 12:53:37 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java	Tue Mar 16 12:55:58 2010 +0000
@@ -11,6 +11,8 @@
 import com.vividsolutions.jts.geom.Coordinate;
 import com.vividsolutions.jts.geom.GeometryFactory;
 import com.vividsolutions.jts.geom.Point;
+import com.vividsolutions.jts.io.ParseException;
+import com.vividsolutions.jts.io.WKTReader;
 
 import de.intevation.gnv.geobackend.util.DateUtils;
 import de.intevation.gnv.utils.exception.ValidationException;
@@ -115,40 +117,50 @@
     
     public Point getPointValue(String value) throws ValidationException{
         log.debug("InputValidator.getPointValue " + value);
-        String[] s, p;
         
-        double x=0,y=0;
-        log.info("Position :"+value);
-        s = value.split(" ");
-        if (s.length != 2) {
-              throw new ValidationException("Kein Blank separiert Breite und Länge");
-        }
-        p = s[0].split("[nNsS]");
-        try {
-            if (p.length == 1)
-                y = new Double(p[0]);
-            else
-                y = new Double(p[0]) +   new Double(p[1]) / new Double(60.);
-            if (s[0].toLowerCase().contains("s"))
-                y = -y;
+        if (value.toLowerCase().startsWith("point")){
+            try {
+                return (Point)new WKTReader().read(value);
+            } catch (ParseException e) {
+                log.error(e,e);
+                throw new ValidationException(e);
+            }
+        }else{
+            String[] s, p;
+            
+            double x=0,y=0;
+            log.info("Position :"+value);
+            s = value.split(" ");
+            if (s.length != 2) {
+                  throw new ValidationException("Kein Blank separiert Breite und Länge");
+            }
+            p = s[0].split("[nNsS]");
+            try {
+                if (p.length == 1)
+                    y = new Double(p[0]);
+                else
+                    y = new Double(p[0]) +   new Double(p[1]) / new Double(60.);
+                if (s[0].toLowerCase().contains("s"))
+                    y = -y;
+            }
+            catch (Exception e) {
+                throw new ValidationException("Kein N|S oder nicht im ersten Substring, zB 56n42");
+            
+            } 
+            p = s[1].split("[eEwW]");
+            try {
+                if (p.length ==1)
+                    x = new Double(p[0]);
+                else
+                    x = new Double(p[0]) +  new Double(p[1]) / new Double(60.) ;
+                if (s[1].toLowerCase().contains("w"))
+                    x = -x;
+            }
+            catch (Exception e) {
+                throw new ValidationException("Kein E|W oder nicht im zweiten Substring");
+            } 
+            return new GeometryFactory().createPoint(new Coordinate(x,y));
         }
-        catch (Exception e) {
-            throw new ValidationException("Kein N|S oder nicht im ersten Substring, zB 56n42");
-        
-        } 
-        p = s[1].split("[eEwW]");
-        try {
-            if (p.length ==1)
-                x = new Double(p[0]);
-            else
-                x = new Double(p[0]) +  new Double(p[1]) / new Double(60.) ;
-            if (s[1].toLowerCase().contains("w"))
-                x = -x;
-        }
-        catch (Exception e) {
-            throw new ValidationException("Kein E|W oder nicht im zweiten Substring");
-        } 
-        return new GeometryFactory().createPoint(new Coordinate(x,y));
     }
 
 }

http://dive4elements.wald.intevation.org