- 积分
- 55975
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 MeteoInfo 于 2013-7-29 16:10 编辑
之前示例了用脚本进行一些图形的绘制:MeteoInfo脚本示例:MeteoInfo脚本示例:图形绘制http://bbs.06climate.com/forum.php?mod=viewthread&tid=10278&fromuid=106
这个帖子补充讲一下同心圆图形的绘制。圆的绘制用到了CircleShape类,该类继承自PolygonShape类,可以用圆心点和半径来构造CircleShape。通过圆心不同角度的线段可以用PolylineShape来绘制。需要MeteoInfo最新文件(见置顶帖子)。
比较简单,多看看代码应该能理解,运行效果如下(注意MapView的XYScaleFactor属性要设为1,缺省是1.2):
脚本代码如下:
- #--------------------------------------------------------
- # Author: Yaqiang Wang
- # Date: 2013-7-29
- # Purpose: Add cicle graphics
- # Note: Sample
- #-----------------------------------------------------------
- #---- Import clr and classes
- import clr
- clr.AddReferenceByPartialName("System")
- clr.AddReferenceByPartialName("System.Drawing")
- from System import *
- from System.Drawing import *
- from System.Collections.Generic import *
- clr.AddReference("MeteoInfoC.dll")
- from MeteoInfoC import *
- from MeteoInfoC.Data.MapData import *
- from MeteoInfoC.Geoprocess import *
- from MeteoInfoC.Layer import *
- from MeteoInfoC.Shape import *
- from MeteoInfoC.Legend import *
- from MeteoInfoC.Drawing import *
- import os.path
- from math import *
- #---- Create circle graphics
- print 'Create circle graphics...'
- cpoint = PointD(120.6, 30.6)
- radius = [0.5, 1, 1.5]
- pLegend = PolygonBreak()
- pLegend.DrawFill = False
- pLegend.OutlineColor = Color.Black
- for r in radius:
- cshape = CircleShape(cpoint, r)
- cgraphic = Graphic(cshape, pLegend)
- mipy.MapDocument.ActiveMapFrame.MapView.GraphicCollection.Add(cgraphic)
- #---- Create polyline graphics
- print 'Create polyline graphics...'
- def getcirclepoint(cp, r, a):
- x = cp.X + r * cos(a * 3.1416 / 180.0)
- y = cp.Y + r * sin(a * 3.1416 / 180.0)
- p = PointD(x, y)
- return p
- llegend = PolyLineBreak()
- llegend.Color = Color.Black
- r = 1.5
- plist = List[PointD]()
- plist.Add(PointD(cpoint.X - r, cpoint.Y))
- plist.Add(PointD(cpoint.X + r, cpoint.Y))
- lshape = PolylineShape()
- lshape.Points = plist
- lgraphic = Graphic(lshape, llegend)
- mipy.MapDocument.ActiveMapFrame.MapView.GraphicCollection.Add(lgraphic)
- plist = List[PointD]()
- plist.Add(PointD(cpoint.X, cpoint.Y + r))
- plist.Add(PointD(cpoint.X, cpoint.Y - r))
- lshape = PolylineShape()
- lshape.Points = plist
- lgraphic = Graphic(lshape, llegend)
- mipy.MapDocument.ActiveMapFrame.MapView.GraphicCollection.Add(lgraphic)
- plist = List[PointD]()
- angle = 45.0
- p = getcirclepoint(cpoint, r, angle)
- plist.Add(p)
- angle = 225.0
- p = getcirclepoint(cpoint, r, angle)
- plist.Add(p)
- lshape = PolylineShape()
- lshape.Points = plist
- lgraphic = Graphic(lshape, llegend)
- mipy.MapDocument.ActiveMapFrame.MapView.GraphicCollection.Add(lgraphic)
- plist = List[PointD]()
- angle = 135.0
- p = getcirclepoint(cpoint, r, angle)
- plist.Add(p)
- angle = 315.0
- p = getcirclepoint(cpoint, r, angle)
- plist.Add(p)
- lshape = PolylineShape()
- lshape.Points = plist
- lgraphic = Graphic(lshape, llegend)
- mipy.MapDocument.ActiveMapFrame.MapView.GraphicCollection.Add(lgraphic)
- #---- Refresh MapView
- mipy.MapDocument.ActiveMapFrame.MapView.PaintLayers()
- print 'Finished!'
|
|