爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 11189|回复: 12

MeteoInfo脚本教程(十七):站点数据分析

[复制链接]

新浪微博达人勋

发表于 2014-12-21 22:30:36 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
站点数据也有类似格点数据的四则运算等,用法也很类似。此外站点数据经常需要插值为格点数据然后进行等值线等分析,因此插值算法也很重要。MeteoInfo站点数据插值为格点数据的算法主要有两种:反距离权法(IDW)和Cressman方法。其中IDW方法又分为IDW_Radius和IDW_Neighbour两种。IDW_Radius和Cressman插值方法都需要搜索半径,在站点稀疏的地区可能会插出缺测值(搜索半径内没有站点)。设置插值方法和参数的类是InterpolationSetting类,位于org.meteoinfo.geoprocess.analysis包中,其构造函数有两个:

IDW方法:
InterpolationSetting(double minX, double maxX, double minY, double maxY, int xNum, int yNum, String aInterMethod, float radius, int minNum)


Cressman方法:
InterpolationSetting(double minX, double maxX, double minY, double maxY, int xNum, int yNum, String aInterMethod, List<Double> radList)

前六个参数定义了格点场的范围和分辨率,第7个参数是方法名('IDW_Radius', 'IDW_Neighbour', 'Cressman'),radius是搜索半径,minNum是使用的最少站点数,Cressman插值方法需要多个搜索半径(radList参数)。

