爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 6401|回复: 14

MeteoInfo脚本教程(九):站点数据

[复制链接]

新浪微博达人勋

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

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

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

x
之前提到过站点数据是StationData类,其中包含了站点号、站点坐标和站点观测值。还有一类站点数据是StationInfoData类,可以包含更多的站点数据信息,包括非数字信息。StationData和StationInfoData类的典型应用是创建站点分布图,分别由DrawMeteoData类的下面方法创建:

    DrawMeteoData.createSTPointLayer(StationData stdata, String layerName, String fieldName)
    DrawMeteoData.createSTInfoLayer(StationInfoData sidata, String layerName)

脚本示例如下:
  1. #-----------------------------------------------------
  2. # Author: Yaqiang Wang
  3. # Date: 2014-12-1
  4. # Purpose: Get and plot station data
  5. # Note: Sample
  6. #-----------------------------------------------------
  7. #---- Import classes
  8. print 'Import classes...'
  9. from org.meteoinfo.layout import MapLayout
  10. from org.meteoinfo.data.mapdata import MapDataManage
  11. from org.meteoinfo.data.meteodata import MeteoDataInfo, DrawMeteoData
  12. from org.meteoinfo.layout import LegendStyles
  13. from org.meteoinfo.global import Extent
  14. import os
  15. from java.awt import Color
  16. from javax.swing import JFrame

  17. #---- Set directories
  18. print 'Set directories...'
  19. baseDir = 'D:/MyProgram/Distribution/java/MeteoInfo/MeteoInfo'
  20. dataDir = os.path.join(baseDir, 'sample')
  21. mapDir = os.path.join(baseDir, 'map')

  22. #---- Create MapLayout object
  23. mapLayout = MapLayout()
  24. mapFrame = mapLayout.getActiveMapFrame()

  25. #---- Load country layer
  26. print 'Load country layer...'
  27. countryLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'country1.shp'))
  28. lb = countryLayer.getLegendScheme().getLegendBreaks().get(0)
  29. lb.setDrawFill(False)
  30. lb.setOutlineColor(Color.blue)
  31. mapFrame.addLayer(countryLayer)

  32. #---- Create MeteoDataInfo object
  33. mdi = MeteoDataInfo()

  34. #---- Open a MICAPS data file
  35. fn = os.path.join(dataDir, 'MICAPS/10101414.000')
  36. mdi.openMICAPSData(fn)

  37. #---- Get station data
  38. sdata = mdi.getStationData('Visibility')
  39. sidata = mdi.getStationInfoData()

  40. #---- Create station point layer from the grid data
  41. layer = DrawMeteoData.createSTPointLayer(sdata, 'Visibility_STPoint', 'Visibility')

  42. #---- Add layer
  43. mapFrame.addLayer(layer)

  44. #--- Move layer to bottom
  45. mapFrame.moveLayer(layer, 0)

  46. #---- Add title
  47. title = mapLayout.addText('MeteoInfo script demo', 350, 30, 'Arial', 16)

  48. #---- Set layout map
  49. print 'Set layout map...'
  50. mapLayout.getActiveLayoutMap().setWidth(580)
  51. mapLayout.getActiveLayoutMap().zoomToExtentLonLatEx(Extent(70, 140, 15, 55))

  52. #---- Set mapframe
  53. mapFrame.setGridXDelt(10)
  54. mapFrame.setGridYDelt(10)

  55. #---- Add legend
  56. legend = mapLayout.addLegend(620, 150)
  57. legend.setLegendStyle(LegendStyles.Normal)
  58. legend.setLegendLayer(layer)
  59. legend.setTitle('Visibility')

  60. frame = JFrame('MeteoInfo Script Sample', size = (800, 600))
  61. frame.add(mapLayout)
  62. frame.visible = True
  63. print 'Finished!'



