爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 2842|回复: 3

MeteoInfo Java版二次开发教程七

[复制链接]

新浪微博达人勋

发表于 2013-11-4 09:37:21 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
此次教程实现站点数据来生成各种图层,主要包括Station Point(站点)、Station Model(站点填图)、Weather Symbol(天气现象符号)、 Station Vector(站点风场矢量)、Station Shaded(站点数据插值成格点数据再生成等值线填色图层)。
用DrawMeteoData类的一些静态方法来创建各种图层:
Station_Point:  DrawMeteoData.createSTPointLayer(StationData stationData, LegendScheme aLS, String lName, String        fieldName)
Station_Model:  DrawMeteoData.createStationModelLayer(StationModelData   stationModelData, LegendScheme aLS, String       layerName, boolean isSurface)
Weather_Symbol:  DrawMeteoData.createWeatherSymbolLayer(StationData   weatherData, String WeatherType, String       layerName)
Station_Vector:  DrawMeteoData.createSTVectorLayer(StationData uData, StationData  vData, StationData stData, LegendScheme  aLS, String layerName, boolean isUV)
创建好菜单后,具体的代码如下:

  1.     private void jMenuItem_StationPointActionPerformed(java.awt.event.ActionEvent evt) {                                                      
  2.         // TODO add your handling code here:      
  3.         //Create a MeteoDataInfo object
  4.         MeteoDataInfo aDataInfo = new MeteoDataInfo();

  5.         //Open MICAPS data file
  6.         String dataDir = "E:\\MeteoInfo\\sample\\MICAPS\\";
  7.         String fileName = dataDir + "10101414.000";
  8.         aDataInfo.openMICAPSData(fileName);

  9.         //Get StationData
  10.         StationData visData = aDataInfo.getStationData("Visibility");

  11.         //Create a legend scheme
  12.         LegendScheme aLS = LegendManage.createLegendSchemeFromStationData(visData, LegendType.GraduatedColor, ShapeTypes.Point);

  13.         for (int i = 0; i < aLS.getBreakNum(); i++) {
  14.             PointBreak pointBreak = (PointBreak) aLS.getLegendBreaks().get(i);            
  15.             pointBreak.setSize(8);
  16.         }
  17.         //Create a contour layer
  18.         VectorLayer aLayer = DrawMeteoData.createSTPointLayer(visData, aLS, "StationPoint_Vis", "Vis");

  19.         //Add layer
  20.         layersLegend1.getActiveMapFrame().addLayer(aLayer);
  21.         layersLegend1.repaint();

  22.         //Change title of the layout
  23.         LayoutGraphic aTitle = mapLayout1.getTexts().get(0);
  24.         aTitle.setLabelText("MeteoInfo Class Library Demo - Station Point Layer");

  25.         //Add or change the legend in layout
  26.         LayoutLegend aLegend;
  27.         if (mapLayout1.getLegends().size() > 0) {
  28.             aLegend = mapLayout1.getLegends().get(0);
  29.         } else {
  30.             aLegend = mapLayout1.addLegend(650, 100);
  31.         }
  32.         aLegend.setLegendStyle(LegendStyles.Bar_Vertical);
  33.         aLegend.setLegendLayer(aLayer);
  34.         mapLayout1.paintGraphics();
  35.     }                                                      

  36.     private void jMenuItem_StationModelActionPerformed(java.awt.event.ActionEvent evt) {                                                      

  37.         // TODO add your handling code here:
  38.         //Create a MeteoDataInfo object
  39.         MeteoDataInfo aDataInfo = new MeteoDataInfo();

  40.         //Open SYNOP data file
  41.         String dataDir = "E:\\MeteoInfo\\sample\\MICAPS\\";
  42.         String fileName = dataDir + "10101414.000";
  43.         aDataInfo.openMICAPSData(fileName);

  44.         //Create a legend scheme
  45.         LegendScheme aLS = LegendManage.createSingleSymbolLegendScheme(ShapeTypes.Point, Color.blue, 12);

  46.         //Get station model data
  47.         StationModelData stationModelData = aDataInfo.getStationModelData();

  48.         //Create a layer
  49.         VectorLayer aLayer = DrawMeteoData.createStationModelLayer(stationModelData,aLS, "StationModel", true);
  50.         aLayer.setShapeType(ShapeTypes.Point);

  51.         //Add layer
  52.         layersLegend1.getActiveMapFrame().addLayer(aLayer);
  53.         layersLegend1.repaint();

  54.         //Change title of the layout
  55.         LayoutGraphic aTitle = mapLayout1.getTexts().get(0);
  56.         aTitle.setLabelText("MeteoInfo Class Library Demo - Station Model Layer");
  57.     }                                                      

  58.     private void jMenuItem_WeatherSymbolActionPerformed(java.awt.event.ActionEvent evt) {                                                        
  59.         // TODO add your handling code here:
  60.         //Create a MeteoDataInfo object
  61.         MeteoDataInfo aDataInfo = new MeteoDataInfo();

  62.         //Open SYNOP data file
  63.         String dataDir = "E:\\MeteoInfo\\sample\\MICAPS\\";
  64.         String fileName = dataDir + "10101414.000";
  65.         aDataInfo.openMICAPSData(fileName);

  66.         //Get StationData
  67.         StationData wData = aDataInfo.getStationData("WeatherNow");

  68.         //Create a legend scheme
  69.         LegendScheme aLS = LegendManage.createSingleSymbolLegendScheme(ShapeTypes.Point, Color.blue, 15);

  70.         //Create a contour layer
  71.         VectorLayer aLayer = DrawMeteoData.createWeatherSymbolLayer(wData, "All Weather", "Weather");

  72.         //Add layer
  73.         layersLegend1.getActiveMapFrame().addLayer(aLayer);
  74.         layersLegend1.repaint();

  75.         //Change title of the layout
  76.         LayoutGraphic aTitle = mapLayout1.getTexts().get(0);
  77.         aTitle.setLabelText("MeteoInfo Class Library Demo - Weather Symbol Layer");

  78.         //Add or change the legend in layout
  79.         LayoutLegend aLegend;
  80.         if (mapLayout1.getLegends().size() > 0) {
  81.             aLegend = mapLayout1.getLegends().get(0);
  82.         } else {
  83.             aLegend = mapLayout1.addLegend(650, 100);
  84.         }
  85.         aLegend.setLegendStyle(LegendStyles.Bar_Vertical);
  86.         aLegend.setLegendLayer(aLayer);
  87.         if (this.jTabbedPane1.getSelectedIndex() == 1) {
  88.             mapLayout1.paintGraphics();
  89.         }
  90.     }                                                      

  91.     private void jMenuItem_StationVectorActionPerformed(java.awt.event.ActionEvent evt) {                                                        
  92.         // TODO add your handling code here:
  93.         //Create a MeteoDataInfo object
  94.         MeteoDataInfo aDataInfo = new MeteoDataInfo();

  95.         //Open MICAPS data file
  96.         String dataDir = "E:\\MeteoInfo\\sample\\MICAPS\\";
  97.         String fileName = dataDir + "10101414.000";
  98.         aDataInfo.openMICAPSData(fileName);

  99.         //Get StationData
  100.         StationData wdData = aDataInfo.getStationData("WindDirection");
  101.         StationData wsData = aDataInfo.getStationData("WindSpeed");

  102.         //Create a legend scheme
  103.         LegendScheme aLS = LegendManage.createSingleSymbolLegendScheme(ShapeTypes.Point, Color.blue, 15);

  104.         //Create a contour layer
  105.         VectorLayer aLayer = DrawMeteoData.createSTVectorLayer(wdData, wsData, wdData, aLS, "StationVector", false);

  106.         //Add layer
  107.         layersLegend1.getActiveMapFrame().addLayer(aLayer);
  108.         layersLegend1.repaint();

  109.         //Change title of the layout
  110.         LayoutGraphic aTitle = mapLayout1.getTexts().get(0);
  111.         aTitle.setLabelText("MeteoInfo Class Library Demo - Station Wind Vector Layer");
  112.     }                                                      

  113.     private void jMenuItem_StationShadedActionPerformed(java.awt.event.ActionEvent evt) {                                                        
  114.         //TODO add your handling code here:
  115.         //Read data info
  116.         MeteoDataInfo aDataInfo = new MeteoDataInfo();
  117.         String dataDir = "E:\\MeteoInfo\\sample\\MICAPS\\";
  118.         String fileName = dataDir + "10101414.000";
  119.         aDataInfo.openMICAPSData(fileName);

  120.         //Get station data
  121.         StationData stationData = aDataInfo.getStationData("Precipitation6h");

  122.         //Interpolate
  123.         GridDataSetting aGDP = new GridDataSetting();
  124.         aGDP.dataExtent.minX = 60;
  125.         aGDP.dataExtent.maxX = 140;
  126.         aGDP.dataExtent.minY = -20;
  127.         aGDP.dataExtent.maxY = 60;
  128.         aGDP.xNum = 80;
  129.         aGDP.yNum = 80;
  130.         InterpolationSetting gridInterp = new InterpolationSetting();
  131.         gridInterp.setGridDataSetting(aGDP);

  132.         gridInterp.setInterpolationMethod(InterpolationMethods.IDW_Radius);
  133.         gridInterp.setRadius(2);
  134.         gridInterp.setMinPointNum(1);

  135.         GridData gridData = stationData.interpolateData(gridInterp);

  136.         //Create legend scheme
  137.         LegendScheme aLS = LegendManage.createLegendSchemeFromGridData(gridData, LegendType.GraduatedColor,ShapeTypes.Polygon);
  138.         ((PolygonBreak) aLS.getLegendBreaks().get(0)).setDrawFill(false);

  139.         //Create layer
  140.         VectorLayer aLayer = new VectorLayer(ShapeTypes.Polygon);
  141.         aLayer = DrawMeteoData.createShadedLayer(gridData, aLS, "Rain", "Rain", true);
  142.         aLayer.setMaskout(true);

  143.         //Add layer
  144.         layersLegend1.getActiveMapFrame().addLayer(aLayer);
  145.         layersLegend1.getActiveMapFrame().moveLayer(aLayer, 0);
  146.         layersLegend1.repaint();

  147.         //Change title of the layout
  148.         LayoutGraphic aTitle = mapLayout1.getTexts().get(0);
  149.         aTitle.setLabelText("MeteoInfo Class Library Demo - Station Shaded Layer");

  150.         //Add or change the legend in layout
  151.         LayoutLegend aLegend;
  152.         if (mapLayout1.getLegends().size() > 0) {
  153.             aLegend = mapLayout1.getLegends().get(0);
  154.         } else {
  155.             aLegend = mapLayout1.addLegend(650, 100);
  156.         }
  157.         aLegend.setLegendStyle(LegendStyles.Bar_Vertical);
  158.         aLegend.setLegendLayer(aLayer);
  159.         if (this.jTabbedPane1.getSelectedIndex() == 1) {
  160.             mapLayout1.paintGraphics();
  161.         }                              
  162.     }


调试结果如下:

1.png

2.png

3.png

4.png

5.png

密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-6-20 16:49:22 | 显示全部楼层
本科生学习中
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-6-13 21:15:23 | 显示全部楼层
{:eb502:}
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2017-6-15 09:40:30 | 显示全部楼层
学习中,谢谢分享
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表