|
interpolated data in convex part of a contourLayer map |
| Posted by quentin debray on Mar-10-2026 22:14 |
|
Hello,
I'm using the contourLayer feature of the 7.0.7 version and while using this simple code (below), my maps are filled in concave areas where they should not be. I tried the Chart.NoValue method but it did not change a thing.
Attached what I get with the undesired part in black.
XYChart c = new XYChart(600, 500);
// Set the plotarea at (30, 25) and of size 300 x 300 pixels. Use semi-transparent black
// (c0000000) for both horizontal and vertical grid lines
c.setPlotArea(75, 40, 400, 400);
// Add a contour layer using the given data
double[] rawData = comparisonResults.get(consideredItem).get(2);
for (int i = 0; i < rawData.length; i++) {
if (Double.isNaN(rawData[i])) {
rawData[i] = Chart.NoValue;
}
}
double[] dataX = referenceCurve.getAxisValues().get(0);
double[] dataY = referenceCurve.getAxisValues().get(1);
// // Add a scatter layer to the chart to show the position of the data points
// ArrayList<double[]> errorPositions = comparisonResultsErrorCoordinates.get(consideredItem);
// for (double[] position : errorPositions) {
// c.addScatterLayer(new double[]{position[0]}, new double[]{position[1]}, "", Chart.Cross2Shape(0.3), 11, 0xDD0000);
// }
// Add a contour layer using the given data
ContourLayer layer = c.addContourLayer(dataX, dataY, rawData);
layer.setZBounds(MathToolBox.min(rawData), MathToolBox.max(rawData));
c.xAxis().setTitle(referenceCurve.getAxisName().get(0) + " (" + referenceCurve.getAxisUnit().get(0) + ")");
c.yAxis().setTitle(referenceCurve.getAxisName().get(1) + " (" + referenceCurve.getAxisUnit().get(1) + ")");
c.addTitle(comparisonlabels.get(consideredItem).get(0) + "(" + comparisonlabels.get(consideredItem).get(1) + ") - diff");
// Add a color axis (the legend) in which the top left corner is anchored at (505, 40). Set
// the length to 400 pixels and the labels on the right side.
layer.setColorAxis(505, 40, Chart.TopLeft, 400, Chart.Right);
BufferedImage bi;
try {
bi = (BufferedImage) c.makeImage();
} catch (OutOfMemoryError e) {
FluxMotorLogger.logDebug(e.getMessage());
bi = new BufferedImage(600, 400, BufferedImage.TYPE_INT_ARGB);
}
File outputFile = new File(pathForImage + SystemToolBox.PATH_SEPARATOR + "figure" + chartNumber + "diff.png");
ImageIO.write(bi, "png", outputFile);
|
Re: interpolated data in convex part of a contourLayer map |
| Posted by Peter Kwan on Mar-11-2026 04:53 |
|
Hi Quentin Debray,
I remembered I had seen a similar case before. See the "Strom" chart image below.
The chart is achieved by setting the color axis to only the required range (0 to 30 for your case), and then set the overflow and underflow color to Chart.Transparent. It is like:
// layer = ContourLayer object
layer.colorAxis().setLinearScale(0, 30, 2);
l
// default colors; transparent if outside of color axis range
layer.colorAxis().setColorGradient(false, null, Chart.Transparent, Chart.Transparent);
Below the "Strom" chart, I have attached another image to show 3 shapes. The 3 shapes have exactly the same data points, but the points are joined differently. This shows the boundary is not uniquely defined. ChartDirector uses the "convex hull" method, which is the biggest possible polygon using some or all of the points as the vertices. The convex hull is well-defined and is commonly used in charts related to geographic locations.
For your case, the surface is not related to geometric locations, so the boundary may not be what you expect. Removing a point by Chart.NoValue may not change the convex hull. if you know the upper/lower bounds of the data, you can use the setColorGradient method to set the unwanted region to transparent.
Best Regards
Peter Kwan
|
|