爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 9891|回复: 15

LegendScheme aLS参数问题

[复制链接]

新浪微博达人勋

发表于 2012-9-12 09:01:29 | 显示全部楼层 |阅读模式

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

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

x
王老师:
GridData press = aDataInfo.GetGridData("PS");
  bool hasUndefData = false;
            LegendScheme aLS = LegendManage.CreateLegendSchemeFromGridData(press,
                        LegendType.UniqueValue, ShapeTypes.Polyline, ref hasUndefData);
我的问题是:
1.aLS有一个很重要的参数BreakNum无法灵活设置,好像是固化在格点数据press中,如果要改变等值线间隔,只能在分析完成后,在可视的图例对话框里设置,以XML导出之,作为配置文件使用时导入,这意味着几十个高度层、几十个变量、冬半年和夏半年以及根据需要设置分析间隔时需作大量的工作。如能够在以上方法中增加几个参数,那将是开发者的一个福音。
2.double[] cValues = LegendManage.CreateContourValuesInterval(950, 1030, 2.5);可以解决间隔和初始值问题:
            LegendScheme aLS = LegendManage.CreateGraduatedLegendScheme(cValues,
                CreateColors(Color.Blue, Color.Black, 33), ShapeTypes.Polyline, 950, 1030, false, -9999);
但在创建图层时无法通过:
VectorLayer aLayer = DrawMeteoData.CreateContourLayer(press, aLS, "Contour_PS", "PS");
原因就是press的节点数与cValues不同。或许修改动态库增加参数是唯一的办法。

以上是学生的一点想法,是否可行,老师赐教!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2012-9-12 10:20:34 | 显示全部楼层
你的这个思路按道理是可行,有什么错误提示?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2012-9-12 11:31:58 | 显示全部楼层
        //得到格点数据
            GridData press = aDataInfo.GetGridData("PS");
            press = press / 100;//百帕
            double[] cValues = LegendManage.CreateContourValuesInterval(950, 1030, 2.5);
            LegendScheme aLS = LegendManage.CreateGraduatedLegendScheme(cValues,
                CreateColors(Color.Blue, Color.Black, 33), ShapeTypes.Polyline, 950, 1030, false, -9999);
            VectorLayer aLayer = DrawMeteoData.CreateContourLayer(press, aLS, "Contour_PS", "PS");
在上一行设断点,跟踪结果:aLayer 为NULL,矢量图层未创建成功。
            layersLegend1.ActiveMapFrame.AddLayer(aLayer);
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2012-9-12 14:01:40 | 显示全部楼层

你看看cValues里的值是不是都不在press格点值的范围之外?这样会导致没有等值线被追踪出来,因此aLayer是Null
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2012-9-12 15:39:56 | 显示全部楼层
王老师正确!其实meteoinfo的方法已经可以处理多数想做的工作,只是没有深入进去而已。以下是完成的代码,再简单做些工作,便可以可视化配置各种矢量图层的分析属性。
该作业完全是王老师一步一动指导完成,提供给大家分享。
private void barButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
        {
            MeteoDataInfo aDataInfo = new MeteoDataInfo();
            string aFile = Application.StartupPath + "\\GrADS\\model.ctl";
            aDataInfo.OpenGrADSData(aFile);
            aDataInfo.LevelIndex = 0;

            //得到格点数据
            GridData press = aDataInfo.GetGridData("PS");
            double interval=25;//等值线间隔
            double[] cValues = LegendManage.CreateContourValuesInterval(press.GetMinValue(), press.GetMaxValue(), interval);
            int cNum =Convert .ToInt32 ((press.GetMaxValue() - press.GetMinValue()) / interval);
            LegendScheme aLS = LegendManage.CreateGraduatedLegendScheme(cValues,
                CreateColors(Color.Blue, Color.Black, cNum), ShapeTypes.Polyline, press.GetMinValue(),
                press.GetMaxValue(), false, -9999);

            VectorLayer aLayer = DrawMeteoData.CreateContourLayer(press, aLS, "Contour_PS", "PS");

            layersLegend1.ActiveMapFrame.AddLayer(aLayer);
            layersLegend1.ActiveMapFrame.MoveLayer(aLayer.Handle, 4);
            //添加标注
            LayerLabelSet(aLayer, Color.Black, true, false, 1, Color.FromArgb(255, 255, 230), false);
            layersLegend1.ActiveMapFrame.MapView.PaintLayers();
            layersLegend1.Refresh();
        }
分析结果:
I:\ps.png

评分

参与人数 1金钱 +2 收起 理由
geoeco + 2 很给力!

查看全部评分

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

新浪微博达人勋

发表于 2012-9-12 15:54:15 | 显示全部楼层
guoming 发表于 2012-9-12 15:39
王老师正确!其实meteoinfo的方法已经可以处理多数想做的工作,只是没有深入进去而已。以下是完成的代码,再 ...

不错,挺能钻研的。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2012-10-31 11:31:49 | 显示全部楼层
谢谢,正用到
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2012-11-16 23:07:53 | 显示全部楼层
本帖最后由 wbriver 于 2012-11-16 23:11 编辑
MeteoInfo 发表于 2012-9-12 14:01
你看看cValues里的值是不是都不在press格点值的范围之外?这样会导致没有等值线被追踪出来,因此aLayer是 ...


