bugfix for imshow function of view data array

This commit is contained in:
wyq 2024-03-13 09:12:03 +08:00
parent f7a6a83413
commit 1756071468
9 changed files with 187 additions and 13 deletions

View File

@ -6,16 +6,21 @@ import org.meteoinfo.common.MIMath;
import org.meteoinfo.common.PointD;
import org.meteoinfo.geometry.graphic.Graphic;
import org.meteoinfo.geometry.graphic.GraphicCollection;
import org.meteoinfo.geometry.legend.ColorBreak;
import org.meteoinfo.geometry.legend.LabelBreak;
import org.meteoinfo.geometry.legend.LegendType;
import org.meteoinfo.geometry.legend.*;
import org.meteoinfo.geometry.shape.PointShape;
import org.meteoinfo.geometry.shape.PolylineShape;
import org.meteoinfo.geometry.shape.Shape;
import org.meteoinfo.geometry.shape.ShapeTypes;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.projection.ProjectionInfo;
import org.meteoinfo.table.AttributeTable;
import org.meteoinfo.table.Field;
import javax.swing.*;
import java.awt.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
public class GeoGraphicCollection extends GraphicCollection {
@ -181,4 +186,124 @@ public class GeoGraphicCollection extends GraphicCollection {
}
}
/**
* Create legend scheme
*
* @param aLT Legend type
* @param fieldName Field name
* @return Legend scheme
*/
public LegendScheme createLegendScheme(LegendType aLT, String fieldName) {
double min, max;
ShapeTypes aST = this.getShapeType();
LegendScheme aLS = new LegendScheme(this.getShapeType());
min = aLS.getMinValue();
max = aLS.getMaxValue();
switch (aLT) {
case SINGLE_SYMBOL:
Color aColor = Color.black;
float size = 1.0F;
switch (aST) {
case POINT:
case POINT_M:
case POINT_Z:
aColor = Color.black;
size = 5;
break;
case POLYLINE:
case POLYLINE_M:
case POLYLINE_Z:
aColor = Color.black;
break;
case POLYGON:
case POLYGON_M:
case POLYGON_Z:
case IMAGE:
aColor = new Color(255, 251, 195);
break;
}
aLS = LegendManage.createSingleSymbolLegendScheme(aST, aColor, size);
break;
case UNIQUE_VALUE:
Color[] colors;
List<String> valueList = new ArrayList<>();
boolean isDateField = false;
DataType colType = this.getAttributeTable().getTable().getColumns().get(fieldName).getDataType();
if (colType == DataType.DATE) {
isDateField = true;
}
List<String> captions = new ArrayList<>();
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy/M/d");
for (int i = 0; i < this.getAttributeTable().getTable().getRows().size(); i++) {
Object value = this.getAttributeTable().getTable().getRows().get(i).getValue(fieldName);
if (!valueList.contains(value.toString())) {
valueList.add(value.toString());
if (isDateField) {
captions.add(format.format((LocalDateTime) value));
}
}
}
if (valueList.size() <= 13) {
colors = LegendManage.createRainBowColors(valueList.size());
} else {
colors = LegendManage.createRandomColors(valueList.size());
}
Color[] newcolors = new Color[colors.length + 1];
newcolors[0] = Color.white;
for (int i = 1; i < newcolors.length; i++) {
newcolors[i] = colors[i - 1];
}
if (isDateField) {
aLS = LegendManage.createUniqValueLegendScheme(valueList, captions, newcolors, aST, min,
max, aLS.getHasNoData(), aLS.getUndefValue());
} else {
aLS = LegendManage.createUniqValueLegendScheme(valueList, newcolors,
aST, min, max, aLS.getHasNoData(), aLS.getUndefValue());
}
aLS.setFieldName(fieldName);
break;
case GRADUATED_COLOR:
double[] S = new double[this.getAttributeTable().getTable().getRows().size()];
for (int i = 0; i < S.length; i++) {
S[i] = Double.parseDouble(this.getAttributeTable().getTable().getRows().get(i).getValue(fieldName).toString());
}
double[] minmax = MIMath.getMinMaxValue(S, aLS.getUndefValue());
min = minmax[0];
max = minmax[1];
if (min == max) {
JOptionPane.showMessageDialog(null, "The values of all shapes are same!");
break;
}
double[] CValues;
CValues = MIMath.getIntervalValues(min, max);
colors = LegendManage.createRainBowColors(CValues.length + 1);
aLS = LegendManage.createGraduatedLegendScheme(CValues, colors,
aST, min, max, aLS.getHasNoData(), aLS.getUndefValue());
aLS.setFieldName(fieldName);
break;
}
return aLS;
}
/**
* Update legend scheme
*
* @param aLT Legend type
* @param fieldName Field name
*/
public void updateLegendScheme(LegendType aLT, String fieldName) {
this.setLegendScheme(createLegendScheme(aLT, fieldName));
}
}

