爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 3171|回复: 2

运行MeteoInfo自带的脚本出错

[复制链接]

新浪微博达人勋

发表于 2015-1-29 21:18:32 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 redersun 于 2015-1-29 21:19 编辑

想尽快的感受一下脚本运行的效果,于是运行demo_rain_sum.py脚本,运行之前修改脚本中的变量BaseDir,修改了操作系统的环境变量path,其他未动,直接运行,弹出提示:

Traceback (most recent call last):
  File "<string>", line 43, in <module>
AttributeError: 'LabelSet' object has no attribute 'Offset'


脚本第43行为:aLayer.LabelSet.Offset = 15;

该怎么办?不知是操作有误还是什么原因?我下载的最新非安装版,直接解压运行的那种
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-1-29 22:51:59 | 显示全部楼层
自带的脚本很陈旧了,新的demo_rain_sum.py如下:

  1. # This Python file uses the following encoding: GB2312
  2. #---- 引入类库
  3. import clr
  4. clr.AddReferenceByPartialName("System")
  5. clr.AddReferenceByPartialName("System.Windows.Forms")
  6. clr.AddReferenceByPartialName("System.Drawing")
  7. from System import *
  8. from System.Windows.Forms import *
  9. from System.Drawing import *
  10. clr.AddReference("MeteoInfoC.dll")
  11. from MeteoInfoC import *
  12. from MeteoInfoC.Data import *
  13. from MeteoInfoC.Data.MapData import *
  14. from MeteoInfoC.Data.MeteoData import *
  15. from MeteoInfoC.Layout import *
  16. from MeteoInfoC.Legend import *
  17. from MeteoInfoC.Projections import *
  18. from MeteoInfoC.Shape import *

  19. #---- 设置路径变量
  20. BaseDir = "D:\\MyProgram\\Distribution\\CSharp\\MeteoInfo\\MeteoInfo\\"
  21. MapDir = BaseDir + "Map\\"
  22. LegendDir = BaseDir + "Legend\\"
  23. DataDir = BaseDir + "Sample\\MICAPS\\"

  24. #---- 打开图层
  25. bou2Layer = MapDataManage.OpenLayer(MapDir + "bou2_4p.shp")
  26. lb = bou2Layer.LegendScheme.LegendBreaks[0]
  27. lb.Color = Color.Yellow
  28. lb.OutlineColor = Color.Gray
  29. lb.OutlineSize = 1
  30. lb.DrawFill = False
  31. bou1Layer = MapDataManage.OpenLayer(MapDir + "bou1_4l.shp")
  32. lb = bou1Layer.LegendScheme.LegendBreaks[0]
  33. lb.Color = Color.Blue
  34. chinaLayer = MapDataManage.OpenLayer(MapDir + "china.shp")
  35. chinaLayer.Visible = False
  36. res1Layer = MapDataManage.OpenLayer(MapDir + "res1_4m.shp")
  37. lb = res1Layer.LegendScheme.LegendBreaks[0]
  38. lb.Color = Color.Red
  39. lb.OutlineColor = Color.Black
  40. lb.Size = 5
  41. res1Layer.LabelSet.FieldName = "NAME";
  42. res1Layer.LabelSet.LabelFont = Font("楷体", 10);
  43. res1Layer.LabelSet.YOffset = 15;
  44. res1Layer.AddLabels();

  45. #---- 创建MIApp类的对象
  46. myApp = MIApp()
  47. mapLayout = myApp.MapLayout
  48. layoutMap = mapLayout.ActiveLayoutMap
  49. mapFrame = layoutMap.MapFrame
  50. mapView = mapFrame.MapView

  51. #---- 添加图层
  52. mapFrame.AddLayer(bou2Layer)
  53. mapFrame.AddLayer(bou1Layer)
  54. mapFrame.AddLayer(chinaLayer)
  55. mapFrame.AddLayer(res1Layer)

  56. #---- Lambert投影
  57. projInfo = ProjectionInfo("+proj=lcc+lat_1=25+lat_2=47+lon_0=105")
  58. mapView.ProjectLayers(projInfo)

  59. #---- 按照经纬度范围缩放地图
  60. mapView.ZoomToExtentLonLat(78,130,15,53)

  61. #---- 设置屏蔽图层(只绘制中国境内图形)
  62. mapView.MaskOut.SetMaskLayer = True
  63. mapView.MaskOut.MaskLayer = chinaLayer.LayerName

  64. #---- 设置ActiveLayoutMap(图层显示)
  65. layoutMap.DrawGridLine = False
  66. layoutMap.DrawNeatLine = False
  67. layoutMap.DrawGridLabel = False
  68. layoutMap.DrawGridTickLine = False
  69. layoutMap.Left = 10
  70. layoutMap.Top = 10
  71. layoutMap.Width = 620
  72. layoutMap.Height = 450

  73. #---- 设置南海脚图(添加Map Frame)
  74. aMapFrame = MapFrame()
  75. aMapFrame.IsFireMapViewUpdate = True
  76. aLayoutMap = LayoutMap(aMapFrame)
  77. aLayoutMap.DrawGridLabel = False
  78. aLayoutMap.DrawGridTickLine = False
  79. aLayoutMap.Left = 40
  80. aLayoutMap.Top = 350
  81. aLayoutMap.Width = 85
  82. aLayoutMap.Height = 109
  83. mapLayout.AddElement(aLayoutMap)
  84. aMapFrame.AddLayer(bou1Layer)
  85. aProjInfo = ProjectionInfo("+proj=lcc+lat_1=25+lat_2=47+lon_0=105")
  86. aMapFrame.MapView.ProjectLayers(aProjInfo)
  87. aMapFrame.MapView.ZoomToExtentLonLat(106.5,122.5,1,23)

  88. #---- 设置图形标题
  89. aText = mapLayout.AddText("Temp",220,50,"黑体",12)

  90. #---- 设置图例
  91. aLegend = mapLayout.AddLegend(550,220)
  92. aLegend.LegendStyle = LegendStyles.Normal   
  93. aLegend.DrawNeatLine = False
  94. aLegend.Title = "降水量(毫米)"
  95. aLegend.BackColor = Color.White
  96. aLegend.Font = Font("Arial", 8)

  97. #---- 站点数据插值为格点数据的设置
  98. interpSet = InterpolationSetting(60,140,-20,60,160,160,"IDW_Radius",2,1)

  99. #---- 设置图例
  100. ls = LegendScheme(ShapeTypes.Polygon)
  101. ls.ImportFromXMLFile(LegendDir + "rain1.lgs")

  102. #---- 设置MeteoDataInfo
  103. mid = MeteoDataInfo()

  104. #---- 设置起始结束时间
  105. sTime = DateTime.Parse("2010-10-14 14:00")
  106. eTime = DateTime.Parse("2010-10-14 20:00")
  107. aTime = sTime.AddHours(-6)

  108. stData = StationData()
  109. i = 1
  110. #---- 循环
  111. while sTime <= eTime:
  112.   inFile = sTime.ToString("yyMMddHH") + ".000"
  113.   print inFile
  114.   #---- 打开MICAPS数据文件
  115.   mid.OpenMICAPSData(DataDir + inFile)  
  116.   #---- 获取累计降水站点数据
  117.   if i == 1:
  118.     stData = mid.GetStationData("Precipitation6h")
  119.   else:
  120.     stData = stData + mid.GetStationData("Precipitation6h")
  121.   
  122.   #---- 时间加6小时
  123.   sTime = sTime.AddHours(6)
  124.   i = i + 1

  125. #---- 将站点数据差值为格点数据
  126. gData = DrawMeteoData.InterpolateData(stData, interpSet)
  127. #---- 生成6小时降水量图层
  128. rainLayer = DrawMeteoData.CreateShadedLayer(gData, ls, "Precipitation", "Rain")
  129. rainLayer.IsMaskout = True
  130. #---- 添加图层
  131. mapFrame.AddLayer(rainLayer)
  132. print "Display finished"  
  133. #---- 调整图层顺序(以避免压盖)
  134. mapFrame.MoveLayerToBottom(rainLayer)  
  135. #---- 设置标题名称
  136. title = "            全国降水量实况图\n" + aTime.ToString("yyyy年MM月dd日HH时") + " - " + eTime.ToString("yyyy年MM月dd日HH时")
  137. aText.SetLabelText(title)     
  138. #---- 设置图例名称
  139. aLegend.Title = "降水量(毫米)"
  140. #---- 绘制图形
  141. mapLayout.PaintGraphics()
  142. #---- 输出图形为文件
  143. outFile = "Prec_" + aTime.ToString("yyyyMMddHH") + "-" + eTime.ToString("yyyyMMddHH") + ".png"
  144. print outFile
  145. #mapLayout.ExportToPicture(DataDir + outFile)   
  146.   
  147. #---- 显示程序窗体(只是为了看效果,自动运行时不需要)
  148. myApp.Show()


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

新浪微博达人勋

 楼主| 发表于 2015-2-1 11:10:27 | 显示全部楼层
用新脚本试过了,没问题,做出来的图很漂亮,谢谢老师的帮忙,我得继续努力学习
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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