MeteoInfo-Java解析與繪圖教程(六)
阿新 • • 發佈:2021-11-18
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,而我們繪製的時候最舒服的方法還是克里金插值,如果可以的話,可以根據原理自己封裝一個
圖片展示:
簡單的繪製基本上都結束了,我也在不停的研究,有新東西我會公佈出來,如果大家也有想法可以私聊我來交流一下,讓我們對氣象開發更加簡單舒服