- 积分
- 28
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2018-8-2
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
使用IDW插值方法出图正常
但是使用Cressman和AssignPointToGrid插值方法就出图有问题
代码是
MapLayout layout=new MapLayout();
//添加标题
if(title != null){
layout.addText(title, 200, 60, "宋体", 18);
}
//添加副标题
if(Subtitle != null){
layout.addText(Subtitle, 200, 80, "宋体", 14);
}
layout.setSize(2970, 2100);
layout.setBackground(new Color(255, 255, 255, 0));
MapFrame mapFrame=layout.getActiveMapFrame();
MapView mapView =mapFrame.getMapView();
mapView.setBackground(new Color(255, 255, 255, 0));
mapView.setBounds(0, 0, 1000, 1000);
//使用shp最方便了,这儿有一个坑,就是你是用的shp可以通过他自带的软件加载显示才行,否则程序会异常,至于为啥有的shp不能加载,我也没搞清楚
//反正这个坑让我趟过去了。
try {
//读取边界层
VectorLayer clipLayer = MapDataManage.readMapFile_ShapeFile(boundShapeFilePath);
//读取地图层
VectorLayer bgLayer = MapDataManage.readMapFile_ShapeFile(bgShapeFilePath);
//获取站点数据
StationData stationData = getStationData();
//
GridDataSetting gridDataSetting = new GridDataSetting();
gridDataSetting.dataExtent = clipLayer.getExtent();
stationData.projInfo = clipLayer.getProjInfo();
gridDataSetting.xNum = xNum;// 格点点数
gridDataSetting.yNum = yNum;// 格点点数
InterpolationSetting interSet = new InterpolationSetting();
interSet.setGridDataSetting(gridDataSetting);
if("IDW".equals(interpolationMethod)){
interSet.setInterpolationMethod(InterpolationMethods.IDW_Radius);
}else if("Cressman".equals(interpolationMethod)){
interSet.setInterpolationMethod(InterpolationMethods.Cressman);
}else if("AssignPointToGrid".equals(interpolationMethod)){
interSet.setInterpolationMethod(InterpolationMethods.AssignPointToGrid);
}else{
interSet.setInterpolationMethod(InterpolationMethods.IDW_Radius);
}
interSet.setRadius(5);
interSet.setMinPointNum(1);
GridData gridData = stationData.interpolateData(interSet);
//剔除无效值
gridData.missingValue = undefData;
double[] maxmin = new double[2];
boolean hasUndef = gridData.getMaxMinValue(maxmin);
LegendScheme legendScheme = LegendManage.createUniqValueLegendScheme(CValues, colors,
ShapeTypes.Polyline, gridData.getMinValue(), gridData.getMaxValue(), hasUndef, gridData.missingValue);
VectorLayer contourLayer = null;
if(type.equals("Shaded")){
//生成色斑图
contourLayer = DrawMeteoData.createShadedLayer(gridData, legendScheme, "ContourLayer", "data",true);
}else if(type.equals("Contour")){
//生成等值线
if(types != null){
for (int i = 0; i < types.length; i++) {
PolylineBreak pb = (PolylineBreak)legendScheme.getLegendBreak(i);
pb.setSize(types);
}
}
contourLayer = DrawMeteoData.createContourLayer(gridData, legendScheme, "ContourLayer", "data",true);
}
VectorLayer lastLayer = contourLayer.clip(clipLayer);
lastLayer.setProjInfo(clipLayer.getProjInfo());
if(type.equals("Contour")){
//显示等值线的值
LabelSet lls = lastLayer.getLabelSet();
lls.setFieldName("data");
lls.setAvoidCollision(true);
lastLayer.addLabels();
}else{
//透明度
lastLayer.setTransparency(50);
}
mapView.addLayer(bgLayer);
mapView.addLayer(lastLayer);
mapView.setGridXDelt(1);
mapView.setGridYDelt(1);
bgLayer.setTransparency(100);
//显示地图的文字,如市名
LabelSet ls = bgLayer.getLabelSet();
ls.setFieldName(bgShapeLableName);
ls.setAvoidCollision(true);
ls.setLabelFont(new Font("宋体", Font.PLAIN, 12));
//设置LabelSet后,必须要addLabels才能起作用
bgLayer.addLabels();
if(type.equals("Shaded")){
//生成图例
LayoutLegend legend = layout.addLegend(60, 240);
legend.setLegendStyle(LegendStyles.Normal);
legend.setLegendLayer(lastLayer);
legend.setFont(new Font("宋体", Font.PLAIN, 12));
legend.setTitle(legendTitle);
}
layout.exportToPicture(exportPath);
|
|