Image00071.png


  1. #-----------------------------------------------------
  2. # Author: Yaqiang Wang
  3. # Date: 2014-12-1
  4. # Purpose: Get and plot station info data
  5. # Note: Sample
  6. #-----------------------------------------------------
  7. #---- Import classes
  8. print 'Import classes...'
  9. from org.meteoinfo.layout import MapLayout
  10. from org.meteoinfo.data.mapdata import MapDataManage
  11. from org.meteoinfo.data.meteodata import MeteoDataInfo, DrawMeteoData
  12. from org.meteoinfo.layout import LegendStyles
  13. from org.meteoinfo.global import Extent
  14. import os
  15. from java.awt import Color
  16. from java.awt import Font
  17. from javax.swing import JFrame

  18. #---- Set directories
  19. print 'Set directories...'
  20. baseDir = 'D:/MyProgram/Distribution/java/MeteoInfo/MeteoInfo'
  21. dataDir = os.path.join(baseDir, 'sample')
  22. mapDir = os.path.join(baseDir, 'map')

  23. #---- Create MapLayout object
  24. mapLayout = MapLayout()
  25. mapFrame = mapLayout.getActiveMapFrame()

  26. #---- Load country layer
  27. print 'Load country layer...'
  28. countryLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'country1.shp'))
  29. lb = countryLayer.getLegendScheme().getLegendBreaks().get(0)
  30. lb.setDrawFill(False)
  31. lb.setOutlineColor(Color.blue)
  32. mapFrame.addLayer(countryLayer)

  33. #---- Create MeteoDataInfo object
  34. mdi = MeteoDataInfo()

  35. #---- Open a MICAPS data file
  36. fn = os.path.join(dataDir, 'MICAPS/10101414.000')
  37. mdi.openMICAPSData(fn)

  38. #---- Get station info data
  39. sidata = mdi.getStationInfoData()

  40. #---- Create station info layer from the station info data
  41. layer = DrawMeteoData.createSTInfoLayer(sidata, 'StationInfo')
  42. labset = layer.getLabelSet()
  43. labset.setFieldName('CloudCover')
  44. font = Font('Arial', Font.PLAIN, 14)
  45. labset.setLabelFont(font)
  46. labset.setYOffset(15)
  47. layer.addLabels()

  48. #---- Add layer
  49. mapFrame.addLayer(layer)

  50. #--- Move layer to bottom
  51. mapFrame.moveLayer(layer, 0)

  52. #---- Add title
  53. title = mapLayout.addText('MeteoInfo script demo', 350, 30, 'Arial', 16)

  54. #---- Set layout map
  55. print 'Set layout map...'
  56. mapLayout.getActiveLayoutMap().setWidth(580)
  57. mapLayout.getActiveLayoutMap().zoomToExtentLonLatEx(Extent(70, 140, 15, 55))

  58. #---- Set mapframe
  59. mapFrame.setGridXDelt(10)
  60. mapFrame.setGridYDelt(10)

  61. #---- Add legend
  62. legend = mapLayout.addLegend(620, 150)
  63. legend.setLegendStyle(LegendStyles.Normal)
  64. legend.setLegendLayer(layer)
  65. legend.setTitle('Station')

  66. frame = JFrame('MeteoInfo Script Sample', size = (800, 600))
  67. frame.add(mapLayout)
  68. frame.visible = True
  69. print 'Finished!'



Image00072.png

本帖被以下淘专辑推荐:

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

新浪微博达人勋

 楼主| 发表于 2015-2-4 11:27:31 | 显示全部楼层
小蜡图图 发表于 2015-2-4 11:23
要画的数据导入应该修改的是哪一行呢?希望指教~

fn = os.path.join(dataDir, 'MICAPS/10101414.000')

总之需要将fn设为你计算机中micaps 1文件的全路径。
密码修改失败请联系微信:mofangbao
回复 支持 1 反对 0

使用道具 举报

新浪微博达人勋

发表于 2015-1-5 09:37:28 | 显示全部楼层
~~~~~zhege keyi you a ~
密码修改失败请联系微信:mofangbao
回复 支持 1 反对 0

使用道具 举报

新浪微博达人勋

发表于 2014-12-1 23:32:58 | 显示全部楼层
速度!快成一个系列了,赞王老师!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-12-7 12:56:22 | 显示全部楼层
继续给我们带来新知识
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-1-9 09:31:33 | 显示全部楼层
感谢楼主!
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2015-2-4 11:01:17 | 显示全部楼层
想问问老师,新手刚刚接触,直接复制的脚本出错:Import classes...
Set directories...
Load country layer...
Traceback (most recent call last):
  File "<string>", line 31, in <module>
AttributeError: 'NoneType' object has no attribute 'getLegendScheme'
想画第一幅图,想问问baseDir= 'D:/MyProgram/Distribution/java/MeteoInfo/MeteoInfo'的路径里存放的是什么?问题略二,求解
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2015-2-4 11:04:32 | 显示全部楼层
小蜡图图 发表于 2015-2-4 11:01
想问问老师,新手刚刚接触,直接复制的脚本出错:Import classes...
Set directories...
Load country la ...

需要修改baseDir为你计算机上MeteoInfo的路径。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-2-4 11:23:14 | 显示全部楼层
MeteoInfo 发表于 2015-2-4 11:04
需要修改baseDir为你计算机上MeteoInfo的路径。

要画的数据导入应该修改的是哪一行呢?希望指教~
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-6-8 21:12:25 | 显示全部楼层
王老师,Visibility怎么会出现70这样的数值?是Micaps里数据读取有问题吗?
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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