tim@335: /** tim@335: * tim@335: */ tim@335: package de.intevation.gnv.state; tim@335: tim@335: import java.util.ArrayList; tim@335: import java.util.Collection; tim@335: import java.util.Iterator; ingo@470: import java.util.List; tim@335: tim@335: import org.apache.log4j.Logger; tim@335: tim@335: import com.vividsolutions.jts.geom.Point; tim@335: import com.vividsolutions.jts.io.ParseException; tim@335: import com.vividsolutions.jts.io.WKTReader; tim@335: tim@335: import de.intevation.gnv.geobackend.base.Result; tim@335: import de.intevation.gnv.state.describedata.DefaultKeyValueDescribeData; tim@335: import de.intevation.gnv.state.describedata.KeyValueDescibeData; tim@335: import de.intevation.gnv.state.describedata.NamedArrayList; tim@335: import de.intevation.gnv.state.describedata.NamedCollection; tim@335: import de.intevation.gnv.utils.InputValidator; ingo@507: import de.intevation.gnv.utils.WKTUtils; tim@335: import de.intevation.gnv.utils.exception.ValidationException; tim@335: tim@335: /** tim@335: * @author Tim Englich tim@335: * tim@335: */ tim@335: public class CoordinateSelectionState extends StateBase { tim@335: tim@335: /** tim@335: * the logger, used to log exceptions and additonaly information tim@335: */ tim@335: private static Logger log = Logger.getLogger(CoordinateSelectionState.class); tim@335: tim@335: /** tim@335: * The UID of this Class tim@335: */ tim@335: private static final long serialVersionUID = 6318923553625195063L; tim@335: tim@335: /** tim@335: * Constructor tim@335: */ tim@335: public CoordinateSelectionState() { tim@335: super(); tim@335: } tim@335: tim@335: @Override tim@335: protected void purifyResult(Collection result, String uuid) { tim@335: log.debug("CoordinateSelectionState.purifyResult"); ingo@470: List describeData = this.getDescibeData(uuid); tim@335: if (describeData == null) { tim@335: describeData = new ArrayList(); tim@335: } tim@335: NamedCollection keyValueDescibeData = this tim@335: .extractKVP(result, "FEATUREID", "SHAPE"); tim@335: describeData.add(keyValueDescibeData); tim@335: this.setDescibeData(uuid, describeData); tim@335: } tim@335: tim@335: @Override tim@335: protected String prepareInputData4RegionDBQuery(String value) { tim@335: log.debug("CoordinateSelectionState.prepareInputData4RegionDBQuery"); tim@335: double distance=0.; tim@335: String returnValue = null; tim@335: try { tim@335: Point center = new InputValidator().getPointValue(value); tim@335: String meshIDValue = super.inputData.get("meshid").getValue(); tim@335: int segments = 97; tim@335: int meshid = new Integer(meshIDValue); tim@335: if (meshid == 3 || meshid == 5){ // TODO nicht hier festbrennen. tim@461: distance = 0.15; //nord-ostsee 6nm // 97 Stützpunkte tim@335: }else if (meshid == 1 || meshid == 4){ tim@335: distance = 0.03; //Kuestenmodell 1 nm tim@335: }else if (meshid == 2 || meshid == 321){ tim@335: distance = 0.3; //SST Karten ca 20km tim@335: }else if (meshid == 641){ tim@335: distance = 0.3; //Eisdaten Klima tim@335: } tim@335: returnValue = center.buffer(distance,segments).toText(); tim@335: } catch (NumberFormatException e) { tim@335: log.error(e,e); tim@335: } catch (ValidationException e) { tim@335: log.error(e,e); tim@335: } tim@335: return returnValue; tim@335: tim@335: } tim@335: tim@335: /** tim@335: * @see de.intevation.gnv.state.StateBase#extractKVP(java.util.Collection, java.lang.String, java.lang.String) tim@335: */ tim@335: @Override tim@335: protected NamedCollection extractKVP( tim@335: Collection result, tim@335: String keyid, tim@335: String valueid) { tim@335: Iterator rit = result.iterator(); tim@335: NamedCollection keyValueDescibeData = new NamedArrayList( tim@335: this.dataName, result.size()); tim@335: keyValueDescibeData.setMultiSelect(this.dataMultiSelect); tim@335: String prevKey = null; tim@335: while (rit.hasNext()) { tim@335: Result resultValue = rit.next(); tim@335: String key = resultValue.getString(keyid); tim@461: if(prevKey == null || !prevKey.equals(key)){ // TODO: FIXME: We have to do that because the arcsde does not support a distinct Query on Layers tim@335: String geomString = this.convert2DisplayCoordinate(resultValue.getString(valueid)); tim@335: String value = geomString; tim@335: if (resultValue.getResultDescriptor().getColumnIndex("VALUE") > 0){ tim@335: value = resultValue.getString("VALUE") + " - "+value; tim@335: } tim@335: tim@335: tim@335: keyValueDescibeData.add(new DefaultKeyValueDescribeData(key,value )); tim@335: } tim@335: prevKey = key; tim@335: } tim@335: return keyValueDescibeData; tim@335: } tim@335: ingo@507: protected static String convert2DisplayCoordinate(String wkt){ ingo@507: return WKTUtils.toText(wkt); tim@335: } tim@335: }