# HG changeset patch # User Sascha L. Teichmann # Date 1263763581 0 # Node ID 64e65daa65e91116ecde41f406aa759467577cdf # Parent 20dde2b6f1b529bd279dbd1bba00363aed68ddaf Fixed some bugs with calculating "Horizontalschnitte". gnv-artifacts/trunk@557 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 20dde2b6f1b5 -r 64e65daa65e9 gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Sun Jan 17 16:34:11 2010 +0000 +++ b/gnv-artifacts/ChangeLog Sun Jan 17 21:26:21 2010 +0000 @@ -1,3 +1,21 @@ +2010-01-17 Sascha L. Teichmann + + * doc/conf/conf.xml: Reduced number of "Horizontalschnitt" + samples to 256 because its much too slow with higher resolutions. + This has to be improved. + + * doc/conf/queries.properties: Use point data to generate + "Horizontalschnitte". Added parameter id and date to results. + + * src/main/java/de/intevation/gnv/utils/WKTUtils.java: Made + reading to points more fault tolerant. + + * src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java: + Call the area interpolation. + + * src/main/java/de/intevation/gnv/math/AreaInterpolation.java: + Fixed bug with calculating points inside bounding box of polygon. + 2010-01-17 Sascha L. Teichmann * src/main/java/de/intevation/gnv/state/State.java: Added diff -r 20dde2b6f1b5 -r 64e65daa65e9 gnv-artifacts/doc/conf/conf.xml --- a/gnv-artifacts/doc/conf/conf.xml Sun Jan 17 16:34:11 2010 +0000 +++ b/gnv-artifacts/doc/conf/conf.xml Sun Jan 17 21:26:21 2010 +0000 @@ -420,7 +420,7 @@ - + diff -r 20dde2b6f1b5 -r 64e65daa65e9 gnv-artifacts/doc/conf/queries.properties --- a/gnv-artifacts/doc/conf/queries.properties Sun Jan 17 16:34:11 2010 +0000 +++ b/gnv-artifacts/doc/conf/queries.properties Sun Jan 17 21:26:21 2010 +0000 @@ -1085,26 +1085,28 @@ horizontalcrosssection_mesh_data = SELECT ST_ASTEXT(SHAPE), \ MSV.DATAVALUE YORDINATE, \ - MEDIAN.MESHFACE.JPOSITION, \ - MEDIAN.MESHFACE.IPOSITION, \ - MEDIAN.MESHFACE.KPOSITION, \ + MEDIAN.MESHPOINT.JPOSITION, \ + MEDIAN.MESHPOINT.IPOSITION, \ + MEDIAN.MESHPOINT.KPOSITION, \ + MSV.PARAMETERID, \ + MSV.TIMEVALUE, \ 2 DATAID \ from MEDIAN.MESHLAYER ML, \ - MEDIAN.MESHFACE, \ + MEDIAN.MESHPOINT, \ MEDIAN.MESH M, \ MEDIAN.MESHSCALARVALUE MSV \ - where MSV.FEATUREID = MEDIAN.MESHFACE.FEATUREID AND \ - ML.KPOSITION = MEDIAN.MESHFACE.KPOSITION and \ - ML.MESHID = MEDIAN.MESHFACE.MESHID and \ - M.MESHID = MEDIAN.MESHFACE.MESHID AND \ + where MSV.FEATUREID = MEDIAN.MESHPOINT.FEATUREID AND \ + ML.KPOSITION = MEDIAN.MESHPOINT.KPOSITION and \ + ML.MESHID = MEDIAN.MESHPOINT.MESHID and \ + M.MESHID = MEDIAN.MESHPOINT.MESHID AND \ M.PARTIDMIN <= MSV.PARTID AND \ M.PARTIDMAX >= MSV.PARTID AND \ MSV.PARAMETERID = ? AND \ MSV.TIMEVALUE = ? AND \ M.OBJECTID = ? AND \ - MEDIAN.MESHFACE.KPOSITION = ? \ - order by MEDIAN.MESHFACE.JPOSITION, \ - MEDIAN.MESHFACE.IPOSITION + MEDIAN.MESHPOINT.KPOSITION = ? \ + order by MEDIAN.MESHPOINT.JPOSITION, \ + MEDIAN.MESHPOINT.IPOSITION horizontalcrosssection_mesh_odv_data = SELECT SI.NAME CRUISE, \ M.MESHID || '-' || MEDIAN.MESHPOINT.IPOSITION || '-' || MEDIAN.MESHPOINT.JPOSITION STATION, \ '*' TYPE, \ diff -r 20dde2b6f1b5 -r 64e65daa65e9 gnv-artifacts/src/main/java/de/intevation/gnv/math/AreaInterpolation.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/AreaInterpolation.java Sun Jan 17 16:34:11 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/AreaInterpolation.java Sun Jan 17 21:26:21 2010 +0000 @@ -49,7 +49,12 @@ Dimension samples, XYDepth depth ) { + boolean debug = log.isDebugEnabled(); + if (points == null || points.isEmpty()) { + if (debug) { + log.debug("no points to interpolate"); + } return false; } @@ -70,6 +75,17 @@ double cellWidth = boundingBox.getWidth() / W; double cellHeight = boundingBox.getHeight() / H; + if (debug) { + 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); + } + Envelope queryBuffer = new Envelope(); Point2d [] neighbors = new Point2d[4]; Coordinate center = new Coordinate(); @@ -78,10 +94,13 @@ double [] raster = new double[W*H]; Arrays.fill(raster, Double.NaN); + double minX = boundingBox.getMinX(); + double minY = boundingBox.getMinY(); + int row = 0; for (int j = 0; j < H; ++j, row += W) { - double y = j*cellHeight + 0.5d*cellHeight; - double x = 0.5d*cellWidth; + double y = j*cellHeight + 0.5d*cellHeight + minY; + double x = 0.5d*cellWidth + minX; for (int i = 0; i < W; ++i, x += cellWidth) { queryBuffer.init( x - dxMax, x + dxMax, @@ -89,7 +108,7 @@ List potential = spatialIndex.query(queryBuffer); - if (potential.isEmpty()) { + if (potential.size() < 4) { continue; } diff -r 20dde2b6f1b5 -r 64e65daa65e9 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 Sun Jan 17 16:34:11 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java Sun Jan 17 21:26:21 2010 +0000 @@ -24,7 +24,10 @@ import de.intevation.gnv.geobackend.sde.datasources.RasterObject; +import de.intevation.gnv.math.AreaInterpolation; import de.intevation.gnv.math.AttributedPoint2ds; +import de.intevation.gnv.math.Point2d; +import de.intevation.gnv.math.QueriedXYDepth; import de.intevation.gnv.state.InputData; import de.intevation.gnv.state.OutputStateBase; @@ -37,11 +40,15 @@ import de.intevation.gnv.utils.StringUtils; import de.intevation.gnv.utils.WKTUtils; +import java.awt.Dimension; + import java.io.File; import java.io.IOException; import java.io.OutputStream; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; import org.apache.log4j.Logger; @@ -324,7 +331,8 @@ preprocess( queryExecutor.executeQuery( queryID, - addedFilterValues))); + addedFilterValues)), + getGroundInterpolation(callContext)); } catch (QueryException e) { log.error(e,e); @@ -343,29 +351,99 @@ AttributedPoint2ds ap2ds = new AttributedPoint2ds(); - boolean first = true; + ArrayList points = new ArrayList(results.size()); + + int sIdx = -1; + int iIdx = -1; + int jIdx = -1; + int vIdx = -1; + int kIdx = -1; + + boolean firstWarn = true; for (Result result: results) { - if (debug && first) { - first = false; + if (sIdx == -1) { ResultDescriptor rd = result.getResultDescriptor(); - log.debug(rd); + sIdx = rd.getColumnIndex("SHAPE"); + iIdx = rd.getColumnIndex("IPOSITION"); + jIdx = rd.getColumnIndex("JPOSITION"); + kIdx = rd.getColumnIndex("KPOSITION"); + vIdx = rd.getColumnIndex("YORDINATE"); + int tIdx = rd.getColumnIndex("TIMEVALUE"); + int pIdx = rd.getColumnIndex("PARAMETERID"); + + if (sIdx == -1 || iIdx == -1 + || jIdx == -1 || kIdx == -1 + || vIdx == -1 || tIdx == -1 + || pIdx == -1 + ) { + log.error("missing column in result set"); + return null; + } + + ap2ds.setAttribute("date", result.getDate(tIdx)); + ap2ds.setAttribute("parameter", result.getInteger(pIdx)); } + Coordinate coord = WKTUtils.toCoordinate(result.getString(sIdx)); + if (coord == null) { + if (firstWarn) { + firstWarn = false; + log.warn("cannot fetch coordinate from result"); + } + continue; + } + double v = result.getDouble(vIdx); + int i = result.getInteger(iIdx); + int j = result.getInteger(jIdx); + + Point2d p2d = new Point2d(coord.x, coord.y, v, i, j); + points.add(p2d); + } - - // TODO: do the interpolation + ap2ds.setPoints(points); return ap2ds; } public AttributedPoint2ds process( - Envelope env, + Envelope boundingBox, Polygon polygon, int numSamples, - AttributedPoint2ds input + AttributedPoint2ds input, + int groundInterpolation ) { - return input; + if (input == null) { + log.error("no data to interpolate"); + return null; + } + + boolean debug = log.isDebugEnabled(); + + if (debug) { + log.debug("before interpolation"); + } + + AreaInterpolation interpolation = + new AreaInterpolation(); + + List points = input.getPoints(); + + if (!interpolation.interpolate( + points, + boundingBox, + new Dimension(numSamples, numSamples), + new QueriedXYDepth(groundInterpolation) + )) { + log.error("interpolation failed"); + return null; + } + + if (debug) { + log.debug("after interpolation"); + } + + return null; } diff -r 20dde2b6f1b5 -r 64e65daa65e9 gnv-artifacts/src/main/java/de/intevation/gnv/utils/WKTUtils.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/WKTUtils.java Sun Jan 17 16:34:11 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/WKTUtils.java Sun Jan 17 21:26:21 2010 +0000 @@ -60,7 +60,9 @@ public static Coordinate toCoordinate(String shape) { try { - return ((Point)(new WKTReader().read(shape))).getCoordinate(); + return shape != null + ? ((Point)(new WKTReader().read(shape))).getCoordinate() + : null; } catch (ParseException pe) { log.error(pe);