# HG changeset patch # User Sascha L. Teichmann # Date 1263909970 0 # Node ID 6e8364e766faf2148ba25452a509e5ef319f4efe # Parent 292f0c8d356c03e399acc129587d966238fc673d Generate JTS geometries of "Horizontalschnitte" correctly. gnv-artifacts/trunk@572 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 292f0c8d356c -r 6e8364e766fa gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Tue Jan 19 12:45:51 2010 +0000 +++ b/gnv-artifacts/ChangeLog Tue Jan 19 14:06:10 2010 +0000 @@ -1,3 +1,24 @@ +2010-01-19 Sascha L. Teichmann + + * src/main/java/de/intevation/gnv/raster/RasterToPPM.java: New. + Class to write rasters with palettes to portable pixmaps. + Handy to debug raster outputs. + + * src/main/java/de/intevation/gnv/raster/Raster.java: Added + getValues() to access the backing data. + + * src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java: + Read parameter from input data correctly. + + * src/main/java/de/intevation/gnv/raster/JTSMultiPolygonProducer.java: Walk + rings of polygons in reversed order to produce correct JTS polygons. + Its not entierly clear why this is necessary. + + * src/main/java/de/intevation/gnv/math/AreaInterpolation.java: Clipp the + input points against an buffered version of the bounding box of + the given polygon to reduce the number of data. TODO: figure out why + upside down rendering in necessary. + 2010-01-19 Tim Englich * doc/schema/externalinterface_testdata.sql, diff -r 292f0c8d356c -r 6e8364e766fa gnv-artifacts/src/main/java/de/intevation/gnv/math/AreaInterpolation.java --- 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); + + ArrayListrelevantPoints = + new ArrayList(); + + 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) { diff -r 292f0c8d356c -r 6e8364e766fa gnv-artifacts/src/main/java/de/intevation/gnv/raster/JTSMultiPolygonProducer.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/raster/JTSMultiPolygonProducer.java Tue Jan 19 12:45:51 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/raster/JTSMultiPolygonProducer.java Tue Jan 19 14:06:10 2010 +0000 @@ -115,7 +115,7 @@ m1*(current.a % width) + b1, m2*(current.a / width) + b2)); } - while ((current = current.next) != head); + while ((current = current.prev) != head); vertices.add(new Coordinate( m1*(head.a % width) + b1, m2*(head.a / width) + b2)); @@ -141,6 +141,8 @@ return; } + log.debug("polygon has a shell"); + Polygon polygon = geometryFactory.createPolygon( shell, holes.toArray(new LinearRing[holes.size()])); diff -r 292f0c8d356c -r 6e8364e766fa gnv-artifacts/src/main/java/de/intevation/gnv/raster/Raster.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/raster/Raster.java Tue Jan 19 12:45:51 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/raster/Raster.java Tue Jan 19 14:06:10 2010 +0000 @@ -192,6 +192,10 @@ return raster.length / width; } + public double [] getValues() { + return raster; + } + public int [] toIndexed(ValueToIndex valueToIndex) { int [] dst = new int[raster.length]; for (int i = 0; i < raster.length; ++i) { diff -r 292f0c8d356c -r 6e8364e766fa gnv-artifacts/src/main/java/de/intevation/gnv/raster/RasterToPPM.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/raster/RasterToPPM.java Tue Jan 19 14:06:10 2010 +0000 @@ -0,0 +1,41 @@ +package de.intevation.gnv.raster; + +import java.io.IOException; +import java.io.OutputStream; + +import java.awt.Color; + +/** + * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) + */ +public class RasterToPPM +{ + private RasterToPPM() { + } + + public static void writeToPPM(Raster raster, Palette palette, OutputStream out) + throws IOException + { + int W = raster.getWidth(); + int H = raster.getHeight(); + out.write(("P6\n" + W + " " + H + "\n255\n").getBytes("US-ASCII")); + double [] values = raster.getValues(); + int pos = 0; + byte [] data = new byte[W*3]; + int black = Color.BLACK.getRGB(); + for (int i = 0; i < H; ++i) { + for (int j = 0; j < data.length; ++pos) { + Palette.Entry entry = palette.getEntry(values[pos]); + int rgb = entry == null + ? black + : entry.getColor().getRGB(); + data[j++] = (byte)((rgb >> 16) & 0xff); + data[j++] = (byte)((rgb >> 8) & 0xff); + data[j++] = (byte)( rgb & 0xff); + } + out.write(data); + } + out.flush(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 292f0c8d356c -r 6e8364e766fa gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java Tue Jan 19 12:45:51 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java Tue Jan 19 14:06:10 2010 +0000 @@ -55,6 +55,7 @@ import java.awt.Dimension; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -431,7 +432,7 @@ } Integer parameterId = - (Integer)input.getAttribute("PARAMETERID"); // XXX: hardcoded + (Integer)input.getAttribute("parameter"); // XXX: hardcoded if (parameterId == null) { log.error("missing parameter id");