Mercurial > dive4elements > gnv-client
view gnv-artifacts/src/main/java/de/intevation/gnv/transition/CoordinateSelectionTransition.java @ 231:74255064a4c5
Added the Region-Filter to the Workflow of the Artifacttescases to be able to test it automatically.
Checkin laer because of trouble with checksum of these file
gnv-artifacts/trunk@299 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Fri, 06 Nov 2009 11:12:45 +0000 |
parents | ee2d4134d0b3 |
children |
line wrap: on
line source
/** * */ package de.intevation.gnv.transition; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import org.apache.log4j.Logger; import com.vividsolutions.jts.geom.Point; import com.vividsolutions.jts.io.ParseException; import com.vividsolutions.jts.io.WKTReader; import de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.transition.describedata.DefaultKeyValueDescribeData; import de.intevation.gnv.transition.describedata.KeyValueDescibeData; import de.intevation.gnv.transition.describedata.NamedArrayList; import de.intevation.gnv.transition.describedata.NamedCollection; import de.intevation.gnv.utils.InputValidator; import de.intevation.gnv.utils.exception.ValidationException; /** * @author Tim Englich <tim.englich@intevation.de> * */ 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(); } @Override protected void purifyResult(Collection<Result> result, String uuid) { log.debug("CoordinateSelectionTransition.purifyResult"); Collection<Object> describeData = this.getDescibeData(uuid); if (describeData == null) { describeData = new ArrayList<Object>(); } NamedCollection<KeyValueDescibeData> keyValueDescibeData = this .extractKVP(result, "FEATUREID", "SHAPE"); describeData.add(keyValueDescibeData); this.setDescibeData(uuid, describeData); } @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; } /** * @see de.intevation.gnv.transition.TransitionBase#extractKVP(java.util.Collection, java.lang.String, java.lang.String) */ @Override protected NamedCollection<KeyValueDescibeData> extractKVP( Collection<Result> result, String keyid, String valueid) { Iterator<Result> rit = result.iterator(); NamedCollection<KeyValueDescibeData> keyValueDescibeData = new NamedArrayList<KeyValueDescibeData>( this.dataName, result.size()); keyValueDescibeData.setMultiSelect(this.dataMultiSelect); String prevKey = null; while (rit.hasNext()) { Result resultValue = rit.next(); String key = resultValue.getString(keyid); if(prevKey == null || !prevKey.equals(key)){ // m�ssen wir so machen, da die sde kein select distinct auf layern zul�sst. String geomString = this.convert2DisplayCoordinate(resultValue.getString(valueid)); String value = geomString; if (resultValue.getResultDescriptor().getColumnIndex("VALUE") > 0){ value = resultValue.getString("VALUE") + " - "+value; } keyValueDescibeData.add(new DefaultKeyValueDescribeData(key,value )); } prevKey = key; } return keyValueDescibeData; } protected String convert2DisplayCoordinate(String wkt){ String formattedCoordinate = null; try { Point p = (Point)new WKTReader().read(wkt); double lat = p.getY(); double lon =p.getX(); String nord="N"; String ost="E"; if (lat <0 ){nord="S"; lat=-lat;} if (lon <0 ){ost="W"; lon=-lon;} formattedCoordinate = String.format("%1$02d�%2$1S %3$05.2f' %4$03d�%5$1S %6$05.2f'", (int)lat, nord,60.*(lat-((int)lat)),(int)lon,ost,60.*(lon-((int)lon))); } catch (ParseException e) { log.error(e,e); } return formattedCoordinate; } }