diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/GeoGraphicCollection.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/GeoGraphicCollection.java index 91c2b328..7bc40813 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/GeoGraphicCollection.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/GeoGraphicCollection.java @@ -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 valueList = new ArrayList<>(); + boolean isDateField = false; + DataType colType = this.getAttributeTable().getTable().getColumns().get(fieldName).getDataType(); + if (colType == DataType.DATE) { + isDateField = true; + } + + List 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)); + } + } diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/GraphicFactory.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/GraphicFactory.java index e6b28fdf..1e83a3f3 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/GraphicFactory.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/GraphicFactory.java @@ -3447,6 +3447,10 @@ public class GraphicFactory { * @return Image graphic */ public static Graphic createImage(Array data, Array xa, Array ya, LegendScheme ls, List extent) { + data = data.copyIfView(); + xa = xa.copyIfView(); + ya = ya.copyIfView(); + int width, height, breakNum; width = (int) xa.getSize(); height = (int) ya.getSize(); diff --git a/meteoinfo-common/src/main/java/org/meteoinfo/common/util/GlobalUtil.java b/meteoinfo-common/src/main/java/org/meteoinfo/common/util/GlobalUtil.java index 181590fd..9951cd38 100644 --- a/meteoinfo-common/src/main/java/org/meteoinfo/common/util/GlobalUtil.java +++ b/meteoinfo-common/src/main/java/org/meteoinfo/common/util/GlobalUtil.java @@ -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; } diff --git a/meteoinfo-lab/milconfig.xml b/meteoinfo-lab/milconfig.xml index 8e69cd5a..99c243de 100644 --- a/meteoinfo-lab/milconfig.xml +++ b/meteoinfo-lab/milconfig.xml @@ -1,7 +1,6 @@ - - + @@ -9,22 +8,27 @@ - - + + + + + + + diff --git a/meteoinfo-lab/pylib/mipylib/dataset/midata$py.class b/meteoinfo-lab/pylib/mipylib/dataset/midata$py.class index 71f44286..d44f1134 100644 Binary files a/meteoinfo-lab/pylib/mipylib/dataset/midata$py.class and b/meteoinfo-lab/pylib/mipylib/dataset/midata$py.class differ diff --git a/meteoinfo-lab/pylib/mipylib/dataset/midata.py b/meteoinfo-lab/pylib/mipylib/dataset/midata.py index c6621f27..fd5263ec 100644 --- a/meteoinfo-lab/pylib/mipylib/dataset/midata.py +++ b/meteoinfo-lab/pylib/mipylib/dataset/midata.py @@ -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) diff --git a/meteoinfo-lab/pylib/mipylib/geolib/_graphic.py b/meteoinfo-lab/pylib/mipylib/geolib/_graphic.py index ba6fb394..f46c3644 100644 --- a/meteoinfo-lab/pylib/mipylib/geolib/_graphic.py +++ b/meteoinfo-lab/pylib/mipylib/geolib/_graphic.py @@ -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() diff --git a/meteoinfo-render2d/pom.xml b/meteoinfo-render2d/pom.xml index 59ceb03b..8b6a54da 100644 --- a/meteoinfo-render2d/pom.xml +++ b/meteoinfo-render2d/pom.xml @@ -40,4 +40,27 @@ + + + + true + org.apache.maven.plugins + maven-javadoc-plugin + 3.3.1 + + + attach-javadocs + + jar + + + false + false + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index e886e760..a1923389 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ UTF-8 1.8 - 3.8 + 3.8.1 8 8 8