Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/math/AreaInterpolation.java @ 495:6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
gnv-artifacts/trunk@572 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 19 Jan 2010 14:06:10 +0000 |
parents | 64e65daa65e9 |
children | 75306d856004 |
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/AreaInterpolation.java Tue Jan 19 12:45:51 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/AreaInterpolation.java Tue Jan 19 14:06:10 2010 +0000 @@ -9,12 +9,15 @@ import java.io.Serializable; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import org.apache.log4j.Logger; +import de.intevation.gnv.utils.GridIndex; + /** * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) */ @@ -58,32 +61,45 @@ return false; } - double [] buffer = Interpolation2D.calculateBuffer(points); + int W = samples.width; + int H = samples.height; + + double cellWidth = boundingBox.getWidth() / W; + double cellHeight = boundingBox.getHeight() / H; + Envelope gridEnvelope = new Envelope(boundingBox); + + gridEnvelope.expandBy(2d*cellWidth, 2d*cellWidth); + + ArrayList<Point2d>relevantPoints = + new ArrayList<Point2d>(); + + for (int i = points.size()-1; i >= 0; --i) { + if (gridEnvelope.contains(points.get(i))) { + relevantPoints.add(points.get(i)); + } + } + + double [] buffer = Interpolation2D.calculateBuffer(relevantPoints); double dxMax = buffer[0]; double dyMax = buffer[1]; Quadtree spatialIndex = new Quadtree(); - for (int i = points.size()-1; i >= 0; --i) { - Point2d p = points.get(i); + for (int i = relevantPoints.size()-1; i >= 0; --i) { + Point2d p = relevantPoints.get(i); spatialIndex.insert(p.envelope(), p); } - int W = samples.width; - int H = samples.height; - - double cellWidth = boundingBox.getWidth() / W; - double cellHeight = boundingBox.getHeight() / H; - if (debug) { - log.debug("width: " + boundingBox.getWidth()); - log.debug("height: " + boundingBox.getHeight()); + log.debug("points: " + relevantPoints.size()); + log.debug("width: " + boundingBox.getWidth()); + log.debug("height: " + boundingBox.getHeight()); log.debug("sample width: " + W); log.debug("sample height: " + H); - log.debug("cell width: " + cellWidth); - log.debug("cell height: " + cellHeight); - log.debug("buffer x: " + dxMax); - log.debug("buffer y: " + dyMax); + log.debug("cell width: " + cellWidth); + log.debug("cell height: " + cellHeight); + log.debug("buffer x: " + dxMax); + log.debug("buffer y: " + dyMax); } Envelope queryBuffer = new Envelope(); @@ -97,8 +113,8 @@ double minX = boundingBox.getMinX(); double minY = boundingBox.getMinY(); - int row = 0; - for (int j = 0; j < H; ++j, row += W) { + int row = (H-1)*W; + for (int j = 0; j < H; ++j, row -= W) { double y = j*cellHeight + 0.5d*cellHeight + minY; double x = 0.5d*cellWidth + minX; for (int i = 0; i < W; ++i, x += cellWidth) {