View File

@ -3447,6 +3447,10 @@ public class GraphicFactory {
* @return Image graphic
*/
public static Graphic createImage(Array data, Array xa, Array ya, LegendScheme ls, List<Number> extent) {
data = data.copyIfView();
xa = xa.copyIfView();
ya = ya.copyIfView();
int width, height, breakNum;
width = (int) xa.getSize();
height = (int) ya.getSize();

View File

@ -67,7 +67,7 @@ import java.util.zip.ZipInputStream;
public static String getVersion(){
String version = GlobalUtil.class.getPackage().getImplementationVersion();
if (version == null || version.equals("")) {
version = "3.8";
version = "3.8.1";
}
return version;
}

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MeteoInfo File="milconfig.xml" Type="configurefile">
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\funny">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
<Path OpenPath="D:\Working\MIScript\Jython\mis\traj">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\3d_earth"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\json"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
@ -9,22 +8,27 @@
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\imshow"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite\FY"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo\calc"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\test"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\contour"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\funny"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\test"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\traj"/>
</Path>
<File>
<OpenedFiles>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\funny\flower_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\meteo\calc\frontogenesis.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\traj\hy_part_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\traj\plot_basic.py"/>
</OpenedFiles>
<RecentFiles>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\funny\flower_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\meteo\calc\frontogenesis.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\traj\hy_part_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\traj\plot_basic.py"/>
</RecentFiles>
</File>
<Font>

View File

@ -586,7 +586,7 @@ def binread(fn, dim, datatype=None, skip=0, byteorder='little_endian'):
:param dim: (*list*) Dimensions.
:param datatype: (*string*) Data type string [byte | short | int | float | double].
:param skip: (*int*) Skip bytes number.
:param byteorder: (*string*) Byte order. ``little_endian`` or ``big_endian``.
:param byteorder: (*string*) Byte order. `little_endian` or `big_endian`. Default is `little_endian`.
:returns: (*NDArray*) Data array
"""
@ -614,10 +614,10 @@ def binwrite(out, data, byteorder='little_endian', append=False, sequential=Fals
:param out: (*string or EndianDataOutputStream*) File path or data output stream.
:param data: (*array_like*) A numeric array variable of any dimensionality.
:param byteorder: (*string*) Byte order. ``little_endian`` or ``big_endian``.
:param append: (*boolean*) Append to an existing file or not. Only valid when ``out``
:param byteorder: (*string*) Byte order. `little_endian` or `big_endian`. Default is `little_endian`.
:param append: (*boolean*) Append to an existing file or not. Only valid when `out`
is file path.
:param sequential: (*boolean*) If write binary data as sequential - Fortran
:param sequential: (*boolean*) If write binary data as sequential - Fortran. Default is `False`.
"""
if isinstance(out, basestring):
ArrayUtil.saveBinFile(out, data.asarray(), byteorder, append, sequential)

View File

@ -81,3 +81,21 @@ class GeoGraphicCollection(object):
:param y: (*float*) Y shift for moving in pixel unit.
"""
self._geographic.moveLabel(label, x, y)
def update_legend(self, ltype, fieldname):
"""
Update legend scheme.
:param ltype: (*string*) Legend type [single | unique | graduate].
:param fieldname: (*string*) Field name.
"""
if ltype == 'single':
ltype = LegendType.SINGLE_SYMBOL
elif ltype == 'unique':
ltype = LegendType.UNIQUE_VALUE
elif ltyp == 'graduate':
ltype = LegendType.GRADUATED_COLOR
else:
raise ValueError(ltype)
self._geographic.updateLegendScheme(ltype, fieldname)
return self._geographic.getLegendScheme()

View File

@ -40,4 +40,27 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<failOnError>false</failOnError>
<failOnWarnings>false</failOnWarnings>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -35,7 +35,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<revision>3.8</revision>
<revision>3.8.1</revision>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.release>8</maven.compiler.release>