- 积分
- 55955
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
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中。
下面给出一个脚本示例程序来演示绘制各种图形:
具体的代码如下:
- #--------------------------------------------------------
- # Author: Yaqiang Wang
- # Date: 2012-10-5
- # Purpose: Add 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
- #---- Create point graphics
- #---- Simple marker type
- print 'Create point graphics...'
- mipy.MapDocument.ActiveMapFrame.MapView.GraphicCollection.RemoveAll()
- pShape= PointShape()
- pShape.Point = PointD(120, 40)
- pLegend = PointBreak()
- pLegend.Size = 10
- pLegend.Color = Color.Blue
- pGraphic = Graphic(pShape, pLegend)
- mipy.MapDocument.ActiveMapFrame.MapView.GraphicCollection.Add(pGraphic)
- #---- Character marker type
- pShape= PointShape()
- pShape.Point = PointD(115, 40)
- pLegend = PointBreak()
- pLegend.MarkerType = MarkerType.Character
- pLegend.FontName = "Weather"
- pLegend.CharIndex = 170
- pLegend.Size = 20
- pGraphic = Graphic(pShape, pLegend)
- mipy.MapDocument.ActiveMapFrame.MapView.GraphicCollection.Add(pGraphic)
- #---- Image marker type
- pShape= PointShape()
- pShape.Point = PointD(110, 40)
- pLegend = PointBreak()
- pLegend.MarkerType = MarkerType.Image
- pLegend.Size = 40
- pLegend.ImagePath = "C:\\Program Files (x86)\\MeteoInfo\\Image\\26.gif"
- pGraphic = Graphic(pShape, pLegend)
- mipy.MapDocument.ActiveMapFrame.MapView.GraphicCollection.Add(pGraphic)
- #---- Create label graphics
- print 'Create label graphics...'
- pShape= PointShape()
- pShape.Point = PointD(110, 36)
- pLegend = LabelBreak()
- pLegend.Font = Font("Arial", 20)
- pLegend.Color = Color.Red
- pLegend.Text = "H"
- pGraphic = Graphic(pShape, pLegend)
- mipy.MapDocument.ActiveMapFrame.MapView.GraphicCollection.Add(pGraphic)
- #---- Create polyline graphic
- print 'Create polyline graphic...'
- plist = List[PointD]()
- plist.Add(PointD(120, 35))
- plist.Add(PointD(115, 32))
- plist.Add(PointD(110, 31))
- plist.Add(PointD(105, 32))
- pShape = PolylineShape()
- pShape.Points = plist
- pLegend = PolyLineBreak()
- pLegend.Style = LineStyles.StationaryFront
- pGraphic = Graphic(pShape, pLegend)
- mipy.MapDocument.ActiveMapFrame.MapView.GraphicCollection.Add(pGraphic)
- #---- Create polygon graphic
- print 'Create polygon graphic...'
- plist = List[PointD]()
- plist.Add(PointD(80, 35))
- plist.Add(PointD(83, 38))
- plist.Add(PointD(86, 40))
- plist.Add(PointD(88, 38))
- plist.Add(PointD(86, 36))
- plist.Add(PointD(82, 34))
- plist.Add(PointD(80, 35))
- pShape = PolygonShape()
- pShape.Points = plist
- pLegend = PolygonBreak()
- pLegend.Color = Color.FromArgb (125, Color.LightBlue);
- pGraphic = Graphic(pShape, pLegend)
- mipy.MapDocument.ActiveMapFrame.MapView.GraphicCollection.Add(pGraphic)
- #---- Refresh MapView
- mipy.MapDocument.ActiveMapFrame.MapView.PaintLayers()
- print 'Finished!'
复制代码
将pShape = PolylineShape()改为pShape = CurveLineShape()
将pShape = PolygonShape()改为pShape = CurvePolygonShape()
|
|