MeteoInfo-Java解析与绘图教程(六)
这一节主要说的是我们取到自动站的数据,如何通过插值,转化成格点数据,并绘制图层
//从数据库查询cimiss数据 List<Map<String,Object>> list = DBUtil.getMapList("SELECT * FROM mete_stationpar_data_2021 WHERE DataTime = '2021-01-01 12:00:00' AND TEM IS NOT NULL"); //创建站点格点 StationData stationData = new StationData(); //循环数据将值塞入格点中 for (Map<String, Object> item : list) { System.out.println(item); stationData.addData(String.valueOf(item.get("Station_Name")), Double.parseDouble(item.get("Lon").toString()), Double.parseDouble(item.get("Lat").toString()), Double.parseDouble(item.get("TEM").toString())); } //读取地图图层 VectorLayer altMap = MapDataManage.readMapFile_ShapeFile("C:\\Users\\Administrator\\Downloads\\阿勒泰地区\\阿勒泰地区.shp"); //创建网格设置参数 GridDataSetting gridDataSetting = new GridDataSetting(); //设定数据区域 gridDataSetting.dataExtent = altMap.getExtent(); //设定格点数 gridDataSetting.xNum = list.size(); gridDataSetting.yNum = list.size(); //创建插值设置 InterpolationSetting interpolationSetting = new InterpolationSetting(); //设定格点配置 interpolationSetting.setGridDataSetting(gridDataSetting); //设定插值方法 interpolationSetting.setInterpolationMethod(InterpolationMethods.IDW_Radius); //设定搜索半径 interpolationSetting.setRadius(10); //设置最小点数 interpolationSetting.setMinPointNum(1); //插值到格点 GridData gridData = stationData.interpolateData(interpolationSetting); LegendScheme als = LgsUtil.readFromLgs("D:\\apache-tomcat-8.0.50\\alt色阶\\color\\ECMWF_HR\\TMP.lgs"); //绘制图层 VectorLayer layer = DrawMeteoData.createShadedLayer(gridData,als,"","",true); //创建视图 MapView view = new MapView(); PolygonBreak pb = (PolygonBreak) altMap.getLegendScheme().getLegendBreak(0); pb.setDrawFill(false); pb.setOutlineColor(Color.GRAY); layer = layer.clip(altMap); //叠加图层 view.addLayer(layer); view.addLayer(altMap); /** * 通用方法,可以抽成工具类 */ MapLayout layout = new MapLayout(); //去除图形边框 layout.getActiveMapFrame().setDrawNeatLine(false); //区域边界 Extent extent = view.getExtent(); //设置矩形的宽和高 Rectangle bounds = new Rectangle(800, (int) (800 * 1D / extent.getWidth() * extent.getHeight())); //设置地图边框 layout.setPageBounds(new Rectangle(0, 0, bounds.width, bounds.height)); //设置页面边框 layout.getActiveMapFrame().setLayoutBounds(new Rectangle(0, 0, bounds.width, bounds.height)); layout.getActiveMapFrame().setMapView(view); layout.exportToPicture(PathUtil.getDeskPath()+"/1.png");
对于该方法主要有几个重点需要关注:
1.GridDataSetting 它是对矩阵做了布局设置
2.InterpolationSetting 它是对插值做了设置,InterpolationMethods就包含了几种插值法,但感觉效果最好的是IDW_Radius,而我们绘制的时候最舒服的方法还是克里金插值,如果可以的话,可以根据原理自己封装一个
图片展示:
简单的绘制基本上都结束了,我也在不停的研究,有新东西我会公布出来,如果大家也有想法可以私聊我来交流一下,让我们对气象开发更加简单舒服