comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java @ 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 1efb6a66c7d9
children 9a828e5a2390
comparison
equal deleted inserted replaced
745:d194939ecbaf 746:b81f6f896668
9 import org.apache.log4j.Logger; 9 import org.apache.log4j.Logger;
10 10
11 import com.vividsolutions.jts.geom.Coordinate; 11 import com.vividsolutions.jts.geom.Coordinate;
12 import com.vividsolutions.jts.geom.GeometryFactory; 12 import com.vividsolutions.jts.geom.GeometryFactory;
13 import com.vividsolutions.jts.geom.Point; 13 import com.vividsolutions.jts.geom.Point;
14 import com.vividsolutions.jts.io.ParseException;
15 import com.vividsolutions.jts.io.WKTReader;
14 16
15 import de.intevation.gnv.geobackend.util.DateUtils; 17 import de.intevation.gnv.geobackend.util.DateUtils;
16 import de.intevation.gnv.utils.exception.ValidationException; 18 import de.intevation.gnv.utils.exception.ValidationException;
17 19
18 /** 20 /**
113 } 115 }
114 116
115 117
116 public Point getPointValue(String value) throws ValidationException{ 118 public Point getPointValue(String value) throws ValidationException{
117 log.debug("InputValidator.getPointValue " + value); 119 log.debug("InputValidator.getPointValue " + value);
118 String[] s, p;
119 120
120 double x=0,y=0; 121 if (value.toLowerCase().startsWith("point")){
121 log.info("Position :"+value); 122 try {
122 s = value.split(" "); 123 return (Point)new WKTReader().read(value);
123 if (s.length != 2) { 124 } catch (ParseException e) {
124 throw new ValidationException("Kein Blank separiert Breite und Länge"); 125 log.error(e,e);
126 throw new ValidationException(e);
127 }
128 }else{
129 String[] s, p;
130
131 double x=0,y=0;
132 log.info("Position :"+value);
133 s = value.split(" ");
134 if (s.length != 2) {
135 throw new ValidationException("Kein Blank separiert Breite und Länge");
136 }
137 p = s[0].split("[nNsS]");
138 try {
139 if (p.length == 1)
140 y = new Double(p[0]);
141 else
142 y = new Double(p[0]) + new Double(p[1]) / new Double(60.);
143 if (s[0].toLowerCase().contains("s"))
144 y = -y;
145 }
146 catch (Exception e) {
147 throw new ValidationException("Kein N|S oder nicht im ersten Substring, zB 56n42");
148
149 }
150 p = s[1].split("[eEwW]");
151 try {
152 if (p.length ==1)
153 x = new Double(p[0]);
154 else
155 x = new Double(p[0]) + new Double(p[1]) / new Double(60.) ;
156 if (s[1].toLowerCase().contains("w"))
157 x = -x;
158 }
159 catch (Exception e) {
160 throw new ValidationException("Kein E|W oder nicht im zweiten Substring");
161 }
162 return new GeometryFactory().createPoint(new Coordinate(x,y));
125 } 163 }
126 p = s[0].split("[nNsS]");
127 try {
128 if (p.length == 1)
129 y = new Double(p[0]);
130 else
131 y = new Double(p[0]) + new Double(p[1]) / new Double(60.);
132 if (s[0].toLowerCase().contains("s"))
133 y = -y;
134 }
135 catch (Exception e) {
136 throw new ValidationException("Kein N|S oder nicht im ersten Substring, zB 56n42");
137
138 }
139 p = s[1].split("[eEwW]");
140 try {
141 if (p.length ==1)
142 x = new Double(p[0]);
143 else
144 x = new Double(p[0]) + new Double(p[1]) / new Double(60.) ;
145 if (s[1].toLowerCase().contains("w"))
146 x = -x;
147 }
148 catch (Exception e) {
149 throw new ValidationException("Kein E|W oder nicht im zweiten Substring");
150 }
151 return new GeometryFactory().createPoint(new Coordinate(x,y));
152 } 164 }
153 165
154 } 166 }

http://dive4elements.wald.intevation.org