# HG changeset patch # User Tim Englich # Date 1255425083 0 # Node ID 1b2fc94766c9e3ee80e7bd9eb4933d7bcb468057 # Parent b5e55f460f0b2cc9f7e85a116d3d5df0bf9eedb9 Added real Coordinate-Query to TimeSeries-Mesh gnv-artifacts/trunk@212 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r b5e55f460f0b -r 1b2fc94766c9 gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Mon Oct 12 09:19:16 2009 +0000 +++ b/gnv-artifacts/ChangeLog Tue Oct 13 09:11:23 2009 +0000 @@ -1,3 +1,21 @@ +2009-10-13 Tim Englich + + * src/main/resources/lang/artifactMessages_*.properties: + Switched to better Description of an Coordinate-Input-Field + * src/test/ressources/timeseries_mesh/timeseries_*_feed.xml: + Switched to Szenario where it is possible to select Data using the Coordinate. + * src/test/ressources/queries.properties, + src/test/ressources/conf.xml: + Switched to SFS-Conformant-Queries in Timeseries-Mesh + * pom.xml: + Added dependency to JTS 1.9 + * src/main/java/de/intevation/gnv/utils/exception/ValidationException.java (ValidationException): + src/main/java/de/intevation/gnv/utils/InputValidator.java (getPointValue): + src/main/java/de/intevation/gnv/transition/TransitionBase.java (prepareInputData4RegionDBQuery): + Added the Support for specialized Handling of InputValues of type Coordinate. + * src/main/java/de/intevation/gnv/transition/CoordinateSelectionTransition.java: + Added Transition for the Support of Coordinateinput handling. + 2009-10-12 Sascha L. Teichmann * src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java: diff -r b5e55f460f0b -r 1b2fc94766c9 gnv-artifacts/pom.xml --- a/gnv-artifacts/pom.xml Mon Oct 12 09:19:16 2009 +0000 +++ b/gnv-artifacts/pom.xml Tue Oct 13 09:11:23 2009 +0000 @@ -80,5 +80,17 @@ oro 2.0.8 + + com.vividsolutions + jts + 1.9 + + + + gt2.repo + GeoTools2 Repository including JTS + http://maven.geotools.fr/repository + + diff -r b5e55f460f0b -r 1b2fc94766c9 gnv-artifacts/src/main/java/de/intevation/gnv/transition/CoordinateSelectionTransition.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/CoordinateSelectionTransition.java Tue Oct 13 09:11:23 2009 +0000 @@ -0,0 +1,88 @@ +/** + * + */ +package de.intevation.gnv.transition; + +import java.util.ArrayList; +import java.util.Collection; + +import org.apache.log4j.Logger; + +import com.vividsolutions.jts.geom.Point; + +import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.transition.describedata.KeyValueDescibeData; +import de.intevation.gnv.transition.describedata.NamedCollection; +import de.intevation.gnv.utils.InputValidator; +import de.intevation.gnv.utils.exception.ValidationException; + +/** + * @author Tim Englich + * + */ +public class CoordinateSelectionTransition extends TransitionBase { + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(CoordinateSelectionTransition.class); + + /** + * The UID of this Class + */ + private static final long serialVersionUID = 6318923553625195063L; + + /** + * Constructor + */ + public CoordinateSelectionTransition() { + super(); + } + + /** + * @see de.intevation.gnv.transition.Transition#validate() + */ + public boolean validate() { + return true; + } + + @Override + protected void purifyResult(Collection result, String uuid) { + log.debug("CoordinateSelectionTransition.purifyResult"); + if (this.descibeData == null) { + this.descibeData = new ArrayList(); + } + NamedCollection keyValueDescibeData = this + .extractKVP(result, "FEATUREID", "SHAPE"); + this.descibeData.add(keyValueDescibeData); + } + + @Override + protected String prepareInputData4RegionDBQuery(String value) { + log.debug("CoordinateSelectionTransition.prepareInputData4RegionDBQuery"); + double distance=0.; + String returnValue = null; + try { + Point center = new InputValidator().getPointValue(value); + String meshIDValue = super.inputData.get("meshid").getValue(); + int segments = 97; + int meshid = new Integer(meshIDValue); + if (meshid == 3 || meshid == 5){ // TODO nicht hier festbrennen. + distance = 0.15; //nord-ostsee 6nm // 97 Stützpunkte + }else if (meshid == 1 || meshid == 4){ + distance = 0.03; //Kuestenmodell 1 nm + }else if (meshid == 2 || meshid == 321){ + distance = 0.3; //SST Karten ca 20km + }else if (meshid == 641){ + distance = 0.3; //Eisdaten Klima + } + returnValue = center.buffer(distance,segments).toText(); + } catch (NumberFormatException e) { + log.error(e,e); + } catch (ValidationException e) { + log.error(e,e); + } + return returnValue; + + } +} diff -r b5e55f460f0b -r 1b2fc94766c9 gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java Mon Oct 12 09:19:16 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java Tue Oct 13 09:11:23 2009 +0000 @@ -335,6 +335,9 @@ } else if (type.equalsIgnoreCase("date")) { requestValue = this .prepareInputData4DateDBQuery(requestValue); + } else if (type.equalsIgnoreCase("coordinate")){ + requestValue = this + .prepareInputData4RegionDBQuery(requestValue); } for (int j = 0; j < size; j++) { list.add(requestValue); @@ -359,6 +362,10 @@ throw new TransitionException(e); } } + + protected String prepareInputData4RegionDBQuery(String value){ + return value; + } private String prepareInputData4DateDBQuery(String value) { log.debug("TransitionBase.prepareInputData4DateDBQuery"); @@ -405,6 +412,18 @@ if (this.descibeData == null) { this.descibeData = new ArrayList(); } + NamedCollection keyValueDescibeData = extractKVP(result, "KEY", "VALUE"); + this.descibeData.add(keyValueDescibeData); + } + + /** + * @param result + * @return + */ + protected NamedCollection extractKVP( + Collection result, + String keyid, + String valueid) { Iterator rit = result.iterator(); NamedCollection keyValueDescibeData = new NamedArrayList( this.dataName, result.size()); @@ -412,9 +431,9 @@ while (rit.hasNext()) { Result resultValue = rit.next(); keyValueDescibeData.add(new DefaultKeyValueDescribeData(resultValue - .getString("KEY"), resultValue.getString("VALUE"))); + .getString(keyid), resultValue.getString(valueid))); } - this.descibeData.add(keyValueDescibeData); + return keyValueDescibeData; } /** diff -r b5e55f460f0b -r 1b2fc94766c9 gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java Mon Oct 12 09:19:16 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java Tue Oct 13 09:11:23 2009 +0000 @@ -6,7 +6,12 @@ import org.apache.commons.validator.GenericValidator; import org.apache.log4j.Logger; +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.GeometryFactory; +import com.vividsolutions.jts.geom.Point; + import de.intevation.gnv.geobackend.util.DateUtils; +import de.intevation.gnv.utils.exception.ValidationException; /** * @author Tim Englich @@ -53,6 +58,13 @@ .matchRegexp(values[i], "[a-zA-Z0-9]"); // TODO: FIXME: // VALIDATE // REGEXP + } else if ("Coordinate".equalsIgnoreCase(type)) { + try { + valid = this.getPointValue(values[i]) != null; + } catch (ValidationException e) { + log.debug(e.getMessage()); + valid = false; + } } else { valid = false; } @@ -66,5 +78,44 @@ log.debug("Is valid? " + returnValue); return returnValue; } + + + 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; + } + 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)); + } } diff -r b5e55f460f0b -r 1b2fc94766c9 gnv-artifacts/src/main/java/de/intevation/gnv/utils/exception/ValidationException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/exception/ValidationException.java Tue Oct 13 09:11:23 2009 +0000 @@ -0,0 +1,48 @@ +/** + * + */ +package de.intevation.gnv.utils.exception; +/** + * @author Tim Englich + * + */ +public class ValidationException extends Exception { + + /** + * The Uid of this Class + */ + private static final long serialVersionUID = -6189218101861801079L; + + /** + * Constructor + */ + public ValidationException() { + super(); + } + + /** + * Constructor + * @param arg0 + */ + public ValidationException(String arg0) { + super(arg0); + } + + /** + * Constructor + * @param arg0 + */ + public ValidationException(Throwable arg0) { + super(arg0); + } + + /** + * Constructor + * @param arg0 + * @param arg1 + */ + public ValidationException(String arg0, Throwable arg1) { + super(arg0, arg1); + } + +} diff -r b5e55f460f0b -r 1b2fc94766c9 gnv-artifacts/src/main/resources/lang/artifactMessages.properties --- a/gnv-artifacts/src/main/resources/lang/artifactMessages.properties Mon Oct 12 09:19:16 2009 +0000 +++ b/gnv-artifacts/src/main/resources/lang/artifactMessages.properties Tue Oct 13 09:11:23 2009 +0000 @@ -11,7 +11,7 @@ verticalProfile = Verticalprofile horizontalProfile = Horizontalprofile featureid = Object -mesh_coordinate = Coordinate Value (x y) +mesh_coordinate = Position (e.g. 56n30 6e20) mesh_point = Meshpoint measurementid = Measurement depth parameterid = Parameter diff -r b5e55f460f0b -r 1b2fc94766c9 gnv-artifacts/src/main/resources/lang/artifactMessages_de.properties --- a/gnv-artifacts/src/main/resources/lang/artifactMessages_de.properties Mon Oct 12 09:19:16 2009 +0000 +++ b/gnv-artifacts/src/main/resources/lang/artifactMessages_de.properties Tue Oct 13 09:11:23 2009 +0000 @@ -12,7 +12,7 @@ horizontalProfile = Horizontalprofil featureid = Station meshid= Netz -mesh_coordinate = Koordinaten Wert (x y) +mesh_coordinate = Position (z.B. 56n30 6e20) mesh_point = Messpunkt measurementid = Messtiefe parameterid = Parameter diff -r b5e55f460f0b -r 1b2fc94766c9 gnv-artifacts/src/main/resources/lang/artifactMessages_de_DE.properties --- a/gnv-artifacts/src/main/resources/lang/artifactMessages_de_DE.properties Mon Oct 12 09:19:16 2009 +0000 +++ b/gnv-artifacts/src/main/resources/lang/artifactMessages_de_DE.properties Tue Oct 13 09:11:23 2009 +0000 @@ -12,7 +12,7 @@ horizontalProfile = Horizontalprofil featureid = Station meshid= Netz -mesh_coordinate = Koordinaten Wert (x y) +mesh_coordinate = Position (z.B. 56n30 6e20) mesh_point = Messpunkt measurementid = Messtiefe parameterid = Parameter diff -r b5e55f460f0b -r 1b2fc94766c9 gnv-artifacts/src/main/resources/lang/artifactMessages_en.properties --- a/gnv-artifacts/src/main/resources/lang/artifactMessages_en.properties Mon Oct 12 09:19:16 2009 +0000 +++ b/gnv-artifacts/src/main/resources/lang/artifactMessages_en.properties Tue Oct 13 09:11:23 2009 +0000 @@ -11,7 +11,7 @@ verticalProfile = Verticalprofile horizontalProfile = Horizontalprofile featureid = Object -mesh_coordinate = Coordinate Value (x y) +mesh_coordinate = Position (e.g. 56n30 6e20) mesh_point = Meshpoint measurementid = Measurement depth parameterid = Parameter diff -r b5e55f460f0b -r 1b2fc94766c9 gnv-artifacts/src/test/ressources/conf.xml --- a/gnv-artifacts/src/test/ressources/conf.xml Mon Oct 12 09:19:16 2009 +0000 +++ b/gnv-artifacts/src/test/ressources/conf.xml Tue Oct 13 09:11:23 2009 +0000 @@ -193,7 +193,7 @@ - + timeseries_meshpoint mesh_point false @@ -202,7 +202,7 @@ - + diff -r b5e55f460f0b -r 1b2fc94766c9 gnv-artifacts/src/test/ressources/queries.properties --- a/gnv-artifacts/src/test/ressources/queries.properties Mon Oct 12 09:19:16 2009 +0000 +++ b/gnv-artifacts/src/test/ressources/queries.properties Tue Oct 13 09:11:23 2009 +0000 @@ -94,14 +94,15 @@ m.NAME VALUE \ FROM MEDIAN.MESH m \ order by m.NAME -timeseries_meshpoint = SELECT FEATUREID KEY, \ - SHAPE VALUE \ - FROM MEDIAN.MESHPOINT mp , \ - MEDIAN.MESH m \ - WHERE m.OBJECTID = ? AND \ - mp.MESHID = m.MESHID AND \ - KPOSITION = 1 AND \ - rownum < 10 +timeseries_meshpoint = SELECT FEATUREID, \ + ST_ASTEXT(SHAPE) \ + FROM MEDIAN.MESHPOINT \ + WHERE MESHID in \ + (SELECT DISTINCT MESHID \ + FROM MEDIAN.MESH \ + WHERE OBJECTID = ?) AND \ + KPOSITION = 1 AND \ + INTERSECTS(SHAPE,"?") timeseries_meshpoint_depth = select mp.FEATUREID KEY, \ -ml.UPPERZLOCATION || ' - '|| -ml.LOWERZLOCATION as VALUE \ diff -r b5e55f460f0b -r 1b2fc94766c9 gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_02_feed.xml --- a/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_02_feed.xml Mon Oct 12 09:19:16 2009 +0000 +++ b/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_02_feed.xml Tue Oct 13 09:11:23 2009 +0000 @@ -4,6 +4,6 @@ - + \ No newline at end of file diff -r b5e55f460f0b -r 1b2fc94766c9 gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_03_feed.xml --- a/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_03_feed.xml Mon Oct 12 09:19:16 2009 +0000 +++ b/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_03_feed.xml Tue Oct 13 09:11:23 2009 +0000 @@ -4,6 +4,6 @@ - + \ No newline at end of file diff -r b5e55f460f0b -r 1b2fc94766c9 gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_04_feed.xml --- a/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_04_feed.xml Mon Oct 12 09:19:16 2009 +0000 +++ b/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_04_feed.xml Tue Oct 13 09:11:23 2009 +0000 @@ -4,6 +4,6 @@ - + \ No newline at end of file diff -r b5e55f460f0b -r 1b2fc94766c9 gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_05_feed.xml --- a/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_05_feed.xml Mon Oct 12 09:19:16 2009 +0000 +++ b/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_05_feed.xml Tue Oct 13 09:11:23 2009 +0000 @@ -4,7 +4,7 @@ - - + + \ No newline at end of file diff -r b5e55f460f0b -r 1b2fc94766c9 gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_07_feed.xml --- a/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_07_feed.xml Mon Oct 12 09:19:16 2009 +0000 +++ b/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_07_feed.xml Tue Oct 13 09:11:23 2009 +0000 @@ -4,7 +4,7 @@ - - + + \ No newline at end of file