這些年做項目的時候,碰到等值面基本都是arcgis server來支撐的,通過構建GP服務,一般的都能滿足做等值線和等值面的需求。可是突然有一天,我發現如果沒有arcgis server 的話,我既然沒法生成等值面等值線了。況且,還有許多別的要求:
-
沒有arcgis server支持,arcgis server畢竟是很大一筆開銷,個人基本無法負擔;
-
跨平台,有的服務器是linux,有的是windows,看來,只能是java的類庫了;
-
免費,生成等值線和等值面的程序不能有費用;
-
輸出多種格式,既能輸出圖片格式,又能輸出矢量格式,尤其是 kml之類的矢量數據;
在氣象家園http://bbs.06climate.com/找到一個很不錯的解決方案,MeteoInfo,作者是一個很厲害的人,具體的不說了,大家可以去看他的網站和博客,下面我說說如何使用他的類庫來進行等值面的生成。如果大家有很好的類似的庫,歡迎推薦給我,謝謝。
1:引用他的項目中的lib目錄中的jar包,生成窗口對象:
1 MapView mapView = new MapView(); 2 mapView.setBackground(new Color(255, 255, 255, 0)); 3 mapView.setBounds(0, 0, 200, 200); 4 VectorLayer clipLayer = MapDataManage.readMapFile_ShapeFile(“d:/chengdu.shp”); //剪切圖層,就是生成等值面的形狀范圍,//使用shp最方便了,這兒有一個坑,就是你是用的shp可以通過他自帶的軟件加載顯示才行,否則程序會異常,至於為啥有的shp不能加載,我也沒搞清楚//反正這個坑讓我趟過去了。2:添加站點信息,用於插值
1 StationData stationData = new StationData(); 2 // 3 for(int i=0;i<10;i++) 4 { 5 stationData.addData("st"+i, 114+0.1*i, 35+0.1*i, i*10); //站點名稱,經度,維度,值 6 }
3:設定插值參數
1 GridDataSetting gridDataSetting = new GridDataSetting(); 2 gridDataSetting.dataExtent = clipLayer.getExtent(); 3 stationData.projInfo = clipLayer.getProjInfo(); 4 gridDataSetting.xNum = contourconfig.getGridx();// 格點點數 5 gridDataSetting.yNum = contourconfig.getGridy();// 格點點數 6 7 InterpolationSetting interSet = new InterpolationSetting(); 8 9 interSet.setGridDataSetting(gridDataSetting); 10 interSet.setInterpolationMethod(InterpolationMethods.IDW_Radius); 11 interSet.setRadius(5); 12 interSet.setMinPointNum(1); 13 GridData gridData = stationData.interpolateData(interSet); 14 15 LegendScheme legendScheme =LegendManage.createLegendSchemeFromGridData(gridData, LegendType.UniqueValue,ShapeTypes.Polygon);
4:插值生成圖層:1 VectorLayer contourLayer = DrawMeteoData.createShadedLayer(gridData, legendScheme, "ContourLayer", "Data", 2 true); 3 VectorLayer lastLayer = contourLayer.clip(clipLayer); 4 mapView.addLayer(lastLayer);
5:導出數據,可以是kml或者png之類的圖片格式
1 mapView.exportToPicture(“d:/ddd.png”); //地圖導出為圖片 2 //地圖導出為kml 3 lastLayer.saveAsKMLFile(“d:/ddd.kml”);
這是使用這個做出的效果圖之一:
瀏覽數據秀(dataxiu.com)網站,了解更多數據可視化方法技術。

