- 积分
- 55965
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 MeteoInfo 于 2014-12-1 12:00 编辑
MeteoInfo里有两个最重要的数据类:GridData(格点数据)和StationData(站点数据)。气象模式输出的数据通常是格点数据,对某一变量而言可以有4维数据(空间三维和时间维)。从MeteoDataInfo对象中获取GridData的方法是getGridData(String variableName),可以通过setTimeIndex和setLevelIndex方法设置时间和高度维,从而获取水平的2维GridData数据。其实也可以通过其它设置获取其它的2维或1维格点数据,比如剖面格点数据,这个以后再讲。
有了GridData数据后可以用DrawMeteoData类的一些静态方法来创建相应的图层达到绘制数据的目的。从GridData数据创建图层的方法主要如下:
DrawMeteoData.createContourLayer(GridData data,String layerName,String fieldName, Bollean isSmooth) -> 生成等值线图层(VectorLayer,Polyline)
DrawMeteoData.createShadedLayer(GridData data,String layerName,String fieldName, Bollean isSmooth) -> 生成等值线填色图层(VectorLayer,Polygon)
DrawMeteoData.createRasterLayer(GridData data,String layerName) -> 生成栅格图层(RasterLayer)
DrawMeteoData.createGridFillLayer(GridData data,String layerName,String fieldName) -> 生成格点填色图层(VectorLayer,Polygon)
DrawMeteoData.createGridPointLayer(GridData data,String layerName,String fieldName) -> 生成格点点图层(VectorLayer,Point)
下面是一个Demo脚本:
- #-----------------------------------------------------
- # Author: Yaqiang Wang
- # Date: 2014-11-30
- # Purpose: Get and plot grid data
- # Note: Sample
- #-----------------------------------------------------
- #---- Import classes
- print 'Import classes...'
- from org.meteoinfo.layout import MapLayout
- 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.blue)
- 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 grid data
- mdi.setTimeIndex(2)
- mdi.setLevelIndex(3)
- gdata = mdi.getGridData('Z')
- gdata.extendToGlobal()
- #---- Create shaded layer from the grid data
- layer = DrawMeteoData.createContourLayer(gdata, 'Z_contour', 'Z', True)
- #layer = DrawMeteoData.createShadedLayer(gdata, 'Z_shaded', 'Z', True)
- #layer = DrawMeteoData.createRasterLayer(gdata, 'Z_raster')
- #layer = DrawMeteoData.createGridFillLayer(gdata, 'Z_gridfill', 'Z')
- #layer = DrawMeteoData.createGridPointLayer(gdata, 'Z_gridpoint', 'Z')
- #---- 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(30)
- mapFrame.setGridYDelt(30)
- #---- Add legend
- legend = mapLayout.addLegend(150, 440)
- legend.setLegendStyle(LegendStyles.Bar_Horizontal)
- legend.setLegendLayer(layer)
- frame = JFrame('MeteoInfo Script Sample', size = (800, 600))
- frame.add(mapLayout)
- frame.visible = True
- print 'Finished!'
|
|