- 积分
- 55954
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
发表于 2015-1-29 22:51:59
|
显示全部楼层
自带的脚本很陈旧了,新的demo_rain_sum.py如下:
- # 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.Data import *
- from MeteoInfoC.Data.MapData import *
- from MeteoInfoC.Data.MeteoData import *
- from MeteoInfoC.Layout import *
- from MeteoInfoC.Legend import *
- from MeteoInfoC.Projections import *
- from MeteoInfoC.Shape import *
- #---- 设置路径变量
- BaseDir = "D:\\MyProgram\\Distribution\\CSharp\\MeteoInfo\\MeteoInfo\\"
- MapDir = BaseDir + "Map\\"
- LegendDir = BaseDir + "Legend\\"
- DataDir = BaseDir + "Sample\\MICAPS\\"
- #---- 打开图层
- bou2Layer = MapDataManage.OpenLayer(MapDir + "bou2_4p.shp")
- lb = bou2Layer.LegendScheme.LegendBreaks[0]
- lb.Color = Color.Yellow
- lb.OutlineColor = Color.Gray
- lb.OutlineSize = 1
- lb.DrawFill = False
- bou1Layer = MapDataManage.OpenLayer(MapDir + "bou1_4l.shp")
- lb = bou1Layer.LegendScheme.LegendBreaks[0]
- lb.Color = Color.Blue
- chinaLayer = MapDataManage.OpenLayer(MapDir + "china.shp")
- chinaLayer.Visible = False
- res1Layer = MapDataManage.OpenLayer(MapDir + "res1_4m.shp")
- lb = res1Layer.LegendScheme.LegendBreaks[0]
- lb.Color = Color.Red
- lb.OutlineColor = Color.Black
- lb.Size = 5
- res1Layer.LabelSet.FieldName = "NAME";
- res1Layer.LabelSet.LabelFont = Font("楷体", 10);
- res1Layer.LabelSet.YOffset = 15;
- res1Layer.AddLabels();
- #---- 创建MIApp类的对象
- myApp = MIApp()
- mapLayout = myApp.MapLayout
- layoutMap = mapLayout.ActiveLayoutMap
- mapFrame = layoutMap.MapFrame
- mapView = mapFrame.MapView
- #---- 添加图层
- mapFrame.AddLayer(bou2Layer)
- mapFrame.AddLayer(bou1Layer)
- mapFrame.AddLayer(chinaLayer)
- mapFrame.AddLayer(res1Layer)
- #---- Lambert投影
- projInfo = ProjectionInfo("+proj=lcc+lat_1=25+lat_2=47+lon_0=105")
- mapView.ProjectLayers(projInfo)
- #---- 按照经纬度范围缩放地图
- mapView.ZoomToExtentLonLat(78,130,15,53)
- #---- 设置屏蔽图层(只绘制中国境内图形)
- mapView.MaskOut.SetMaskLayer = True
- mapView.MaskOut.MaskLayer = chinaLayer.LayerName
-
- #---- 设置ActiveLayoutMap(图层显示)
- layoutMap.DrawGridLine = False
- layoutMap.DrawNeatLine = False
- layoutMap.DrawGridLabel = False
- layoutMap.DrawGridTickLine = False
- layoutMap.Left = 10
- layoutMap.Top = 10
- layoutMap.Width = 620
- layoutMap.Height = 450
- #---- 设置南海脚图(添加Map Frame)
- aMapFrame = MapFrame()
- aMapFrame.IsFireMapViewUpdate = True
- aLayoutMap = LayoutMap(aMapFrame)
- aLayoutMap.DrawGridLabel = False
- aLayoutMap.DrawGridTickLine = False
- aLayoutMap.Left = 40
- aLayoutMap.Top = 350
- aLayoutMap.Width = 85
- aLayoutMap.Height = 109
- mapLayout.AddElement(aLayoutMap)
- aMapFrame.AddLayer(bou1Layer)
- aProjInfo = ProjectionInfo("+proj=lcc+lat_1=25+lat_2=47+lon_0=105")
- aMapFrame.MapView.ProjectLayers(aProjInfo)
- aMapFrame.MapView.ZoomToExtentLonLat(106.5,122.5,1,23)
- #---- 设置图形标题
- aText = mapLayout.AddText("Temp",220,50,"黑体",12)
- #---- 设置图例
- aLegend = mapLayout.AddLegend(550,220)
- aLegend.LegendStyle = LegendStyles.Normal
- aLegend.DrawNeatLine = False
- aLegend.Title = "降水量(毫米)"
- aLegend.BackColor = Color.White
- aLegend.Font = Font("Arial", 8)
- #---- 站点数据插值为格点数据的设置
- interpSet = InterpolationSetting(60,140,-20,60,160,160,"IDW_Radius",2,1)
- #---- 设置图例
- ls = LegendScheme(ShapeTypes.Polygon)
- ls.ImportFromXMLFile(LegendDir + "rain1.lgs")
- #---- 设置MeteoDataInfo
- mid = MeteoDataInfo()
- #---- 设置起始结束时间
- sTime = DateTime.Parse("2010-10-14 14:00")
- eTime = DateTime.Parse("2010-10-14 20:00")
- aTime = sTime.AddHours(-6)
- stData = StationData()
- i = 1
- #---- 循环
- while sTime <= eTime:
- inFile = sTime.ToString("yyMMddHH") + ".000"
- print inFile
- #---- 打开MICAPS数据文件
- mid.OpenMICAPSData(DataDir + inFile)
- #---- 获取累计降水站点数据
- if i == 1:
- stData = mid.GetStationData("Precipitation6h")
- else:
- stData = stData + mid.GetStationData("Precipitation6h")
-
- #---- 时间加6小时
- sTime = sTime.AddHours(6)
- i = i + 1
- #---- 将站点数据差值为格点数据
- gData = DrawMeteoData.InterpolateData(stData, interpSet)
- #---- 生成6小时降水量图层
- rainLayer = DrawMeteoData.CreateShadedLayer(gData, ls, "Precipitation", "Rain")
- rainLayer.IsMaskout = True
- #---- 添加图层
- mapFrame.AddLayer(rainLayer)
- print "Display finished"
- #---- 调整图层顺序(以避免压盖)
- mapFrame.MoveLayerToBottom(rainLayer)
- #---- 设置标题名称
- title = " 全国降水量实况图\n" + aTime.ToString("yyyy年MM月dd日HH时") + " - " + eTime.ToString("yyyy年MM月dd日HH时")
- aText.SetLabelText(title)
- #---- 设置图例名称
- aLegend.Title = "降水量(毫米)"
- #---- 绘制图形
- mapLayout.PaintGraphics()
- #---- 输出图形为文件
- outFile = "Prec_" + aTime.ToString("yyyyMMddHH") + "-" + eTime.ToString("yyyyMMddHH") + ".png"
- print outFile
- #mapLayout.ExportToPicture(DataDir + outFile)
-
- #---- 显示程序窗体(只是为了看效果,自动运行时不需要)
- myApp.Show()
|
|