- 积分
- 55950
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2011-8-10 12:37:33
|
显示全部楼层
上面讲到的在MeteoInfo桌面软件中处理数据的方式虽然简单,只需动动鼠标就可以了,不过对于批量数据处理以及自动运行的需求无能为力。这时候就轮到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.DrawGridLabel = 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("2010-10-14 20:00")
aTime = sTime.AddHours(-6)
#---- 获取站点数据
myApp.RemoveDataLayers()
inFile = "China_Prec_" + sTime.ToString("yyyyMMddHH") + ".csv"
print inFile
#---- 打开文本格式站点数据文件
myApp.OpenLonLatData(DataDir + inFile)
#---- 获取累计降水站点数据
stData = myApp.GetStationData("Precipitation")
#---- 绘制累计降水图层
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时") + " - " + sTime.ToString("yyyy年MM月dd日HH时")
myApp.SetTitle(title)
#---- 设置图例名称
myApp.MapLayout.DefaultLegend.Title = "降水量(毫米)"
#---- 绘制图形
myApp.MapLayout.PaintGraphics()
#---- 输出图形为文件
outFile = "Prec_" + aTime.ToString("yyyyMMddHH") + "-" + sTime.ToString("yyyyMMddHH") + ".png"
print outFile
#myApp.SaveFigure(DataDir + outFile)
#---- 显示程序窗体(只是为了看效果,自动运行时不需要)
Application.Run(myApp)
运行结果:
|
|