fix UniqueValue legend creating bug

This commit is contained in:
wyq 2021-09-30 21:33:18 +08:00
parent 65823b5f03
commit f0f6d8ac67
4 changed files with 31 additions and 13 deletions

View File

@ -21,9 +21,11 @@ import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.swing.JOptionPane;
import org.meteoinfo.common.Extent;
@ -508,6 +510,9 @@ public class GridArray {
int vdNum = 0;
for (int i = 0; i < getYNum(); i++) {
for (int j = 0; j < getXNum(); j++) {
if (Double.isNaN(this.getValue(i, j).doubleValue())) {
continue;
}
if (MIMath.doubleEquals(this.getValue(i, j).doubleValue(), missingValue)) {
continue;
}
@ -520,6 +525,7 @@ public class GridArray {
vdNum += 1;
}
}
values = values.stream().sorted().collect(Collectors.toList());
return values;
}

View File

@ -21,6 +21,7 @@ import org.meteoinfo.common.MIMath;
import org.meteoinfo.common.util.GlobalUtil;
import org.meteoinfo.data.GridArray;
import org.meteoinfo.geometry.legend.LegendScheme;
import org.meteoinfo.geometry.legend.LegendType;
import org.meteoinfo.geometry.shape.ShapeTypes;
import java.awt.Color;
import java.awt.RenderingHints;
@ -255,15 +256,20 @@ public class RasterLayer extends ImageLayer {
color = undefColor;
} else {
idx = Arrays.binarySearch(values, value);
if (idx < 0) {
if (idx == -1)
idx = 0;
else if (idx == -n - 1)
idx = n - 1;
else
idx = -idx - 2;
} else if (idx == n - 1)
idx = n - 2;
if (als.getLegendType() == LegendType.UNIQUE_VALUE) {
if (idx < 0 || idx >= n)
color = undefColor;
} else {
if (idx < 0) {
if (idx == -1)
idx = 0;
else if (idx == -n - 1)
idx = n - 1;
else
idx = -idx - 2;
} else if (idx == n - 1)
idx = n - 2;
}
color = als.getLegendBreak(idx).getColor();
}

View File

@ -499,8 +499,12 @@ package org.meteoinfo.geometry.legend;
cb = legendBreaks.get(i);
if (!cb.isNoData()) {
if (values.isEmpty()) {
values.add(Double.parseDouble(cb.getStartValue().toString()));
values.add(Double.parseDouble(cb.getEndValue().toString()));
if (this.legendType == LegendType.UNIQUE_VALUE)
values.add(Double.parseDouble(cb.getEndValue().toString()));
else {
values.add(Double.parseDouble(cb.getStartValue().toString()));
values.add(Double.parseDouble(cb.getEndValue().toString()));
}
} else {
values.add(Double.parseDouble(cb.getEndValue().toString()));
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MeteoInfo File="milconfig.xml" Type="configurefile">
<Path OpenPath="D:\Working\MIScript\Jython\mis\toolbox\verification">
<Path OpenPath="D:\Working\MIScript\Jython\mis\micaps">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\toolbox\miml\model_selection"/>
@ -11,22 +11,24 @@
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\chart\subplot"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\micaps"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\toolbox\miml"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\toolbox"/>
<RecentFolder Folder="D:\Temp\test\ymy"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\toolbox\verification"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\micaps"/>
</Path>
<File>
<OpenedFiles>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf_sombrero.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\toolbox\miml\deep_learning\classification\saturn.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\chart\subplot\subplots_sharexy_text.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\micaps\micaps_4_6-1.py"/>
</OpenedFiles>
<RecentFiles>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf_sombrero.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\toolbox\miml\deep_learning\classification\saturn.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\chart\subplot\subplots_sharexy_text.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\micaps\micaps_4_6-1.py"/>
</RecentFiles>
</File>
<Font>