- 积分
- 55965
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 MeteoInfo 于 2012-5-30 14:46 编辑
较全面的讲讲格点数据生成的各种图层,主要包括Contour(等值线)、Shaded(等值填充)、Grid_Fill(格点填充)、Grid_Point(格点点图层)、Raster(栅格图层)、Vector(风场矢量)、Barb(风向杆)、Streamline(流场)。
先说说Contour、Shaded、Grid_Fill、Grid_Point和Raster,这几种图层只需要一个格点数据(GridData)。获取格点数据已经在上一讲讲过了,然后需要生成图例(LegendScheme),再用DrawMeteoData类的一些静态方法来从GridData创建各种图层:
Contour: DrawMeteoData.CreateContourLayer(GridData gridData, LegendScheme aLS, string layerName, string fieldName)
Shaded: DrawMeteoData.CreateShadedLayer(GridData gridData, LegendScheme aLS, string layerName, string fieldName)
Grid_Fill: DrawMeteoData.CreateGridFillLayer(GridData gridData, LegendScheme aLS, string LName, string fieldName)
Grid_Point: DrawMeteoData.CreateGridPointLayer(GridData gridData, LegendScheme aLS, string LName, string fieldName)
Raster: DrawMeteoData.CreateRasterLayer(GridData GridData, string LName, LegendScheme aLS)
相关代码如下:
- private void TSMI_GrADSShaded_Click(object sender, EventArgs e)
- {
- //Create a MeteoDataInfo object
- MeteoDataInfo aDataInfo = new MeteoDataInfo();
- //Open GrADS data file
- string aFile = Application.StartupPath + "\\Sample\\model.ctl";
- aDataInfo.OpenGrADSData(aFile);
- //Get GridData
- GridData press = aDataInfo.GetGridData("PS");
- //Create a legend scheme
- bool hasUndefData = false;
- LegendScheme aLS = LegendManage.CreateLegendSchemeFromGridData(press,
- LegendType.GraduatedColor, ShapeTypes.Polygon, ref hasUndefData);
- //Create a contour layer
- VectorLayer aLayer = DrawMeteoData.CreateShadedLayer(press, aLS, "Shaded_PS");
- //Add layer
- layersLegend1.ActiveMapFrame.AddLayer(aLayer);
- layersLegend1.ActiveMapFrame.MoveLayer(aLayer.Handle, 0);
- layersLegend1.Refresh();
- //Change title of the layout
- LayoutGraphic aTitle = mapLayout1.GetTexts()[0];
- aTitle.SetLabelText("MeteoInfo Class Library Demo - Shaded Layer");
- //Add or change the legend in layout
- LayoutLegend aLegend;
- if (mapLayout1.GetLegends().Count > 0)
- aLegend = mapLayout1.GetLegends()[0];
- else
- aLegend = mapLayout1.AddLegend(650, 100);
- aLegend.LegendStyle = LegendStyleEnum.Bar_Vertical;
- aLegend.LegendLayer = aLayer;
- mapLayout1.PaintGraphics();
- }
- private void TSMI_GrADSGrid_Fill_Click(object sender, EventArgs e)
- {
- //Create a MeteoDataInfo object
- MeteoDataInfo aDataInfo = new MeteoDataInfo();
- //Open GrADS data file
- string aFile = Application.StartupPath + "\\Sample\\model.ctl";
- aDataInfo.OpenGrADSData(aFile);
- //Get GridData
- GridData press = aDataInfo.GetGridData("PS");
- //Create a legend scheme
- bool hasUndefData = false;
- LegendScheme aLS = LegendManage.CreateLegendSchemeFromGridData(press,
- LegendType.GraduatedColor, ShapeTypes.Polygon, ref hasUndefData);
- //Create a contour layer
- VectorLayer aLayer = DrawMeteoData.CreateGridFillLayer(press, aLS, "GridFill_PS");
- //Add layer
- layersLegend1.ActiveMapFrame.AddLayer(aLayer);
- layersLegend1.ActiveMapFrame.MoveLayer(aLayer.Handle, 0);
- layersLegend1.Refresh();
- //Change title of the layout
- LayoutGraphic aTitle = mapLayout1.GetTexts()[0];
- aTitle.SetLabelText("MeteoInfo Class Library Demo - Grid_Fill Layer");
- //Add or change the legend in layout
- LayoutLegend aLegend;
- if (mapLayout1.GetLegends().Count > 0)
- aLegend = mapLayout1.GetLegends()[0];
- else
- aLegend = mapLayout1.AddLegend(650, 100);
- aLegend.LegendStyle = LegendStyleEnum.Bar_Vertical;
- aLegend.LegendLayer = aLayer;
- mapLayout1.PaintGraphics();
- }
- private void TSMI_GrADSGrid_Point_Click(object sender, EventArgs e)
- {
- //Create a MeteoDataInfo object
- MeteoDataInfo aDataInfo = new MeteoDataInfo();
- //Open GrADS data file
- string aFile = Application.StartupPath + "\\Sample\\model.ctl";
- aDataInfo.OpenGrADSData(aFile);
- //Get GridData
- GridData press = aDataInfo.GetGridData("PS");
- //Create a legend scheme
- bool hasUndefData = false;
- LegendScheme aLS = LegendManage.CreateLegendSchemeFromGridData(press,
- LegendType.GraduatedColor, ShapeTypes.Point, ref hasUndefData);
- //Create a contour layer
- VectorLayer aLayer = DrawMeteoData.CreateGridPointLayer(press, aLS, "GridPoint_PS");
- //Add layer
- layersLegend1.ActiveMapFrame.AddLayer(aLayer);
- layersLegend1.ActiveMapFrame.MoveLayer(aLayer.Handle, 2);
- layersLegend1.Refresh();
- //Change title of the layout
- LayoutGraphic aTitle = mapLayout1.GetTexts()[0];
- aTitle.SetLabelText("MeteoInfo Class Library Demo - Shaded Layer");
- //Add or change the legend in layout
- LayoutLegend aLegend;
- if (mapLayout1.GetLegends().Count > 0)
- aLegend = mapLayout1.GetLegends()[0];
- else
- aLegend = mapLayout1.AddLegend(650, 100);
- aLegend.LegendStyle = LegendStyleEnum.Bar_Vertical;
- aLegend.LegendLayer = aLayer;
- mapLayout1.PaintGraphics();
- }
- private void TSMI_Raster_Click(object sender, EventArgs e)
- {
- //Create a MeteoDataInfo object
- MeteoDataInfo aDataInfo = new MeteoDataInfo();
- //Open GrADS data file
- string aFile = Application.StartupPath + "\\Sample\\model.ctl";
- aDataInfo.OpenGrADSData(aFile);
- //Get GridData
- GridData press = aDataInfo.GetGridData("PS");
- //Create a legend scheme
- bool hasUndefData = false;
- LegendScheme aLS = LegendManage.CreateLegendSchemeFromGridData(press,
- LegendType.GraduatedColor, ShapeTypes.Polygon, ref hasUndefData);
- //Create a contour layer
- RasterLayer aLayer = DrawMeteoData.CreateRasterLayer(press, "Raster_PS", aLS);
- //Add layer
- layersLegend1.ActiveMapFrame.AddLayer(aLayer);
- layersLegend1.ActiveMapFrame.MoveLayer(aLayer.Handle, 0);
- layersLegend1.Refresh();
- //Change title of the layout
- LayoutGraphic aTitle = mapLayout1.GetTexts()[0];
- aTitle.SetLabelText("MeteoInfo Class Library Demo - Raster Layer");
- //Add or change the legend in layout
- LayoutLegend aLegend;
- if (mapLayout1.GetLegends().Count > 0)
- aLegend = mapLayout1.GetLegends()[0];
- else
- aLegend = mapLayout1.AddLegend(650, 100);
- aLegend.LegendStyle = LegendStyleEnum.Bar_Vertical;
- aLegend.LegendLayer = aLayer;
- mapLayout1.PaintGraphics();
- }
运行结果:
再讲讲后三种关于风场的图层,需要至少两个格点数据,风场U、V分量或者风速、风向,model.ctl/model.dat数据里是U、V分量,所以这里只示例了这种情况,风速、风向的情况也很类似。MeteoDataInfo对象里可以设置TiimeIndex和LevelIndex来获得不同时次是高度的某变量的格点数据,由于地面风场只有海洋区域有,因此可以将LevelIndex设的大些。用GetGridData方法获取风场U、V分量的GridData,然后就可以用DrawMeteoData类中的相应方法来创建Vector、Barb和Streamline图层了。其中Vector和Barb图层还可以根据第三个变量来设置图元的颜色,以便显示更丰富的信息。
Vector: DrawMeteoData.CreateGridVectorLayer(GridData uData, GridData vData, GridData gridData,
LegendScheme aLS, bool ifColor, string lName, bool isUV)
Barb: DrawMeteoData.CreateGridBarbLayer(GridData uData, GridData vData, GridData gridData,
LegendScheme aLS, bool ifColor, string lName, bool isUV)
Streamline: DrawMeteoData.CreateStreamlineLayer(GridData uData, GridData vData, int density, LegendScheme aLS,
string lName, bool isUV)
具体的代码如下:
- private void TSMI_GrADSVector_Click(object sender, EventArgs e)
- {
- //Create a MeteoDataInfo object
- MeteoDataInfo aDataInfo = new MeteoDataInfo();
- //Open GrADS data file
- string aFile = Application.StartupPath + "\\Sample\\model.ctl";
- aDataInfo.OpenGrADSData(aFile);
- //Get GridData
- aDataInfo.TimeIndex = 2;
- aDataInfo.LevelIndex = 3;
- GridData tData = aDataInfo.GetGridData("T");
- GridData uData = aDataInfo.GetGridData("U");
- GridData vData = aDataInfo .GetGridData ("V");
- //Create a legend scheme
- bool hasUndefData = false;
- LegendScheme aLS = LegendManage.CreateLegendSchemeFromGridData(tData,
- LegendType.GraduatedColor, ShapeTypes.Point, ref hasUndefData);
- //Create a contour layer
- VectorLayer aLayer = DrawMeteoData.CreateGridVectorLayer(uData, vData, tData, aLS, true, "Vector_T", true);
- //Add layer
- layersLegend1.ActiveMapFrame.AddLayer(aLayer);
- layersLegend1.ActiveMapFrame.MoveLayer(aLayer.Handle, 2);
- layersLegend1.Refresh();
- //Change title of the layout
- LayoutGraphic aTitle = mapLayout1.GetTexts()[0];
- aTitle.SetLabelText("MeteoInfo Class Library Demo - Wind Vector Layer");
- //Add or change the legend in layout
- LayoutLegend aLegend;
- if (mapLayout1.GetLegends().Count > 0)
- aLegend = mapLayout1.GetLegends()[0];
- else
- aLegend = mapLayout1.AddLegend(650, 100);
- aLegend.LegendStyle = LegendStyleEnum.Bar_Vertical;
- aLegend.LegendLayer = aLayer;
- mapLayout1.PaintGraphics();
- }
- private void TSMI_GrADSBarb_Click(object sender, EventArgs e)
- {
- //Create a MeteoDataInfo object
- MeteoDataInfo aDataInfo = new MeteoDataInfo();
- //Open GrADS data file
- string aFile = Application.StartupPath + "\\Sample\\model.ctl";
- aDataInfo.OpenGrADSData(aFile);
- //Get GridData
- aDataInfo.TimeIndex = 2;
- aDataInfo.LevelIndex = 3;
- GridData uData = aDataInfo.GetGridData("U");
- GridData vData = aDataInfo.GetGridData("V");
- //Create a legend scheme
- LegendScheme aLS = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Point, Color.Blue, 10);
- //Create a contour layer
- VectorLayer aLayer = DrawMeteoData.CreateGridBarbLayer(uData, vData, uData, aLS, false, "Barb_UV", true);
- //Add layer
- layersLegend1.ActiveMapFrame.AddLayer(aLayer);
- layersLegend1.ActiveMapFrame.MoveLayer(aLayer.Handle, 2);
- layersLegend1.Refresh();
- //Change title of the layout
- LayoutGraphic aTitle = mapLayout1.GetTexts()[0];
- aTitle.SetLabelText("MeteoInfo Class Library Demo - Wind Barb Layer");
- }
- private void TSMI_GrADSStreamline_Click(object sender, EventArgs e)
- {
- //Create a MeteoDataInfo object
- MeteoDataInfo aDataInfo = new MeteoDataInfo();
- //Open GrADS data file
- string aFile = Application.StartupPath + "\\Sample\\model.ctl";
- aDataInfo.OpenGrADSData(aFile);
- //Get GridData
- aDataInfo.TimeIndex = 2;
- aDataInfo.LevelIndex = 3;
- GridData uData = aDataInfo.GetGridData("U");
- GridData vData = aDataInfo.GetGridData("V");
- //Create a legend scheme
- LegendScheme aLS = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Polyline, Color.Blue, 1);
- //Create a contour layer
- VectorLayer aLayer = DrawMeteoData.CreateStreamlineLayer(uData, vData, 4, aLS, "Streamline_UV", true);
- //Add layer
- layersLegend1.ActiveMapFrame.AddLayer(aLayer);
- layersLegend1.ActiveMapFrame.MoveLayer(aLayer.Handle, 2);
- layersLegend1.Refresh();
- //Change title of the layout
- LayoutGraphic aTitle = mapLayout1.GetTexts()[0];
- aTitle.SetLabelText("MeteoInfo Class Library Demo - Wind Streamline Layer");
- }
运行结果:
|
|