view gnv-artifacts/src/main/java/de/intevation/gnv/math/QueriedXYDepth.java @ 455:363236fc462d

Added Rasterdatasupport to VerticalCrossSections gnv-artifacts/trunk@505 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Mon, 04 Jan 2010 15:27:33 +0000
parents
children 47ad9721e692
line wrap: on
line source
/**
 *
 */
package de.intevation.gnv.math;

import java.util.Collection;

import org.apache.log4j.Logger;

import com.vividsolutions.jts.geom.Coordinate;

import de.intevation.gnv.geobackend.base.Result;
import de.intevation.gnv.geobackend.base.query.QueryExecutor;
import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory;
import de.intevation.gnv.geobackend.base.query.exception.QueryException;


/**
 * @author Tim Englich <tim.englich@intevation.de>
 *
 */
public class QueriedXYDepth implements XYDepth {

    /**
     * the logger, used to log exceptions and additonaly information
     */
    private static Logger log = Logger.getLogger(QueriedXYDepth.class);
    
    private String queryID = "rasterQuery";
    
    private QueryExecutor queryExecutor = null;
    
    /**
     * Constructor
     */
    public QueriedXYDepth() {
        this.queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor();
    }

    /**
     * @see de.intevation.gnv.math.XYDepth#depth(com.vividsolutions.jts.geom.Coordinate)
     */
    public double depth(Coordinate coordinate) {
        log.debug("QueriedXYDepth.depth for " + coordinate.x+" "+ coordinate.y);
        double resultValue = 0;
        Collection<Result> result = null;
        try {
            String[] filterValues = new String[]{"Point ("+coordinate.x+" "+coordinate.y+")"};
            result = this.queryExecutor.executeQuery(this.queryID,filterValues);
        } catch (QueryException e) {
            log.error(e,e);
        }
        
        if (result != null){
            if (!result.isEmpty()){
                Result row = result.iterator().next();
                resultValue = row.getDouble(0);
            }else{
                resultValue = Double.NaN;
            }
        }else{
            resultValue = Double.NaN;
        }
        return resultValue;
    }

}

http://dive4elements.wald.intevation.org