- 积分
- 55955
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
发表于 2015-4-14 23:34:05
|
显示全部楼层
示例脚本程序,注意看里面的注释:
- #-----------------------------------------------------
- # Author: Yaqiang Wang
- # Date: 2014-12-1
- # Purpose: Read and plot U/V grid data
- # Note: Sample
- #-----------------------------------------------------
- #---- Import classes
- print 'Import classes...'
- from org.meteoinfo.layout import MapLayout
- from org.meteoinfo.data import DataMath
- from org.meteoinfo.data.mapdata import MapDataManage
- from org.meteoinfo.data.meteodata import MeteoDataInfo, DrawMeteoData
- from org.meteoinfo.layout import LegendStyles
- from org.meteoinfo.global import Extent
- import os
- from java.awt import Color
- from javax.swing import JFrame
- #---- Set directories
- print 'Set directories...'
- baseDir = 'D:/MyProgram/Distribution/java/MeteoInfo/MeteoInfo'
- dataDir = os.path.join(baseDir, 'sample')
- mapDir = os.path.join(baseDir, 'map')
- #---- Create MapLayout object
- mapLayout = MapLayout()
- mapFrame = mapLayout.getActiveMapFrame()
- #---- Load country layer
- print 'Load country layer...'
- countryLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'country1.shp'))
- lb = countryLayer.getLegendScheme().getLegendBreaks().get(0)
- lb.setDrawFill(False)
- lb.setOutlineColor(Color.black)
- mapFrame.addLayer(countryLayer)
- #---- Create MeteoDataInfo object
- mdi = MeteoDataInfo()
- #---- Open a GrADS data file
- fn = os.path.join(dataDir, 'GrADS/model.ctl')
- mdi.openGrADSData(fn)
- #---- Get U/V grid data
- mdi.setTimeIndex(2)
- mdi.setLevelIndex(3)
- udata = mdi.getGridData('U')
- vdata = mdi.getGridData('V')
- #---- Calculate wind speed from U/V data
- speed = DataMath.magnitude(udata, vdata)
- #---- Set the grid value to -1 if the speed is less than 10
- speed.replaceValue(10, -1, False)
- #---- Maskout U data, Only the grid with speed bigger than 10 has valid value
- udata = udata.maskout(speed)
- #---- Create wind layer from the U/V grid data
- #layer = DrawMeteoData.createGridVectorLayer(udata, vdata, 'UV_Vector', True)
- layer = DrawMeteoData.createGridBarbLayer(udata, vdata, 'UV_Barb', True)
- #layer = DrawMeteoData.createStreamlineLayer(udata, vdata, 'Z_Streamline', True)
- #---- Add layer
- mapFrame.addLayer(layer)
- #--- Move pressure layer to bottom
- mapFrame.moveLayer(layer, 0)
- #---- Add title
- title = mapLayout.addText('MeteoInfo script demo', 350, 30, 'Arial', 16)
- #---- Zoom layout map
- print 'Zoom layout map...'
- mapLayout.getActiveLayoutMap().zoomToExtentLonLatEx(Extent(0, 360, -90, 90))
- #---- Set mapframe
- mapFrame.setGridXDelt(10)
- mapFrame.setGridYDelt(10)
- frame = JFrame('MeteoInfo Script Sample', size = (800, 600))
- frame.add(mapLayout)
- frame.visible = True
- print 'Finished!'
结果:
|
|