tim@173: /** tim@173: * tim@173: */ tim@173: package de.intevation.gnv.transition; tim@173: tim@173: import java.util.ArrayList; tim@173: import java.util.Collection; tim@180: import java.util.Iterator; tim@173: tim@173: import org.apache.log4j.Logger; tim@173: tim@173: import com.vividsolutions.jts.geom.Point; tim@180: import com.vividsolutions.jts.io.ParseException; tim@180: import com.vividsolutions.jts.io.WKTReader; tim@173: tim@173: import de.intevation.gnv.geobackend.base.Result; tim@180: import de.intevation.gnv.transition.describedata.DefaultKeyValueDescribeData; tim@173: import de.intevation.gnv.transition.describedata.KeyValueDescibeData; tim@180: import de.intevation.gnv.transition.describedata.NamedArrayList; tim@173: import de.intevation.gnv.transition.describedata.NamedCollection; tim@173: import de.intevation.gnv.utils.InputValidator; tim@173: import de.intevation.gnv.utils.exception.ValidationException; tim@173: tim@173: /** tim@173: * @author Tim Englich tim@173: * tim@173: */ tim@173: public class CoordinateSelectionTransition extends TransitionBase { tim@173: tim@173: /** tim@173: * the logger, used to log exceptions and additonaly information tim@173: */ tim@173: private static Logger log = Logger.getLogger(CoordinateSelectionTransition.class); tim@173: tim@173: /** tim@173: * The UID of this Class tim@173: */ tim@173: private static final long serialVersionUID = 6318923553625195063L; tim@173: tim@173: /** tim@173: * Constructor tim@173: */ tim@173: public CoordinateSelectionTransition() { tim@173: super(); tim@173: } tim@173: tim@173: /** tim@173: * @see de.intevation.gnv.transition.Transition#validate() tim@173: */ tim@173: public boolean validate() { tim@173: return true; tim@173: } tim@173: tim@173: @Override tim@173: protected void purifyResult(Collection result, String uuid) { tim@173: log.debug("CoordinateSelectionTransition.purifyResult"); tim@207: Collection describeData = this.getDescibeData(uuid); tim@207: if (describeData == null) { tim@207: describeData = new ArrayList(); tim@173: } tim@173: NamedCollection keyValueDescibeData = this tim@173: .extractKVP(result, "FEATUREID", "SHAPE"); tim@207: describeData.add(keyValueDescibeData); tim@207: this.setDescibeData(uuid, describeData); tim@173: } tim@173: tim@173: @Override tim@173: protected String prepareInputData4RegionDBQuery(String value) { tim@173: log.debug("CoordinateSelectionTransition.prepareInputData4RegionDBQuery"); tim@173: double distance=0.; tim@173: String returnValue = null; tim@173: try { tim@173: Point center = new InputValidator().getPointValue(value); tim@173: String meshIDValue = super.inputData.get("meshid").getValue(); tim@173: int segments = 97; tim@173: int meshid = new Integer(meshIDValue); tim@173: if (meshid == 3 || meshid == 5){ // TODO nicht hier festbrennen. tim@173: distance = 0.15; //nord-ostsee 6nm // 97 Stützpunkte tim@173: }else if (meshid == 1 || meshid == 4){ tim@173: distance = 0.03; //Kuestenmodell 1 nm tim@173: }else if (meshid == 2 || meshid == 321){ tim@173: distance = 0.3; //SST Karten ca 20km tim@173: }else if (meshid == 641){ tim@173: distance = 0.3; //Eisdaten Klima tim@173: } tim@173: returnValue = center.buffer(distance,segments).toText(); tim@173: } catch (NumberFormatException e) { tim@173: log.error(e,e); tim@173: } catch (ValidationException e) { tim@173: log.error(e,e); tim@173: } tim@173: return returnValue; tim@173: tim@173: } tim@180: tim@180: /** tim@180: * @see de.intevation.gnv.transition.TransitionBase#extractKVP(java.util.Collection, java.lang.String, java.lang.String) tim@180: */ tim@180: @Override tim@180: protected NamedCollection extractKVP( tim@180: Collection result, tim@180: String keyid, tim@180: String valueid) { tim@180: Iterator rit = result.iterator(); tim@180: NamedCollection keyValueDescibeData = new NamedArrayList( tim@180: this.dataName, result.size()); tim@180: keyValueDescibeData.setMultiSelect(this.dataMultiSelect); tim@205: String prevKey = null; tim@180: while (rit.hasNext()) { tim@180: Result resultValue = rit.next(); tim@205: String key = resultValue.getString(keyid); tim@205: if(prevKey == null || !prevKey.equals(key)){ // müssen wir so machen, da die sde kein select distinct auf layern zulässt. tim@205: String geomString = this.convert2DisplayCoordinate(resultValue.getString(valueid)); tim@205: String value = geomString; tim@205: if (resultValue.getResultDescriptor().getColumnIndex("VALUE") > 0){ tim@205: value = resultValue.getString("VALUE") + " - "+value; tim@205: } tim@205: tim@205: tim@205: keyValueDescibeData.add(new DefaultKeyValueDescribeData(key,value )); tim@205: } tim@205: prevKey = key; tim@180: } tim@180: return keyValueDescibeData; tim@180: } tim@180: tim@180: protected String convert2DisplayCoordinate(String wkt){ tim@180: String formattedCoordinate = null; tim@180: try { tim@180: Point p = (Point)new WKTReader().read(wkt); tim@180: double lat = p.getY(); tim@180: double lon =p.getX(); tim@180: String nord="N"; tim@180: String ost="E"; tim@180: if (lat <0 ){nord="S"; lat=-lat;} tim@180: if (lon <0 ){ost="W"; lon=-lon;} tim@180: formattedCoordinate = String.format("%1$02d°%2$1S %3$05.2f' %4$03d°%5$1S %6$05.2f'", tim@180: (int)lat, nord,60.*(lat-((int)lat)),(int)lon,ost,60.*(lon-((int)lon))); tim@180: } catch (ParseException e) { tim@180: log.error(e,e); tim@180: } tim@180: tim@180: return formattedCoordinate; tim@180: } tim@173: }