- 积分
- 8631
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2014-5-4
- 最后登录
- 1970-1-1
|
发表于 2014-10-13 13:38:09
|
显示全部楼层
本帖最后由 zhksoft 于 2014-10-13 13:43 编辑
我修改的脚本如下 :
- # 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.MapData import *
- from MeteoInfoC.Data.MeteoData import *
- from MeteoInfoC.Layout import *
- from MeteoInfoC.Legend import *
- from MeteoInfoC.Projections import *
- from MeteoInfoC.Shape import *
- #---- 设置路径变量
- BaseDir = "e:\\Program Files\\MeteoInfo\"
- MapDir = BaseDir + "Map\"
- LegendDir = BaseDir + "Legend\"
- #DataDir = BaseDir + "Sample\\MICAPS\"
- DataDir="T:\\surface\\r6-p\"
- #---- 打开图层
- 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)
- #---- 设置起始结束时间
- sTime = DateTime.Parse("2014-10-12 14:00")
- eTime = DateTime.Parse("2014-10-12 20:00")
- #---- 站点数据插值为格点数据的设置
- interpSet = InterpolationSetting(60,140,-20,60,160,160,"IDW_Radius",2,1)
- #---- 设置图例
- ls = LegendScheme(ShapeTypes.Polygon)
- ls.ImportFromXMLFile(LegendDir + "rain1.lgs")
- #---- 设置MeteoDataInfo
- mid = MeteoDataInfo()
- #---- 循环
- while sTime <= eTime:
- inFile = sTime.ToString("yyMMddHH") + ".000"
- print inFile
- #---- 打开MICAPS数据文件
- mid.OpenMICAPSData(DataDir + inFile)
- #---- 获取6小时降水量站点数据
- stData = mid.GetStationData("Precipitation6h")
- #---- 将站点数据差值为格点数据
- 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 = " 全国降水量实况图\n6小时降水量 (" + sTime.ToString("yyyy-MM-dd HH:00") + ")"
- aText.SetLabelText(title)
- #---- 设置图例名称
- aLegend.Title = "降水量(毫米)"
- #---- 绘制图形
- mapLayout.PaintGraphics()
- #---- 输出图形为文件
- outFile = "Prec_" + sTime.ToString("yyyyMMddHH") + ".png"
- print outFile
- #mapLayout.ExportToPicture("E:\\Temp\" + outFile)
- #---- 删除6小时降水量图层
- if sTime < eTime:
- mapFrame.RemoveLayer(rainLayer)
- #---- 时间加6小时
- sTime = sTime.AddHours(6)
- #---- 显示程序窗体(只是为了看效果,自动运行时不需要)
- #Application.Run(myApp)
- myApp.Show()
复制代码
使用的是micaps地面降水数据
diamond 3 14年10月12日14时6小时降水量
14 10 12 14 -1
6
1 5 10 25 50 100
1 25 39
122.7 37.3 122.5 36.7 120.8 36.2 119.3 35.0 120.4 34.3
121.1 32.7 122.3 30.9 122.5 30.1 121.5 28.0 119.8 25.0
116.1 22.6 111.0 21.0 111.0 18.6 109.6 18.1 108.3 18.5
108.9 19.9 109.3 21.0 106.4 21.6 104.1 22.2 101.6 20.8
98.7 22.0 97.1 24.1 97.7 27.0 91.7 26.6 85.7 27.7
78.9 30.6 73.3 37.1 74.1 40.7 87.6 49.8 98.5 43.9
110.4 44.3 122.0 54.7 135.7 48.3 131.5 42.2 125.2 39.4
121.3 38.5 121.2 40.3 118.5 38.6 120.8 38.1
1 1123
50468 127.45 50.25 166 0
50953 126.77 45.75 143 0
52533 98.48 39.77 1478 0
52652 100.43 38.93 1483 0
52866 101.77 36.62 2262 0
52983 104.15 35.86 1875 0
53463 111.68 40.82 1065 0
53513 107.40 40.77 1041 0
53588 113.53 39.03 2898 0.8
53772 112.55 37.78 779 0.6
53915 106.67 35.55 1348 0.5
54218 118.97 42.27 572 0
54337 121.12 41.13 70 0
54342 123.43 41.77 43 0
54471 122.20 40.67 4 0
54497 124.33 40.05 14 0
54823 116.98 36.68 58 0.01
错误代码如下:
- 14101214.000
- Traceback (most recent call last):
- File "<string>", line 130, in <module>
- Exception: Invalid variable: Precipitation6h
复制代码
另:我运行另一个贴子的的程序
- #---- 相对湿度
- myApp.SetAntiAlias(True)
- myApp.SetLegendScheme("D:\micaps2ppt\\LGS\\RH.lgs")
- myApp.OpenMICAPSData("t:\\ecmwf\\RH\\700\" + inFile)
- myApp.SetDrawType("Shaded")
- myApp.Display("Var")
复制代码
也会出现如下错误:
- <div>14100920.096</div><div>Traceback (most recent call last):</div><div> File "<string>", line 80, in <module></div><div>Exception: Invalid variable: Var</div>
复制代码
14101214.000
(39.08 KB, 下载次数: 0)
|
|