tim@544: /** tim@544: * tim@544: */ tim@544: package de.intevation.gnv.geobackend.sde.datasources; tim@544: tim@544: import com.vividsolutions.jts.geom.Coordinate; tim@544: import com.vividsolutions.jts.geom.Envelope; tim@544: tim@544: /** tim@544: * @author Tim Englich tim@544: * tim@544: */ tim@544: public class RasterObject { tim@544: tim@544: private int rasterSize; tim@544: private int rowIndex; tim@544: private int columnIndex; tim@544: private int rasterWidth; tim@544: private int rasterHeight; tim@544: private Envelope envelope = null; tim@544: private Envelope rasterEnvelope = null; tim@544: tim@544: private double[] rasterData = null; tim@544: /** tim@544: * Constructor tim@544: */ tim@544: public RasterObject(Envelope envelope , double[] rasterData, tim@544: int rasterSize, int rowIndex, tim@544: int columnIndex, int rasterWidth, int rasterHeight ){ tim@544: this.envelope = envelope; tim@544: this.rasterData = rasterData; tim@544: this.rasterSize = rasterSize; tim@544: this.rowIndex = rowIndex; tim@544: this.columnIndex = columnIndex; tim@544: this.rasterHeight = rasterHeight; tim@544: this.rasterWidth = rasterWidth; tim@544: } tim@544: public synchronized Envelope getEnvelope() { tim@544: if (this.rasterEnvelope == null){ tim@544: double minX = (columnIndex* rasterSize * tim@544: (envelope.getWidth() / rasterWidth)+ envelope.getMinX()); tim@544: double maxX = minX + (rasterSize * (envelope.getWidth() / rasterWidth)); tim@544: tim@544: double maxY = envelope.getMaxY() - tim@544: (rowIndex * rasterSize * tim@544: (envelope.getHeight() / rasterHeight)); tim@544: double minY = maxY - tim@544: (rasterSize * (envelope.getHeight() / rasterHeight)); tim@544: this.rasterEnvelope = new Envelope( tim@544: new Coordinate(minX, minY), tim@544: new Coordinate(maxX, maxY)); tim@544: } tim@544: return this.rasterEnvelope; tim@544: } tim@544: tim@544: public synchronized double getValue(Coordinate coordinate){ tim@544: double dxNature = coordinate.x - envelope.getMinX(); tim@544: double dyNature = envelope.getMaxY() - coordinate.y; tim@544: double widthNature = envelope.getMaxX()-envelope.getMinX(); tim@544: double heightNature = envelope.getMaxY()-envelope.getMinY(); tim@544: tim@544: int pixelX = (int)Math.round(dxNature * rasterWidth / widthNature); tim@544: int pixelY = (int)Math.round(dyNature * rasterHeight/ heightNature); tim@544: tim@544: tim@544: int localPixelX = pixelX - (columnIndex*rasterSize); tim@544: int localPixelY = pixelY - (rowIndex*rasterSize); tim@544: tim@544: int pos = localPixelY * rasterSize + localPixelX; tim@544: tim@544: tim@544: if (pos < rasterData.length){ tim@544: return this.rasterData[pos]; tim@544: } tim@544: tim@544: return Double.NaN; tim@544: } tim@544: tim@544: }