请选择 进入手机版 | 继续访问电脑版
爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 21481|回复: 44

MeteoInfo脚本示例:图形绘制

[复制链接]

新浪微博达人勋

发表于 2012-10-5 21:00:13 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 MeteoInfo 于 2012-10-6 11:11 编辑

在MeteoInfo中用户绘制图形的类是Graphic,有两个重要的属性:Shape和Legend,Shape里包含了PointShape、PolylineShape、PolygonShape,分别对应点、线、面。Legend可以是PointBreak(点)、LabelBreak(文字)、PolylineBreak(线)、PolygonBreak(面)。PointBreak又可以设置不同的MarkerType:Simple(简单点图形)、Character(利用字体来绘制点)、Image(利用图片来绘制点)。有了这些组合就可以绘制出丰富的图形了,所有绘制的图形都在MapView的GraphicCollection中。

下面给出一个脚本示例程序来演示绘制各种图形:
Image00927.png
Image00929.png

具体的代码如下:
  1. #--------------------------------------------------------        
  2. # Author: Yaqiang Wang                                          
  3. # Date: 2012-10-5                                                
  4. # Purpose: Add Graphics  
  5. # Note: Sample                                                   
  6. #-----------------------------------------------------------  
  7. #---- Import clr and classes
  8. import clr
  9. clr.AddReferenceByPartialName("System")
  10. clr.AddReferenceByPartialName("System.Drawing")
  11. from System import *
  12. from System.Drawing import *
  13. from System.Collections.Generic import *
  14. clr.AddReference("MeteoInfoC.dll")
  15. from MeteoInfoC import *
  16. from MeteoInfoC.Data.MapData import *
  17. from MeteoInfoC.Geoprocess import *
  18. from MeteoInfoC.Layer import *
  19. from MeteoInfoC.Shape import *
  20. from MeteoInfoC.Legend import *
  21. from MeteoInfoC.Drawing import *
  22. import os.path

  23. #---- Create point graphics
  24. #---- Simple marker type
  25. print 'Create point graphics...'
  26. mipy.MapDocument.ActiveMapFrame.MapView.GraphicCollection.RemoveAll()
  27. pShape= PointShape()
  28. pShape.Point = PointD(120, 40)
  29. pLegend = PointBreak()
  30. pLegend.Size = 10
  31. pLegend.Color = Color.Blue
  32. pGraphic = Graphic(pShape, pLegend)
  33. mipy.MapDocument.ActiveMapFrame.MapView.GraphicCollection.Add(pGraphic)
  34. #---- Character marker type
  35. pShape= PointShape()
  36. pShape.Point = PointD(115, 40)
  37. pLegend = PointBreak()
  38. pLegend.MarkerType = MarkerType.Character
  39. pLegend.FontName = "Weather"
  40. pLegend.CharIndex = 170
  41. pLegend.Size = 20
  42. pGraphic = Graphic(pShape, pLegend)
  43. mipy.MapDocument.ActiveMapFrame.MapView.GraphicCollection.Add(pGraphic)
  44. #---- Image marker type
  45. pShape= PointShape()
  46. pShape.Point = PointD(110, 40)
  47. pLegend = PointBreak()
  48. pLegend.MarkerType = MarkerType.Image
  49. pLegend.Size = 40
  50. pLegend.ImagePath = "C:\\Program Files (x86)\\MeteoInfo\\Image\\26.gif"
  51. pGraphic = Graphic(pShape, pLegend)
  52. mipy.MapDocument.ActiveMapFrame.MapView.GraphicCollection.Add(pGraphic)

  53. #---- Create label graphics
  54. print 'Create label graphics...'
  55. pShape= PointShape()
  56. pShape.Point = PointD(110, 36)
  57. pLegend = LabelBreak()
  58. pLegend.Font = Font("Arial", 20)
  59. pLegend.Color = Color.Red
  60. pLegend.Text = "H"
  61. pGraphic = Graphic(pShape, pLegend)
  62. mipy.MapDocument.ActiveMapFrame.MapView.GraphicCollection.Add(pGraphic)

  63. #---- Create polyline graphic
  64. print 'Create polyline graphic...'
  65. plist = List[PointD]()
  66. plist.Add(PointD(120, 35))
  67. plist.Add(PointD(115, 32))
  68. plist.Add(PointD(110, 31))
  69. plist.Add(PointD(105, 32))
  70. pShape = PolylineShape()
  71. pShape.Points = plist
  72. pLegend = PolyLineBreak()
  73. pLegend.Style = LineStyles.StationaryFront
  74. pGraphic = Graphic(pShape, pLegend)
  75. mipy.MapDocument.ActiveMapFrame.MapView.GraphicCollection.Add(pGraphic)

  76. #---- Create polygon graphic
  77. print 'Create polygon graphic...'
  78. plist = List[PointD]()
  79. plist.Add(PointD(80, 35))
  80. plist.Add(PointD(83, 38))
  81. plist.Add(PointD(86, 40))
  82. plist.Add(PointD(88, 38))
  83. plist.Add(PointD(86, 36))
  84. plist.Add(PointD(82, 34))
  85. plist.Add(PointD(80, 35))
  86. pShape = PolygonShape()
  87. pShape.Points = plist
  88. pLegend = PolygonBreak()
  89. pLegend.Color = Color.FromArgb (125, Color.LightBlue);
  90. pGraphic = Graphic(pShape, pLegend)
  91. mipy.MapDocument.ActiveMapFrame.MapView.GraphicCollection.Add(pGraphic)

  92. #---- Refresh MapView
  93. mipy.MapDocument.ActiveMapFrame.MapView.PaintLayers()
  94. print 'Finished!'