这里给出一个计算站点累计降水并插值成格点绘制等值线填色图的例子。内容比较丰富,包括了站点数据运算(相加)、插值、添加南海脚图、投影、标注等功能,希望大家能仔细理解。

  1. # encoding=utf-8
  2. #-----------------------------------------------------
  3. # Author: Yaqiang Wang
  4. # Date: 2014-12-6
  5. # Purpose: Interpolate station data to grid data
  6. # Note: Sample
  7. #-----------------------------------------------------
  8. #---- Import classes
  9. print 'Import classes...'
  10. from org.meteoinfo.layout import MapLayout
  11. from org.meteoinfo.data import StationData
  12. from org.meteoinfo.data.mapdata import MapDataManage
  13. from org.meteoinfo.data.meteodata import MeteoDataInfo, DrawMeteoData
  14. from org.meteoinfo.legend import LegendScheme, LegendType, PolygonBreak, MapFrame
  15. from org.meteoinfo.shape import ShapeTypes
  16. from org.meteoinfo.layout import LegendStyles, LayoutMap
  17. from org.meteoinfo.global import Extent
  18. from org.meteoinfo.projection import ProjectionInfo
  19. from org.meteoinfo.geoprocess.analysis import InterpolationSetting
  20. import os
  21. from datetime import datetime
  22. from datetime import timedelta
  23. from java.awt import Color
  24. from java.awt import Font
  25. from javax.swing import JFrame

  26. #---- Set directories
  27. print 'Set directories...'
  28. baseDir = 'D:/MyProgram/Distribution/java/MeteoInfo/MeteoInfo'
  29. dataDir = os.path.join(baseDir, 'sample/MICAPS')
  30. mapDir = os.path.join(baseDir, 'map')

  31. #---- Create MapLayout object
  32. mapLayout = MapLayout()
  33. mapFrame = mapLayout.getActiveMapFrame()
  34. mapView = mapFrame.getMapView()
  35. layoutMap = mapLayout.getActiveLayoutMap()

  36. #---- Load layers
  37. print 'Load layers...'
  38. bou2Layer = MapDataManage.loadLayer(os.path.join(mapDir, 'bou2_4p.shp'))
  39. lb = bou2Layer.getLegendScheme().getLegendBreaks().get(0)
  40. lb.setDrawFill(False)
  41. lb.setOutlineColor(Color.gray)
  42. mapFrame.addLayer(bou2Layer)
  43. bou1Layer = MapDataManage.loadLayer(os.path.join(mapDir, 'bou1_4l.shp'))
  44. lb = bou1Layer.getLegendScheme().getLegendBreaks().get(0)
  45. lb.setColor(Color.blue)
  46. mapFrame.addLayer(bou1Layer)
  47. bou1Layer_1 = MapDataManage.loadLayer(os.path.join(mapDir, 'bou1_4l.shp'))
  48. lb = bou1Layer_1.getLegendScheme().getLegendBreaks().get(0)
  49. lb.setColor(Color.blue)
  50. chinaLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'china.shp'))
  51. chinaLayer.setVisible(False)
  52. mapFrame.addLayer(chinaLayer)
  53. cityLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'res1_4m.shp'))
  54. lb = cityLayer.getLegendScheme().getLegendBreaks().get(0)
  55. lb.setSize(6)
  56. lb.setColor(Color.red)
  57. labset = cityLayer.getLabelSet()
  58. labset.setFieldName('NAME')
  59. font = Font(u'楷体', Font.PLAIN, 16)
  60. labset.setLabelFont(font)
  61. labset.setYOffset(15)
  62. cityLayer.addLabels()
  63. mapFrame.addLayer(cityLayer)

  64. #---- Add South China Sea
  65. aMapFrame = MapFrame()
  66. aLayoutMap = LayoutMap(aMapFrame)
  67. aLayoutMap.setDrawGridLabel(False)
  68. aLayoutMap.setDrawGridTickLine(False)
  69. aLayoutMap.setLeft(40)
  70. aLayoutMap.setTop(350)
  71. aLayoutMap.setWidth(85)
  72. aLayoutMap.setHeight(109)
  73. mapLayout.addElement(aLayoutMap)
  74. aMapFrame.addLayer(bou1Layer_1)
  75. aProjInfo = ProjectionInfo("+proj=lcc+lat_1=25+lat_2=47+lon_0=105")
  76. aMapFrame.getMapView().projectLayers(aProjInfo)
  77. aMapFrame.getMapView().zoomToExtentLonLatEx(Extent(106.5,122.5,1,23))

  78. #---- Project mapview
  79. print 'Project mapview...'
  80. projStr = '+proj=lcc+lat_1=25+lat_2=47+lon_0=105'
  81. projInfo = ProjectionInfo(projStr)
  82. mapView.projectLayers(projInfo)
  83. extent = Extent(78,130,15,53)
  84. mapView.zoomToExtentLonLatEx(extent)

  85. #---- Create MeteoDataInfo object
  86. mdi = MeteoDataInfo()

  87. #---- Set start/end time
  88. stime = datetime(2010,10,14,14)
  89. etime = datetime(2010,10,14,20)

  90. #---- Loop
  91. print 'Get sum station data...'
  92. sdata = StationData()
  93. atime = stime
  94. i = 0
  95. while atime < etime:
  96.   #---- Open a MICAPS data file
  97.   fn = os.path.join(dataDir, stime.strftime('%y%m%d%H') + '.000')
  98.   mdi.openMICAPSData(fn)

  99.   #---- Sum precipitation station data
  100.   if i == 0:
  101.     sdata = mdi.getStationData('Precipitation6h')
  102.   else:
  103.     sdata = sdata.add(mdi.getStationData('Precipitation6h'))

  104.   atime = atime + timedelta(hours=6)
  105.   
  106. #---- Interpolate station data to grid data
  107. print 'Interpolate station data to grid data...'
  108. interpSet = InterpolationSetting(60,140,-20,60,160,160,"IDW_Radius",2,1)
  109. #radList = [10.0, 8.0, 6.0, 4.0]
  110. #interpSet = InterpolationSetting(60,140,-20,60,160,160,"Cressman",radList)
  111. gdata = sdata.interpolateData(interpSet)

  112. #---- Set legend scheme
  113. ls = LegendScheme(ShapeTypes.Polygon)
  114. ls.setLegendType(LegendType.GraduatedColor)
  115. values = [0,0.1,1,2,5,10,20,25,50,100,1000]
  116. colors = [Color(255,255,255),Color(170,240,255),Color(120,230,240),Color(200,220,50),Color(240,220,20),
  117.   Color(255,120,10),Color(255,90,10),Color(240,40,0),Color(180,10,0),Color(120,10,0)]
  118. lbs = ls.getLegendBreaks()
  119. for i in range(0, len(colors)):
  120.   lb = PolygonBreak()
  121.   lb.setColor(colors)
  122.   lb.setStartValue(values)
  123.   lb.setEndValue(values[i + 1])
  124.   if i == 0:
  125.     lb.setCaption('< ' + str(values[i + 1]))
  126.   elif i == len(colors) - 1:
  127.     lb.setCaption('> ' + str(values))
  128.   else:
  129.     lb.setCaption(str(values) + ' - ' + str(values[i + 1]))
  130.   lb.setDrawOutline(False)
  131.   lbs.add(lb)

  132. #---- Create shaded layer
  133. print 'Create shaded layer...'  
  134. layer = DrawMeteoData.createShadedLayer(gdata, ls, 'Rain_shaded', 'Rain', True)
  135. layer.setMaskout(True)

  136. #---- Add layer
  137. mapFrame.addLayer(layer)
  138. mapFrame.moveLayer(layer, 0)

  139. #---- Add title
  140. title = mapLayout.addText(u'全国降水量实况图', 280, 40, u'黑体', 18)
  141. stime = stime + timedelta(hours=-6)
  142. subTitle = mapLayout.addText(u'(' + stime.strftime('%Y-%m-%d %H:00') +
  143.   u' 至 ' + etime.strftime('%Y-%m-%d %H:00') + u')', 280, 60, u'黑体', 16)

  144. #---- Set layout map
  145. print 'Set layout map...'
  146. layoutMap.setDrawGridLine(False)
  147. layoutMap.setDrawNeatLine(False)
  148. layoutMap.setDrawGridLabel(False)
  149. layoutMap.setDrawGridTickLine(False)
  150. layoutMap.setLeft(10)
  151. layoutMap.setTop(10)
  152. layoutMap.setWidth(620)
  153. layoutMap.setHeight(450)

  154. #---- Set maskout
  155. mapView.getMaskOut().setMask(True)
  156. mapView.getMaskOut().setMaskLayer(chinaLayer.getLayerName())

  157. #---- Set mapframe
  158. mapFrame.setGridXDelt(10)
  159. mapFrame.setGridYDelt(10)

  160. #---- Add legend
  161. legend = mapLayout.addLegend(575, 250)
  162. legend.setLegendStyle(LegendStyles.Normal)
  163. legend.setLegendLayer(layer)
  164. legend.setFont(Font(u'宋体', Font.PLAIN, 12))
  165. legend.setTitle(u'降水量(毫米)')

  166. frame = JFrame('MeteoInfo Script Sample', size = (750, 530))
  167. frame.add(mapLayout)
  168. frame.visible = True
  169. print 'Finished!'


