mirror of
https://github.com/meteoinfo/MeteoInfo.git
synced 2025-12-08 20:36:05 +00:00
bugfix for Polygon toGeometry method related to issue #26
This commit is contained in:
parent
6c67a980c1
commit
8627374c9a
@ -91,7 +91,7 @@ public class GLPlot extends Plot {
|
||||
protected boolean clipPlane = true;
|
||||
protected boolean axesZoom = false;
|
||||
|
||||
protected Color boxColor = Color.getHSBColor(0f, 0f, 0.95f);
|
||||
protected Color boxColor = Color.lightGray;
|
||||
|
||||
protected boolean boxed, mesh, scaleBox, displayXY, displayZ,
|
||||
drawBoundingBox, hideOnDrag, drawBase;
|
||||
|
||||
81
meteoinfo-geo/src/test/java/ClipTest.java
Normal file
81
meteoinfo-geo/src/test/java/ClipTest.java
Normal file
@ -0,0 +1,81 @@
|
||||
import org.meteoinfo.data.GridData;
|
||||
import org.meteoinfo.data.meteodata.MeteoDataInfo;
|
||||
import org.meteoinfo.geo.layer.VectorLayer;
|
||||
import org.meteoinfo.geo.legend.LegendManage;
|
||||
import org.meteoinfo.geo.mapdata.MapDataManage;
|
||||
import org.meteoinfo.geo.meteodata.DrawMeteoData;
|
||||
import org.meteoinfo.geometry.legend.LegendScheme;
|
||||
import org.meteoinfo.geometry.legend.PolygonBreak;
|
||||
import org.meteoinfo.geometry.shape.ShapeTypes;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class ClipTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
new ClipTest().run();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void run() throws Exception {
|
||||
//绘制色斑图
|
||||
String fileFullName = "D:\\Temp\\test\\2022042720.120";
|
||||
MeteoDataInfo meteoDataInfo = new MeteoDataInfo();
|
||||
meteoDataInfo.openMICAPSData(fileFullName);
|
||||
GridData grid = meteoDataInfo.getGridData();
|
||||
|
||||
//创建图例 如把 5 设置成6及以上则不会报错,GridData最小与最大分别为 7.6 21.3
|
||||
double[] values = new double[]{
|
||||
5,
|
||||
7,
|
||||
9,
|
||||
11,
|
||||
13,
|
||||
15,
|
||||
17};
|
||||
Color[] colors = new Color[]{
|
||||
Color.cyan,
|
||||
Color.white,
|
||||
Color.blue,
|
||||
Color.green,
|
||||
Color.yellow,
|
||||
Color.red,
|
||||
Color.orange,
|
||||
Color.gray};
|
||||
|
||||
double minData = 0;
|
||||
double maxData = 0;
|
||||
double[] maxMin = new double[2];
|
||||
if (!grid.getMaxMinValue(maxMin)) {
|
||||
maxData = maxMin[0];
|
||||
minData = maxMin[1];
|
||||
}
|
||||
if (values[0] < minData) {
|
||||
minData = values[0];
|
||||
}
|
||||
if (values[values.length - 1] > maxData) {
|
||||
maxData = values[values.length - 1];
|
||||
}
|
||||
|
||||
//渐变值
|
||||
LegendScheme aLS = LegendManage.createGraduatedLegendScheme(values, colors,
|
||||
ShapeTypes.POLYGON, minData, maxData, false, grid.getDoubleMissingValue());
|
||||
//绘制图层
|
||||
VectorLayer layer = DrawMeteoData.createShadedLayer(grid, aLS, "Shaded_var", "var", true);
|
||||
|
||||
//对绘制的图层进行裁剪
|
||||
VectorLayer clipShp = MapDataManage.readMapFile_ShapeFile("D:\\Temp\\test\\taizhou.shp");
|
||||
|
||||
PolygonBreak pb = (PolygonBreak) clipShp.getLegendScheme().getLegendBreak(0);
|
||||
pb.setDrawFill(false);
|
||||
pb.setDrawOutline(true);
|
||||
pb.setOutlineSize(1);
|
||||
pb.setOutlineColor(Color.gray);
|
||||
|
||||
VectorLayer newlayer = layer.clip(clipShp);
|
||||
//如果 vlaues设置的范围不一样会报异常,如果使用系统自生成的则正常。最小值小于等于5异常。
|
||||
}
|
||||
}
|
||||
@ -213,29 +213,22 @@ public class Polygon {
|
||||
p = _outLine.get(i);
|
||||
cs[i] = new Coordinate(p.X, p.Y);
|
||||
}
|
||||
if (cs[0].x != cs[cs.length -1].x){
|
||||
if (!cs[0].equals(cs[cs.length - 1])){
|
||||
cs = (Coordinate[])DataConvert.resizeArray(cs, cs.length + 1);
|
||||
cs[cs.length - 1] = new Coordinate(cs[0].x, cs[1].y);
|
||||
cs[cs.length - 1] = (Coordinate) cs[0].clone();
|
||||
}
|
||||
LinearRing shell = factory.createLinearRing(cs);
|
||||
LinearRing[] holes = new LinearRing[this._holeLines.size()];
|
||||
int n;
|
||||
boolean isclose;
|
||||
for (int j = 0; j < holes.length; j++) {
|
||||
List<? extends PointD> hole = this._holeLines.get(j);
|
||||
n = hole.size();
|
||||
isclose = true;
|
||||
if (n == 3) {
|
||||
n = 4;
|
||||
isclose = false;
|
||||
}
|
||||
cs = new Coordinate[n];
|
||||
cs = new Coordinate[hole.size()];
|
||||
for (int i = 0; i < hole.size(); i++) {
|
||||
p = hole.get(i);
|
||||
cs[i] = new Coordinate(p.X, p.Y);
|
||||
}
|
||||
if (!isclose){
|
||||
cs[n - 1] = new Coordinate(hole.get(0).X, hole.get(0).Y);
|
||||
if (!cs[0].equals(cs[cs.length - 1])){
|
||||
cs = (Coordinate[])DataConvert.resizeArray(cs, cs.length + 1);
|
||||
cs[cs.length - 1] = (Coordinate) cs[0].clone();
|
||||
}
|
||||
holes[j] = factory.createLinearRing(cs);
|
||||
}
|
||||
|
||||
@ -1,11 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<MeteoInfo File="milconfig.xml" Type="configurefile">
|
||||
<Path OpenPath="D:\Working\MIScript\Jython\mis\traj">
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\awx"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\burf"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\radar"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\projection"/>
|
||||
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\mesh">
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\savefig"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\linalg"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math"/>
|
||||
@ -13,24 +8,25 @@
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\interpolate"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\LaSW\airship"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\dataconvert"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\traj"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\plot"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\mesh"/>
|
||||
</Path>
|
||||
<File>
|
||||
<OpenedFiles>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\LaSW\airship\sounding.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\LaSW\airship\radar_bz2.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\dataconvert\wrfout2arl_2.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\dataconvert\test_arl.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\dataconvert\test.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\mesh\mesh_peaks.py"/>
|
||||
</OpenedFiles>
|
||||
<RecentFiles>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\LaSW\airship\sounding.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\LaSW\airship\radar_bz2.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\io\dataconvert\wrfout2arl_2.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\io\dataconvert\test_arl.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\io\dataconvert\test.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\mesh\mesh_peaks.py"/>
|
||||
</RecentFiles>
|
||||
</File>
|
||||
<Font>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user