需要HDF数据符合EOS规范才能自动读出数据的空间范围和格点坐标。
不符合EOS规范的HDF数据可以通过写脚本给定格点坐标来读取数据并生成图层,下面给一个Jython脚本的例子。
用你给的数据生成的图层:
脚本代码:
- #-----------------------------------------------------
- # Author: Yaqiang Wang
- # Date: 2013-10-29
- # Purpose: Read hdf4 data
- # Note: Sample
- #-----------------------------------------------------
- from org.meteoinfo.data.meteodata import MeteoDataInfo
- from org.meteoinfo.data.meteodata import Dimension
- from org.meteoinfo.data.meteodata import DimensionType
- from org.meteoinfo.data.meteodata import DrawMeteoData
- from org.meteoinfo.projection import ProjectionInfo
- 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/hdf/'
- #Create MeteoDataInfo object
- mdi = MeteoDataInfo()
- #Read hdf data file
- fn = dataDir + 's66.HDF'
- if os.path.isfile(fn):
- print fn
- mdi.openNetCDFData(fn)
- dataInfo = mdi.getDataInfo()
- print mdi.getInfoText()
- xmin = -180.0
- ymin = -90.0
- xnum = 360
- ynum = 180
- xdelt = 1.0
- ydelt = 1.0
- xlist = []
- ylist = []
- for i in range(0,xnum):
- xlist.append(xmin + xdelt * i)
- for i in range(0,ynum):
- ylist.append(ymin + ydelt * i)
- X = jarray.array(xlist, 'd')
- Y = jarray.array(ylist, 'd')
- xDim = Dimension(DimensionType.X)
- xDim.setValues(X)
- dataInfo.setXDimension(xDim)
- yDim = Dimension(DimensionType.Y)
- yDim.setValues(Y)
- dataInfo.setYDimension(yDim)
- var = dataInfo.getVariable('ddd\dddd')
- dimList = [yDim, xDim]
- var.setDimensions(dimList)
- gData = mdi.getGridData(var.getName())
- gData = gData.multiply(0.01)
- aLS = LegendManage.createLegendSchemeFromGridData(gData, LegendType.GraduatedColor, ShapeTypes.Polygon)
- aLayer = DrawMeteoData.createRasterLayer(gData, "Test_HDF", aLS)
- aLayer.setProjInfo(dataInfo.getProjectionInfo())
- mf = miapp.getMapDocument().getActiveMapFrame()
- mf.addLayer(aLayer)
- mf.moveLayer(aLayer, 0)
- print 'Finished!'
|