Image00097.png

本帖被以下淘专辑推荐:

密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-12-22 08:38:59 | 显示全部楼层
不错,{:eb502:}{:eb502:}{:eb502:}{:eb502:}
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2014-12-24 09:37:25 | 显示全部楼层
楼主好厉害
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-12-31 09:00:16 | 显示全部楼层
图画的好漂亮
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-6-7 17:41:58 | 显示全部楼层
太厉害,介绍的很详细~~~~~
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-12-22 16:00:03 | 显示全部楼层
想请问一下地图根据范经纬度围缩放在C#里面怎么使用呢?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-12-24 21:34:03 | 显示全部楼层
很好一 啊 哈哈哈
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-12-30 12:55:36 | 显示全部楼层
不知道王老师在站点数据较多,需要绘制等值线时,是否对三角剖分追踪等值线算法实现?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2015-12-30 16:06:07 | 显示全部楼层
zfvv 发表于 2015-12-30 12:55
不知道王老师在站点数据较多,需要绘制等值线时,是否对三角剖分追踪等值线算法实现?

没研究过那个算法。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-8-18 10:53:46 | 显示全部楼层
您好,我是用Java二次开发的,生成的图例的名称我按照
  1. legend.setTitle("降水量(mm)");
复制代码
结果却显示contourlayer,这是为什么呢,要怎么解决
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表