- 积分
- 55946
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 MeteoInfo 于 2014-9-12 15:34 编辑
格点数据(GridData)是MeteoInfo数据结构中很重要的一个类,这个Jython脚本程序(需要用MeteoInfo Java版)演示了两个文件中同一变量格点数据的加、减、乘、除几个基本运算。需要在MeteoInfo Java版桌面程序中运行此脚本(脚本代码中有miapp变量的都需要在桌面程序中运行,因为miapp就是当前运行的桌面程序主界面对象)。Java不支持运算符重载,所以只能用add, sub, mul, div方法来实现相应的计算功能。
- #-----------------------------------------------------
- # Author: Yaqiang Wang
- # Date: 2014-9-12
- # Purpose: Add, sub, mul, div functions
- # Note: Sample
- #-----------------------------------------------------
- from org.meteoinfo.data.meteodata import MeteoDataInfo
- from org.meteoinfo.data.meteodata import DrawMeteoData
- from org.meteoinfo.legend import LegendManage
- from org.meteoinfo.legend import LegendType
- from org.meteoinfo.shape import ShapeTypes
- import os.path
- import jarray
- #Set data directory
- dataDir = 'D:/Temp/nc'
- #Create MeteoDataInfo object
- mdi1 = MeteoDataInfo()
- mdi2 = MeteoDataInfo()
- #Read data files
- fn1 = os.path.join(dataDir, 'wrfout_d01_2008-01-01_12_00_00.nc')
- fn2 = os.path.join(dataDir, 'wrfout_d01_2008-01-02_12_00_00.nc')
- print 'File 1: ' + fn1
- print 'File 2: ' + fn2
- mdi1.openNetCDFData(fn1)
- mdi2.openNetCDFData(fn2)
- #Get grid data
- print 'Get grid data...'
- gData1 = mdi1.getGridData('Q2')
- gData2 = mdi2.getGridData('Q2')
- #Add two grid data
- print 'Add grid data...'
- addData = gData1.add(gData2)
- #Subtract two grid data
- print 'Subtract grid data...'
- subData = gData1.sub(gData2)
- #Multiple two grid data
- print 'Multiple grid data...'
- mulData = gData1.mul(gData2)
- #Divide two grid data
- print 'Divide grid data...'
- divData = gData1.div(gData2)
- #Create legend scheme
- addLS = LegendManage.createLegendSchemeFromGridData(addData, LegendType.GraduatedColor, ShapeTypes.Polygon)
- subLS = LegendManage.createLegendSchemeFromGridData(subData, LegendType.GraduatedColor, ShapeTypes.Polygon)
- mulLS = LegendManage.createLegendSchemeFromGridData(mulData, LegendType.GraduatedColor, ShapeTypes.Polygon)
- addLS = LegendManage.createLegendSchemeFromGridData(divData, LegendType.GraduatedColor, ShapeTypes.Polygon)
- #Create shaded layers
- print 'Create shaded layers...'
- addLayer = DrawMeteoData.createShadedLayer(addData, addLS, 'Test_Add_Shaded', 'Add', True)
- subLayer = DrawMeteoData.createShadedLayer(subData, subLS, 'Test_Sub_Shaded', 'Sub', True)
- mulLayer = DrawMeteoData.createShadedLayer(mulData, addLS, 'Test_Mul_Shaded', 'Mul', True)
- divLayer = DrawMeteoData.createShadedLayer(divData, addLS, 'Test_Div_Shaded', 'Div', True)
- addLayer.setProjInfo(mdi1.getProjectionInfo())
- subLayer.setProjInfo(mdi1.getProjectionInfo())
- mulLayer.setProjInfo(mdi1.getProjectionInfo())
- divLayer.setProjInfo(mdi1.getProjectionInfo())
- #Add layers
- print 'Add layers...'
- mf = miapp.getMapDocument().getActiveMapFrame()
- mf.getMapView().projectLayers(mdi1.getProjectionInfo())
- mf.addLayer(addLayer)
- mf.moveLayer(addLayer, 0)
- mf.addLayer(subLayer)
- mf.moveLayer(subLayer, 0)
- mf.addLayer(mulLayer)
- mf.moveLayer(mulLayer, 0)
- mf.addLayer(divLayer)
- mf.moveLayer(divLayer, 0)
- print 'Finished!'
|
|