- 积分
- 55945
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
在MeteoInfo中图层、地图、版面等的各种设置可以保存在一个项目文件中(.mip)。可以通过打开该项目文件还原项目的各种设置。项目文件也可以在脚本程序中使用,会很大程度降低脚本程序的复杂性(其实脚本程序中最复杂的部分主要是图形的各种设置)。比如上一讲中站点数据分析绘图的例子可以利用项目文件降低复杂性,并在某些方面提升图形质量。前面还提到了图例文件(.lgs),使用它也能是脚本中图例设置部分更加简洁。
1、首先在MeteoInfo桌面软件中根据需要编辑一个项目文件(这里是rain.mip),能更方便地控制图形中各要素,尤其是对省会城市标志位置的编辑能够提升图形质量(如果在脚本中控制每个标注的位置是非常繁琐的)。同时编辑出降水图层的图例(rain1.lgs)。
2、利用项目文件和图例文件简化上一讲的脚本程序。
- # encoding=utf-8
- #-----------------------------------------------------
- # Author: Yaqiang Wang
- # Date: 2014-12-6
- # Purpose: Interpolate station data to grid data
- # Note: Sample
- #-----------------------------------------------------
- #---- Import classes
- print 'Import classes...'
- from org.meteoinfo.layout import MapLayout
- from org.meteoinfo.data import StationData
- from org.meteoinfo.data.mapdata import MapDataManage
- from org.meteoinfo.data.meteodata import MeteoDataInfo, DrawMeteoData
- from org.meteoinfo.legend import LegendScheme, LegendType, PolygonBreak, MapFrame
- from org.meteoinfo.shape import ShapeTypes
- from org.meteoinfo.layout import LegendStyles, LayoutMap
- from org.meteoinfo.global import Extent
- from org.meteoinfo.projection import ProjectionInfo
- from org.meteoinfo.geoprocess.analysis import InterpolationSetting
- import os
- from datetime import datetime
- from datetime import timedelta
- from java.awt import Color
- from java.awt import Font
- from javax.swing import JFrame
- #---- Set directories
- print 'Set directories...'
- baseDir = 'D:/MyProgram/Distribution/java/MeteoInfo/MeteoInfo'
- dataDir = os.path.join(baseDir, 'sample/MICAPS')
- mapDir = os.path.join(baseDir, 'map')
- #---- Create MapLayout object
- mapLayout = MapLayout()
- #---- Load project file (*.mip)
- pfn = 'D:/Temp/mip/rain.mip'
- mapLayout.loadProjectFile(pfn)
- mapFrame = mapLayout.getActiveMapFrame()
- #---- Create MeteoDataInfo object
- mdi = MeteoDataInfo()
- #---- Set start/end time
- stime = datetime(2010,10,14,14)
- etime = datetime(2010,10,14,20)
- #---- Loop
- print 'Get sum station data...'
- sdata = StationData()
- atime = stime
- i = 0
- while atime < etime:
- #---- Open a MICAPS data file
- fn = os.path.join(dataDir, stime.strftime('%y%m%d%H') + '.000')
- mdi.openMICAPSData(fn)
- #---- Sum precipitation station data
- if i == 0:
- sdata = mdi.getStationData('Precipitation6h')
- else:
- sdata = sdata.add(mdi.getStationData('Precipitation6h'))
- atime = atime + timedelta(hours=6)
-
- #---- Interpolate station data to grid data
- print 'Interpolate station data to grid data...'
- interpSet = InterpolationSetting(60,140,-20,60,160,160,"IDW_Radius",2,1)
- #radList = [10.0, 8.0, 6.0, 4.0]
- #interpSet = InterpolationSetting(60,140,-20,60,160,160,"Cressman",radList)
- gdata = sdata.interpolateData(interpSet)
- #---- Set legend scheme
- ls = LegendScheme(ShapeTypes.Polygon)
- lsfn = 'D:/Temp/rain1.lgs'
- ls.importFromXMLFile(lsfn)
- #---- Create shaded layer
- print 'Create shaded layer...'
- layer = DrawMeteoData.createShadedLayer(gdata, ls, 'Rain_shaded', 'Rain', True)
- layer.setMaskout(True)
- #---- Add layer
- mapFrame.addLayer(layer)
- mapFrame.moveLayer(layer, 0)
- #---- Set sub title
- stime = stime + timedelta(hours=-6)
- subTitle = mapLayout.getTexts().get(1)
- subTitle.setLabelText(u'(' + stime.strftime('%Y-%m-%d %H:00') +
- u' 至 ' + etime.strftime('%Y-%m-%d %H:00') + u')')
- #---- Set legend
- legend = mapLayout.getLegends().get(0)
- legend.setLegendLayer(layer)
- legend.setTitle(u'降水量(毫米)')
- frame = JFrame('MeteoInfo Script Sample', size = (750, 530))
- frame.add(mapLayout)
- frame.visible = True
- print 'Finished!'
从运行结果图中可以看出省会城市标注的改进。
|
|