复制代码

将pShape = PolylineShape()改为pShape = CurveLineShape()
将pShape = PolygonShape()改为pShape = CurvePolygonShape()
Image00930.png

本帖被以下淘专辑推荐:

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

新浪微博达人勋

发表于 2013-6-14 16:00:41 | 显示全部楼层
请教一下,我参考这个脚本,用c#代码调用相关方法如下:
        PointShape ps = new PointShape();
            ps.Point.X = 121;
            ps.Point.Y = 30;

            PointBreak pb = new PointBreak();
            pb.Size = 100;
            pb.Color = Color.Blue;

            LabelBreak pl = new LabelBreak();
            pl.Font = new Font("Arial", 20);
            pl.Color = Color.Red;
            pl.Text = "HHHH";

            Graphic g = new Graphic(ps, pl);            
            layersLegend1.ActiveMapFrame.MapView.GraphicCollection.Add(g);
            this.mapView1.PaintLayers();
为什么画图没显示呢?
密码修改失败请联系微信:mofangbao
回复 支持 0 反对 1

使用道具 举报

新浪微博达人勋

发表于 2012-10-6 04:11:59 | 显示全部楼层
脚本真是功能强大啊
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2013-6-14 16:16:07 | 显示全部楼层
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2013-6-14 16:23:42 | 显示全部楼层
额,就是没任何内容,没报错,我断点设置了一下发现代码还是执行了的;
如下图:
11.png
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2013-6-14 16:27:13 | 显示全部楼层
alexmitsui 发表于 2013-6-14 16:23
额,就是没任何内容,没报错,我断点设置了一下发现代码还是执行了的;
如下图:

你的MapView是否投影过?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2013-6-14 16:50:31 | 显示全部楼层
MeteoInfo 发表于 2013-6-14 16:27
你的MapView是否投影过?

不是十分理解王老师的问题;关于投影转换,使用了默认的经纬度投影,除此之外,只做了以下几个方面视图显示的代码(应该不是您问题所指):
1、  private void 宁波视图_Click(object sender, EventArgs e)
        {
            layersLegend1.ActiveMapFrame.MapView.ZoomToExtent(120.7, 122.7, 29, 30.5);
            layersLegend1.Refresh();
        }
2、 private void TSB_FullExtent_Click(object sender, EventArgs e)
        {
            Extent aExtent = mapView1.Extent;
            mapView1.ZoomToExtent(aExtent);
        }
3、加了经纬度网格显示;
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2013-6-16 09:47:41 | 显示全部楼层
alexmitsui 发表于 2013-6-14 16:00
请教一下,我参考这个脚本,用c#代码调用相关方法如下:
        PointShape ps = new PointShape();
    ...

相关代码改为:
PointShape ps = new PointShape();
ps.Point = new PointD(121, 30);
即可。

问题在于设置PointShape的Point属性时会更新PointShape的Extent,这个Extent是显示时很重要的属性。你原来的代码设置X, Y值不会更新Extent就带来了显示的问题。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2013-6-16 10:03:26 | 显示全部楼层
{:eb313:}{:eb313:}{:eb313:}果然搞定!谢谢王老师指导!!!
嘿嘿,再次感谢,王老师提供的深层次的原因解释,后面使用的时候可以避免类似情况。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-1-26 17:59:34 | 显示全部楼层
请问怎么把花上去的单独生成一个shape格式的图层!!!
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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