王老师您好,最近想做个气象适宜度的图,主要用下面几个县市预报数据来做的,大致分三个等级:适宜、较适宜和不适宜(1、2、3级)。。。
我是模仿Demo里面Station Data→Shaded方法来做的,根据预报,每个站点赋值(如数值:1、2、3),再进行插值显示,如图片所示。。。请教王老师如何在图片右侧显示类似左侧显示的色标(左侧的色标是我自己手动改的),谢谢~
  1.     private void TSMI_StationShaded_Click(object sender, EventArgs e)
  2.         {
  3.             this.Cursor = Cursors.WaitCursor;
  4.             //Read data info
  5.             MeteoDataInfo aDataInfo = new MeteoDataInfo();
  6.             string aFile = Application.StartupPath + "\\qx_agr.csv";
  7.             aDataInfo.OpenLonLatData(aFile);
  8.             
  9.             //Get station data
  10.             StationData stationData = aDataInfo.GetStationData("SuitabilityDegree");
  11.             //Interpolate
  12.             GridDataPara aGDP = new GridDataPara();
  13.             aGDP.dataExtent.minX = 118.2;
  14.             aGDP.dataExtent.maxX = 121.5;
  15.             aGDP.dataExtent.minY = 30.35;
  16.             aGDP.dataExtent.maxY = 31.2;
  17.             aGDP.xNum = 100;
  18.             aGDP.yNum = 100;
  19.             GridInterpolation gridInterp = new GridInterpolation();
  20.             gridInterp.GridDataParaV = aGDP;
  21.             gridInterp.GridInterMethodV = GridInterMethod.IDW_Radius;
  22.             gridInterp.Radius = 2;
  23.             gridInterp.MinPointNum = 1;
  24.             double[] X = new double[1];
  25.             double[] Y = new double[1];
  26.             ContourDraw.CreateGridXY(gridInterp.GridDataParaV, ref X, ref Y);
  27.             double[,] S = stationData.Data;
  28.             S = ContourDraw.FilterDiscreteData_Radius(S, gridInterp.Radius,
  29.                 gridInterp.GridDataParaV.dataExtent, stationData.UNDEF);
  30.             GridData gridData = ContourDraw.InterpolateDiscreteData_Radius(S,
  31.                 X, Y, gridInterp.MinPointNum, gridInterp.Radius, stationData.UNDEF);
  32.             //Create legend scheme
  33.             bool hasUndefData = false;
  34.             Color[] colors = new Color[] { Color.FromArgb(255, 0, 205, 252), Color.FromArgb(255, 38, 255, 0), Color.FromArgb(255, 255, 0, 0) };
  35.             double[] cValues = LegendManage.CreateContourValuesInterval(1, 3, 1);
  36.             LegendScheme aLS = LegendManage.CreateGraduatedLegendScheme(cValues, colors, ShapeTypes.Polygon, Math.Round(gridData.GetMinValue()), Math.Round(gridData.GetMaxValue()), hasUndefData, -99999);
  37.             //Create a contour layer
  38.             VectorLayer aLayer = DrawMeteoData.CreateShadedLayer(gridData, aLS, "气象适宜度", null);
  39.             aLayer.IsMaskout = true;//设置IsMaskout属性,设为true即可进行边界剪裁
  40.             aLayer.Expanded = true;
  41.             //Add layer
  42.             layersLegend1.ActiveMapFrame.AddLayer(aLayer);
  43.             layersLegend1.ActiveMapFrame.MoveLayer(aLayer.Handle, 0);

  44.             //Change title of the layout
  45.             LayoutGraphic aTitle = mapLayout1.GetTexts()[0];
  46.             
  47.             LayoutLegend aLegend;
  48.             if (mapLayout1.GetLegends().Count > 0)
  49.                 aLegend = mapLayout1.GetLegends()[0];
  50.             else
  51.                 aLegend = mapLayout1.AddLegend(700, 150);
  52.             aLegend.LegendStyle = LegendStyleEnum.Bar_Vertical;
  53.             aLegend.LegendLayer = aLayer;
  54.             if (tabControl1.SelectedIndex == 1)
  55.                 mapLayout1.PaintGraphics();
  56.             layersLegend1.Refresh();
  57.             this.Cursor = Cursors.Default;
  58.         }
QQ截图20121116224948.jpg
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2012-11-17 10:50:49 | 显示全部楼层
wbriver 发表于 2012-11-16 23:07
王老师您好,最近想做个气象适宜度的图,主要用下面几个县市预报数据来做的,大致分三个等级:适宜、较 ...

这个你可以讲你左侧的图例保存好,每次绘图的时候加载这个图例就可以了~~~用
LegendScheme aLS = new LegendScheme(ShapeTypes.Polygon);
            aLS.ImportFromXMLFile(Application.StartupPath+"\\Legend\\气象适宜度.lgs");
这两句代码创建图例,这个*.lgs文件就是你手动保存好的那个图例,你下次自己加载就可以了~~~你可以试试,互相讨论哈 ,哥们!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2012-11-17 17:03:38 | 显示全部楼层
wbriver 发表于 2012-11-16 23:07
王老师您好,最近想做个气象适宜度的图,主要用下面几个县市预报数据来做的,大致分三个等级:适宜、较 ...

aLegend.LegendStyle = LegendStyleEnum.Bar_Vertical;
改为:
aLegend.LegendStyle = LegendStyleEnum.Normal;
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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