- 积分
- 55955
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
发表于 2011-7-11 09:43:10
|
显示全部楼层
有可能是路径的问题,Demo程序中用路径的起始为.\\是在当前目录为MeteoInfo安装目录的情况下。如果当前目录有变化,就需要重新设置图层及数据的路径。更好的方法是将路径用变量来表示,路径变化后只需要改动变量即可。下面是添加了路径变量的例子,你可以参照修改试试。
# This Python file uses the following encoding: GB2312
#---- 引入类库
import clr
clr.AddReferenceByPartialName("System")
clr.AddReferenceByPartialName("System.Windows.Forms")
clr.AddReferenceByPartialName("System.Drawing")
from System import *
from System.Windows.Forms import *
from System.Drawing import *
clr.AddReference("MeteoInfoC.dll")
from MeteoInfoC import *
from MeteoInfoC.Layout import *
from MeteoInfoC.Data import *
#---- 设置路径变量
BaseDir = "C:\\Program Files (x86)\\MeteoInfo\\"
MapDir = BaseDir + "Map\\"
LegendDir = BaseDir + "Legend\\"
DataDir = "E:\\temp\\"
#---- 创建MIApp类的对象
myApp = MIApp()
#---- 添加图层
myApp.OpenLayer(MapDir + "bou2_4p.shp")
#---- 设置图层渲染
myApp.SetLegendBreak("bou2_4p.shp",0,Color.Yellow,Color.Gray,1,True,False,True)
myApp.OpenLayer(MapDir + "bou1_4l.shp")
myApp.SetLegendBreak("bou1_4l.shp",0,Color.Blue)
myApp.OpenLayer(MapDir + "china.shp")
myApp.SetLayerVisible("china.shp", False)
myApp.OpenLayer(MapDir + "res1_4m.shp")
myApp.SetLegendBreak("res1_4m.shp",0,5,Color.Red,Color.Black,True,True,True)
#---- 获取矢量图层对象,并设置标注
aLayer = myApp.GetVectorLayer("res1_4m.shp")
aLayer.LabelSet.FieldName = "NAME";
aLayer.LabelSet.LabelFont = Font("楷体", 10);
aLayer.LabelSet.Offset = 15;
aLayer.AddLabels();
#---- Lambert投影
myApp.ProjectLayers("+proj=lcc+lat_1=25+lat_2=47+lon_0=105")
#---- 按照经纬度范围缩放地图
myApp.ZoomLonLat(78,130,15,53)
#---- 设置屏蔽图层(只绘制中国境内图形)
myApp.SetMaskout("china.shp")
#---- 设置绘图类型为shaded
myApp.SetDrawType("shaded")
#---- 站点数据插值为格点数据的设置
myApp.SetInterpolation(60,140,-20,60,160,160,"IDW_Radius",1,1)
#---- 设置图例文件
myApp.SetLegendScheme(LegendDir + "rain1.lgs")
#---- 设置DefalutLayoutMap(图层显示)
myApp.MapLayout.DefaultLayoutMap.DrawGridLine = False
myApp.MapLayout.DefaultLayoutMap.DrawNeatLine = False
myApp.MapLayout.DefaultLayoutMap.Left = 10
myApp.MapLayout.DefaultLayoutMap.Top = 10
myApp.MapLayout.DefaultLayoutMap.Width = 620
myApp.MapLayout.DefaultLayoutMap.Height = 450
#---- 设置DefaultIllustration(插图,这里是南海脚图)
myApp.MapLayout.DefaultIllustration.Visible = True
myApp.MapLayout.DefaultIllustration.Left = 40
myApp.MapLayout.DefaultIllustration.Top = 350
myApp.MapLayout.DefaultIllustration.Width = 85
myApp.MapLayout.DefaultIllustration.Height = 109
#---- 设置DefaultTitle(图形标题)
myApp.MapLayout.DefaultTitle.SetFont("黑体", 12)
myApp.MapLayout.DefaultTitle.Top = 40
myApp.MapLayout.DefaultTitle.Left = 80
#---- 设置DefaultLegend(图例)
myApp.MapLayout.DefaultLegend.LegendStyle = LegendStyleEnum.Normal
myApp.MapLayout.DefaultLegend.DrawNeatLine = False
myApp.MapLayout.DefaultLegend.Title = "降水量(毫米)"
myApp.MapLayout.DefaultLegend.BackColor = Color.White
myApp.MapLayout.DefaultLegend.Font = Font("Arial", 8)
myApp.MapLayout.DefaultLegend.Left = 575
myApp.MapLayout.DefaultLegend.Top = 250
#---- 设置起始结束时间
sTime = DateTime.Parse("2009-02-24 08:00")
eTime = DateTime.Parse("2009-02-24 14:00")
aTime = sTime.AddHours(-6)
stData = StationData()
i = 1
#---- 循环
while sTime <= eTime:
myApp.RemoveDataLayers()
inFile = sTime.ToString("yyMMddHH") + ".000"
print inFile
#---- 打开MICAPS数据文件
myApp.OpenMICAPSData(DataDir + inFile)
#---- 获取累计降水站点数据
if i == 1:
stData = myApp.GetStationData("Precipitation6h")
else:
stData = stData + myApp.GetStationData("Precipitation6h")
#---- 时间加6小时
sTime = sTime.AddHours(6)
i = i + 1
#---- 绘制累计降水图层
myApp.Display(stData)
#---- 调整图层顺序(以避免压盖)
myApp.MoveLayerToTop("bou2_4p.shp")
myApp.MoveLayerToTop("bou1_4l.shp")
myApp.MoveLayerToTop("res1_4m.shp")
#---- 设置标题名称
title = " 全国降水量实况图\n" + aTime.ToString("yyyy年MM月dd日HH时") + " - " + eTime.ToString("yyyy年MM月dd日HH时")
myApp.SetTitle(title)
#---- 设置图例名称
myApp.MapLayout.DefaultLegend.Title = "降水量(毫米)"
#---- 绘制图形
myApp.MapLayout.PaintGraphics()
#---- 输出图形为文件
outFile = "Prec_" + aTime.ToString("yyyyMMddHH") + "-" + eTime.ToString("yyyyMMddHH") + ".png"
print outFile
#myApp.SaveFigure(DataDir + outFile)
#---- 显示程序窗体(只是为了看效果,自动运行时不需要)
Application.Run(myApp) |
|